Commit graph

1085 commits

Author SHA1 Message Date
Carles Cufi 7924d16aef Bluetooth: controller: Fix broken switch statement
Add a missing break that was forgotten when we introduced the Read TX
Power command.

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

Jira: ZEP-2553

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

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

Jira: ZEP-1918

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

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

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

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-22 15:22:25 +02:00
Carles Cufi 523a9dfe8a Bluetooth: controller: Fix RL index check
In the ll_rl_pdu_adv_update() function, the check to verify if we are
dealing with an item from the resolving list or else with a simple
standard non-privacy enabled device was left over from the previous
iteration, which used negative values. Replace that check with the
proper current one, using the size of the rl array as an indicator of
whether the index is valid.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-21 18:49:59 +02:00
Vinayak Kariappa Chettimada dd52b8ea02 Bluetooth: controller: Fix first connection interval timing
Due to varying remainder value, first interval will need to
consider the remainder value used in microsecond timing from
the start of the initiator window.

Also the tx chain delay and ready delay must be substract
after the window offset is calculated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-21 17:37:43 +02:00
Carles Cufi 558be2e02c Bluetooth: controller: Enable Read Remote Ver Info bit
The Read Remote Version Information command is supported on the BLE
controller, enable the bit in Read Local Supported Commands to reflect
this.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-21 08:42:24 -04:00
Vinayak Kariappa Chettimada 6a39ed084f Bluetooth: controller: Add Minimum Number of Used Channels Proc
Add implementation to support Bluetooth 5.0 Minimum Number
of Used Channels Procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-21 08:41:56 -04:00
Vinayak Kariappa Chettimada cb90fbe56a Bluetooth: controller: Fix controller assert at clock rollover
Fix controller assert due to a bug introduced in commit
07270e52ba ("Bluetooth: controller: Coding style and
refactoring").

This reverts implementation to original way it was and the
calculation of the ticker expiry will now not overflow the
range of the RTC peripheral, which is a 24 bit counter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-18 15:34:19 +02:00
Ricardo Salveti 60a908c9c9 Bluetooth: Kconfig: fix default value and range for BT_RX_STACK_SIZE
Fix checks for BT_HCI_RAW and move default range after the other range
options, required by Kconfig to avoid overwriting other options.

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
2017-08-17 21:11:50 +03:00
Andrzej Kaczmarek dedb70d864 Bluetooth: Fix formatting string for storage directory name
Precision specifier is not supported by printk(), let's use
zero padding instead.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-08-17 11:16:03 +03:00
Carles Cufi e0194750cf Bluetooth: controller: Fix RSSI sign
The RSSI value is an 8-bit signed integer. Since the Link Layer works
only with positive unsigned integers, translate into a negative number
at the HCI layer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-17 10:02:07 +02:00
Paul Sokolovsky cf43be1a2e Bluetooth: Increase CONFIG_BT_HCI_TX_STACK_SIZE for BT_SPI
Older value of 256 was introduced in 1.7 times. Testing on
BOARD=96b_carbon with 2 weeks old codebase however showed that TX
thread stack however can grow to 324 bytes. Finally, with the
latest master, following stacks are reported on BLE disconnect
(with CONFIG_INIT_STACKS enabled):

rx stack (real size 1024): unused 452 usage 572 / 1024 (55 %)
tx stack (real size 384):  unused 16  usage 368 / 384 (95 %)

Two outcomes:

1. TX stack needs increase.
2. Over time, the stack usage grows, plus variations in SPI
drivers should also be taken into account.

So, increase the stack size to 416 bytes, to leave some headroom
beyond the immediate values seen on 96b_carbon.

Jira: ZEP-2510

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-16 14:54:20 +03:00
Ricardo Salveti 8dbb388000 samples: Bluetooth: add HCI SPI raw handler sample
Add a sample application that allows a Zephyr-based Bluetooth
controller to interface with an HCI driver via SPI. This sample
implements the same BT SPI protocol already as Zephyr's HCI SPI
driver.

Currently, the sample only supports the legacy SPI API.

Provide a single configuration file, avoiding board-specific
files. Some board-specific configuration information must be provided
via other means:

- CONFIG_BT_CONTROLLER_TO_HOST_SPI_DEV_NAME
- CONFIG_BT_CONTROLLER_TO_HOST_SPI_IRQ_DEV_NAME
- CONFIG_BT_CONTROLLER_TO_HOST_SPI_IRQ_PIN

Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-08-15 22:58:02 +03:00
Marti Bolivar 4e53f4e830 Bluetooth: Kconfig: delete stray double quote
Trivial fix.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-08-15 22:58:02 +03:00
Carles Cufi fc965e5554 Bluetooth: controller: Split Ext Scan Filter Policies out
Since Extended Scanner Filter Policies is an independent feature from
Controller-based Privacy, split it out so it can be built independently
and included without it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-15 22:55:15 +03:00
Paul Sokolovsky 0592c0ce59 Bluetooth: shell: gatt_read: Reset offset to 0
Unless offset was specified, it should default to 0, whereas
previously, value from the last command was used.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-15 21:16:40 +03:00
Carles Cufi 03a75e17dd Bluetooth: controller: Enable Extended Scan Filter Policies bit
Whenever privacy is enabled, we support the Extended Scan Filter
Policies functionality, and therefore we must show it in the bitfield of
LE supported features for the controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-14 21:06:51 +02: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
Johan Hedberg 01df52c2b7 Bluetooth: Use higher RX_BUF_LEN when Mesh Proxy protocol is used
Avoiding segmentation in the GATT-based Mesh Proxy protocol requires
having an RX buffer length of at least 77. We could round it up to 80
since there's otherwise wasted space, however there's also
BT_HCI_RESERVE to consider, so to avoid pushing over the 4-byte
boundary for certain HCI drivers just leave the size at 77.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-14 13:01:39 +03:00
Carles Cufi 868aeeb126 Bluetooth: controller: LE Directed Advertising Report
Implement the 4.2 event LE Directed Advertising Report, used for
scanners in a privacy-enabled controller to report directed advertising
events whose TargetA cannot be resolved by the local controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-10 12:33:36 +03:00
Vinayak Kariappa Chettimada 882bdd57b4 Bluetooth: controller: Add packet transmit time restrictions
Add implementation to support PHY update procedure with
packet transmit time restrictions.

This fixes:
TP/CON/SLA/BV-49-C [Initiating PHY Update Procedure Packet
Time Restrictions]
TP/CON/SLA/BV-50-C [Responding to PHY Update Procedure
Packet Time Restrictions]
TP/CON/SLA/BV-52-C [Initiating PHY Update Procedure Packet
Time Restrictions, No Change]
TP/CON/SLA/BV-53-C [Responding to PHY Update Procedure
Packet Time Restrictions, No Change]
TP/CON/MAS/BV-49-C [Initiating PHY Update Procedure Packet
Time Restrictions]
TP/CON/MAS/BV-50-C [Responding to PHY Update Procedure
Packet Time Restrictions]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-10 10:54:28 +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
Vinayak Kariappa Chettimada dc1dad34f3 Bluetooth: controller: Fix return type in hal/rand.c
Fix incorrect return data type, which causes controller to
hang generating random numbers.

Fixes bug introduced in commit d90095b556 ("Bluetooth:
controller: Use random numbers in adv and enc setup")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-08 18:11:07 +03:00
Carles Cufi 2fab706216 Bluetooth: controller: Check AdvA in Scan Response
The specification requires the scanner to verify that the AdvA present
in a scan response matches the AdvA that was sent in the original scan
request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-08 14:48:34 +02:00
Vinayak Kariappa Chettimada d90095b556 Bluetooth: controller: Use random numbers in adv and enc setup
Added implementation to get random numbers in ISR. And fixed
implementation to use random numbers in advertisement random
delay and encryption setup procedure.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-08-08 15:29:55 +03:00
Carles Cufi 505ebfbe36 Bluetooth: controller: Fix TargetA check as initiator
The existing check for the TargetA address in directed advertising
events was incorrect. In fact the specification states:

"An initiator that has been instructed by the Host to use
Resolvable Private Addresses shall not respond to directed connectable
advertising events that contain Public or Static addresses for the
target’s address (TargetA field)."

Hence, reject TargetA values that have not been successfully resolved
when the controller is generating its own RPAs.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 21:54:16 -04:00
Johan Hedberg bf8e504588 Bluetooth: Mesh: Fix duplicate const declarations
Remvoe duplicate const declarations which may cause compiler warnings.

Jira: ZEP-2442

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-07 19:18:02 +03:00
Johan Hedberg 01b684f82b Bluetooth: Mesh: Fix pointer signedness compiler warnings
Fix compiler warnings resulting from passing C string literals to
functions expecting an unsigned char pointer.

Jira: 2443

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-07 19:17:40 +03:00
Carles Cufi 264481116c Bluetooth: controller: Enable AAR for Scan Responses
To be able to get a hit on the AAR whenever a Scan Response is received,
enable it in the state transition.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 14:37:56 +03:00
Carles Cufi ba9d3ae6b5 Bluetooth: controller: Fix whitelist filter logic
Add missing checks for the logic that discriminates between whitelisting
and non-whitelisting filtering, so that we do not fall into an
unsuspected false positive.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-07 12:05:49 +02:00
Carles Cufi f6405dfd93 Bluetooth: controller: Avoid assignments in if statement
Rework the ctrl_lrpa_get() function so that it doesn't require an
assignment to be present inside the if statement, yielding smaller and
safer code.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi f23aaeb7f4 Bluetooth: controller: Fix warning due to unused variable
With privacy disabled the lrpa pointers are not used, so exclude them
from the build.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 3a35859410 Bluetooth: controller: Translate addresses in adv reports
Advertising reports generated by a scanner require the controller to
look up the resolving list to supply the host with an ID address instead
of the RPA that has been sent over the air.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 66c619eb83 Bluetooth: controller: Fix typo in scan request address population
Use the actual scanner address to copy the generated RPA into, instead
of mistakenly copying it into the advertiser's address.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 6e42c2af3b Bluetooth: controller: Use RPA in scanner only if available
Whenever trying to generate a local RPA to send a scan request or a conn
ind, verify that it can be generated (i.e. no NULL IRK provided by the
Host) and fall back to using the public/random address if required.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 15:17:48 +02:00
Carles Cufi 2c60df0786 Bluetooth: controller: Fix Set Privacy Mode command
Trivial fix for the return value in the processing of the Set Privacy
Mode HCI command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 12:01:11 +03:00
Carles Cufi a87e8a08ee Bluetooth: controller: Use little-endian peer IRKs for generation
Since the hardware expects big-endian IRKs but the common generation
function expects it in little-endian, copy and reverse the peer IRK
before generating RPAs.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-04 12:01:11 +03:00
Carles Cufi b2a76be25b Bluetooth: controller: LE Enhanced Connection Complete
Implement the LE Enhanced Connection Complete HCI event, but include it
only when controller-based privacy is enabled, since it is only relevant
with it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-03 16:13:09 +03:00
Carles Cufi dce2f95e95 Bluetooth: controller: Increase conn count only on success
Since a connection attempt can fail and will still generate an LE
Connection Complete event, check the status from the LL control module
before incrementing the HCI connection count used for flow control.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-03 16:13:09 +03:00
Johan Hedberg f8c338fde8 Bluetooth: Mesh: Health: Fix Current Status encoding
The Test ID was incorrectly being added as 4 bytes (size of a pointer)
instead of the intended 1 byte.

This fixes Coverity CID 173643.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 14:09:40 +03:00
Johan Hedberg d97be9e7a6 Bluetooth: Mesh: Provisioning: Always allow Failed PDU
In addition to the next expected PDU we should also process Failed in
all states.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 13:10:40 +03:00
Johan Hedberg 019b805275 Bluetooth: hci_ecc: Fine-tune thread stack size
The current 960 is at least too small under qemu_x86:

ecc stack (real size 1024): unused 36 usage 988 / 1024 (96 %)

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-03 10:47:18 +03:00
Carles Cufi 4694fe6e8a Bluetooth: controller: nrf5: Fix AAR packet pointer
The nRF5 AAR requires the packet pointer to be placed exactly 3 bytes
before the beginning of the address. Since we don't use the S1 extra
length byte, substract one from the address of the radio packet pointer.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Carles Cufi fc0c3a6c32 Bluetooth: controller: Fix IRK endianness
The currently supported hardware in the LL requires big-endian IRK
values to properly function. Reverse the order of the IRK bytes coming
from HCI to address this issue.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Carles Cufi ba2f0a1f1e Bluetooth: controller: nrf5: Fix AAR scratch pointer
The nRF5's AAR was being improperly configured, leading to a NULL
scratch pointer which made it not function at all.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-02 16:48:03 +02:00
Johan Hedberg 2d57272f65 Bluetooth: hci_ecc: Convert to new uECC API
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-01 10:35:06 -04:00
Carles Cufi 296b469c40 Bluetooth: controller: Thread-safe local RPA access
In order to make sure that the ISR never gets an incomplete or partial
local RPA, use pointers to share the local RPA between thread mode and
ISRs. Pointer updates are guaranteed to be atomic at least on ARM
Cortex-M.
Additionally add support for using local RPAs when initiating a
connection or sending a scan request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Carles Cufi a260d6face Bluetooth: controller: Resolve TargetA in software
Since the hardware is only able to resolve the first address in the
packet, use the existing functionality to resolve a potential TargetA
RPA in software to verify if it matches the local device.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Carles Cufi af93255aa5 Bluetooth: controller: Privacy filtering in scanner and initiator
This commit introduces controller-based privacy for both the scanner and
the initiator roles. All the features in the specification are
implemented except:

* RPA resolution for directed advertising (TargetA address)
* RPA generation for scan requests and conn ind packets

Follow-up patches will cover the 2 items of functionality still missing
from the basic implementation. Hosts not using controller-based privacy
should not be affected by this change.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-01 09:39:59 +02:00
Luiz Augusto von Dentz cf913738c5 Bluetooth: GATT: Indicate service changes when reconnecting
If peer has previously configure to received service changes indications
any changes to the database during the time it has been disconnected
shall be indicated once it reconnects:

[bt] [DBG] sc_process: (0x004065b4) start 0x000a end 0x0014
[bt] [DBG] sc_save: (0x004065b4) peer b8:8a:60:d8:17:d7 (public)
 start 0x000a end 0x0014
[bt] [DBG] bt_gatt_connected: (0x00405240) conn 0x00405aa0
[bt] [DBG] gatt_ccc_changed: (0x00405240) ccc 0x00400b30 value 0x0002
[bt] [DBG] sc_ccc_cfg_changed: (0x00405240) value 0x0002
[bt] [DBG] sc_restore: (0x00405240) peer b8:8a:60:d8:17:d7 (public)
 start 0x000a end 0x0014
[bt] [DBG] sc_process: (0x004065b4) start 0x000a end 0x0014
[bt] [DBG] gatt_indicate: (0x004065b4) conn 0x00405aa0 handle 0x0008
[bt] [DBG] sc_indicate_rsp: (0x00405240) err 0x00

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Luiz Augusto von Dentz c6cb97f7c4 Bluetooth: GATT: Fix not setting SC_INDICATE_PENDING
bt_gatt_indicate return 0 in case of success, not true, so
SC_INDICATE_PENDING was flag was not set when it should.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Luiz Augusto von Dentz 737c50b50f Bluetooth: GATT: Improve notification code
Only checks if consolidated CCC value matches with data->type once.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-31 13:52:08 +03:00
Vinayak Kariappa Chettimada bc64c46e35 Bluetooth: controller: Fix control and data Tx queue management
Control and Data packet Tx queue management updated to be
optimal and defer control packet responses when Tx is paused
during encryption setup.

This fixes:
TP/SEC/MAS/BV-12 [Master Start Encryption: Overlapping
Procedure]
TP/SEC/MAS/BV-13 [Master Start Encryption: Overlapping
Procedure with LL_SLAVE_FEATURES_REQ]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 6b02fb6e93 Bluetooth: controller: Fix handling PHY upd diff proc collision
Fix handling of different procedure collision when receiving
a PHY update request and handling of reject extended
indication.

This fixes:
TP/CON/MAS/BV-47-C [Handling Protocol Collision – Different
Procedure – Channel Map],

TP/CON/SLA/BV-46-C [Handling Protocol Collision – Different
Procedure – Channel Map] and

TP/CON/SLA/BV-48-C [Handling Protocol Collision – Different
Procedure – Connection Update]

conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 08466d5021 Bluetooth: controller: Fix missing procedure timeout on PHY_RSP
Fix missing procedure timeout start on PHY_RSP response
enqueue.

This fixes TP/CON/SLA/BV-51-C [Protocol Timeout for PHY
Update Procedure – No Update Request] conformance test in
LL.TS.5.0.0,

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 4ceca0864d Bluetooth: controller: Fix a missing PHY Update event
Fix missing PHY update event generation on same procedure
collision,

This fixes TP/CON/SLA/BV-44-C [Handling Protocol Collision –
Same Procedure] conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada c9a9d0f708 Bluetooth: controller: Fix PHY update with no change in PHY
Fix PHY update procedure intiation to use correct No Change
value in MtoS and StoM when there is no change to respective
PHYs. Also, added missing HCI event generation under this
case.

This fixes TP/CON/MAS/BV-41-C [Initiating PHY Update
Procedure] conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 21935f7dd6 Bluetooth: controller: Fix asymmetric PHY by using correct tIFS
Fix asymmetric PHY connection by using correct tIFS,
considering previous PHY and next PHY chain delays while
calculating the Tx and Rx tIFS.

This fixes:
TP/CON/SLA/BV-40-C [Initiating PHY Update Procedure]
TP/CON/SLA/BV-42-C [Responding to PHY Update Procedure]
TP/CON/MAS/BV-41-C [Initiating PHY Update Procedure]
TP/CON/MAS/BV-43-C [Responding to PHY Update Procedure]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada df5deea218 Bluetooth: controller: Fix header complete timeout calculation
Fix header complete timeout calculation by using Rx PHY
chain delay instead of incorrectly used Tx PHY chain delay.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada a682554231 Bluetooth: controller: Fix slave drift compensation
As ticker can only drift in 32kHz units, the slave Rx
window should consider a +/- one 32kHz unit in addition to
+/- 16us jitter of the master. Hence, for the current
implementation the slave Rx window jitter is +/- 48us.
Future improvement can be done by using remainder of 32kHz
unit drift to reduce this jitter to +/- 16us.

With this fix 20ppm clock accuracy passes conformance TIM
tests (else 251-500ppm had to be used).

Problem was not seen in real life as master do not have a
+/- 16us jitter.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 1ff96f2588 Bluetooth: controller: Fix terminate procedure timeout
Fix terminate procedure timeout when supervision timeout
equals connection interval. In this case, avoid timing out
in the first event of procedure initiation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada b0f3944e90 Bluetooth: controller: Fix slave sending reject_ext_ind
Fix slave implementation to initiate reject_ext_ind if peer
supports reject_ext_ind.

This fixes:
TP/SEC/SLA/BV-11-C [Slave Sending Reject_Ind_Ext]
conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 0883915a1e Bluetooth: controller: Fix master rx-ing reject_ext_ind enc_req
Fix master receiving REJECT_EXT_IND for ENC_REQ PDU.

This fixes:
TP/SEC/MAS/BV-11-C [Master Receiving Reject_Ind_Ext]
conformance test in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada 8bf3d5d98f Bluetooth: controller: Fix for unexpected PDU during Enc setup
Fix for handling unexpected PDU during Encryption start.

This fixes:
TP/SEC/MAS/BV-14-C [Master Receiving unexpected PDU during
encryption start], and
TP/SEC/SLA/BI-05-C [Slave Receiving unexpected PDU during
encryption start]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada b187b1b949 Bluetooth: controller: Fix handling invalid control PDUs
Fix handling invalid control PDUs by generating
LL_UNKNOWN_RSP PDU.

This fixes:
TP/PAC/SLA/BV-01-C [Unknown Packet from Master]
TP/PAC/MAS/BV-01-C [Unknown Packet from Slave]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada f80344f0fe Bluetooth: controller: Fix access address generation
Fix access address generation to correctly have two
transitions in the six MS bits and add other missing checks.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Vinayak Kariappa Chettimada d6506c1f54 Bluetooth: controller: Minor cleanup of enc pause impl.
Minor cleanup of Encryption Restart Procedure; No need to
pause rx for slave role on reception of PAUSE_ENC_RSP PDU as
its already paused.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-31 13:51:16 +03:00
Luiz Augusto von Dentz 59e9d7ad1c Bluetooth: L2CAP: Store sent data in the correct buffer
The buf variable may have been unrefed by net_buf_frag_del thus it shall
not be used to store the sent data nor it should be in the
chan->tx_queue.

Jira: ZEP-2395

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-30 18:00:17 +03:00
Vinayak Kariappa Chettimada ca143612bf Bluetooth: controller: Fix assert on create connection
Fix assert in the controller on master connection creation
due to the CONNECT_IND PDU being transmitted beyond the
calculated scan window.

This is related to commit 80a796b493 ("Bluetooth:
controller: Fix scanner to use correct slot ticks")

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-29 09:51:20 +03:00
Vinayak Kariappa Chettimada b380ab0251 Bluetooth: controller: Fix assert, reset ticker_id_prepare
Fix an assert in next role event preparation when a
connection terminated during the connection event being
aborted/pre-empted out by the next role event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-28 13:41:16 -07:00
Johan Hedberg c878bbdf08 Bluetooth: Mesh: Fix advertising thread initialization
Recent thread API update patches failed to update the mesh advertising
thread initialization.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-27 11:38:01 +03:00
Kumar Gala a45dac0bd1 dts: fix Kconfig enablment of BLUETOOTH_MONITOR_ON_DEV_NAME
Since we generate BLUETOOTH_MONITOR_ON_DEV_NAME based on dts we need a
!HAS_DTS check around it.  Otherwise we can get into odd build errors.
Its also possibly that we don't specify "zephyr,bt-mon-uart" and in that
case we default to CONFIG_UART_CONSOLE_ON_DEV_NAME (ie 'zephyr,console'
on DTS platforms).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-07-25 12:23:20 -05:00
Vinayak Kariappa Chettimada 255e5cc344 Bluetooth: controller: Implement Read/Write Auth Payload timeout
Added implementation to support HCI Read Authenticated
Payload Timeout Command and HCI Write Authenticated Payload
Timeout Command.

This fixes:
TP/SEC/SLA/BV-08-C [No response to LL_PING_REQ]
TP/SEC/SLA/BV-09-C [Modified Authentication Payload Timeout]
TP/SEC/MAS/BV-08-C [No response to LL_PING_REQ]
TP/SEC/MAS/BV-09-C [Modified Authentication Payload Timeout]
conformance tests in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-22 11:55:35 +03:00
Johan Hedberg 0ec2630882 Bluetooth: Mesh: Add initial implementation
Add an initial implementation for the Bluetooth Mesh Profile
Specification. The main code resides in subsys/bluetooth/host/mesh and
the public API can be found in include/bluetooth/mesh.h. There are a
couple of samples provided as well under samples/bluetooth and
tests/bluetooth.

The implementation covers all layers of the Bluetooth Mesh stack and
most optional features as well. The following is a list of some of
these features and the c-files where the implementation can be found:

 - GATT & Advertising bearers (proxy.c & adv.c)
 - Network Layer (net.c)
 - Lower and Upper Transport Layers (transport.c)
 - Access Layer (access.c)
 - Foundation Models, Server role (health.c & cfg.c)
 - Both PB-ADV and PB-GATT based provisioning (prov.c)
 - Low Power Node support (lpn.c)
 - Relay support (net.c)
 - GATT Proxy (proxy.c)

Notable features that are *not* part of the implementation:

 - Friend support (initial bits are in place in friend.c)
 - Provisioner support (low-value for typical Zephyr devices)
 - GATT Client (low-value for typical Zephyr devices)

Jira: ZEP-2360

Change-Id: Ic773113dbfd84878ff8cee7fe2bb948f0ace19ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-20 09:30:44 +03:00
Carles Cufi 35b34c2e65 Bluetooth: controller: Only add active slots to hw filter
When populating the hardware filter, add only slots that are marked as
taken to avoid the hardware being confused by all-0 addresses. This
solves an EBQ issue with whitelist filtering.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 22:11:40 +03:00
Carles Cufi 77b0108afd Bluetooth: controller: Avoid warning with privacy disabled
To avoid warnings (seen on some machines) that a function reaches its
end without returning a value, conditionally compile the function in a
way that this cannot happen.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 22:11:40 +03:00
Vinayak Kariappa Chettimada 52ee6622c0 Bluetooth: controller: Fix master terminate procedure
Fix master terminate procedure so that if slave responded to
the ack from master for the LL_TERMINATE_IND then the master
correctly disconnected.

This fixes TP/CON/MAS/BV-09-C [Master Accepting Termination]
in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Tested-by: Ulrich Myhre <ulmy@nordicsemi.no>
2017-07-14 22:11:25 +03:00
Vinayak Kariappa Chettimada 9fc4fefc47 Bluetooth: controller: Fix slave latency enable at conn setup
Fix implementation to maintain a connection in the slave
role not taking slave latency into use before receiving an
acknowledgement from the master.

This fixes TP/CON/ADV/BV-03-C [Master Missing Slave Packets]
in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Tested-by: Ulrich Myhre <ulmy@nordicsemi.no>
2017-07-14 22:11:25 +03:00
Marcel Holtmann aefcf547ad Bluetooth: controller: Add skeleton for vendor HCI commands
Signed-off-by: Marcel Holtmann <marcel.holtmann@intel.com>
2017-07-14 14:54:52 +03:00
Carles Cufi a8173b9033 Bluetooth: controller: Fix privacy whitelist allocation
Fix copy-paste issues when allocating devices in the privacy-enabled
whitelist.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-14 13:07:41 +02:00
Vinayak Kariappa Chettimada 88dba0dd35 Bluetooth: controller: Fix cond. mayfly priority check
When the controller is configured to have its worker and job
be run at different interrupt priority, check for mayfly
priority being equal was incorrect.

Fixed by conditionally compiling the correct check of mayfly
priority level.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 10:01:15 +02:00
Vinayak Kariappa Chettimada 9dc7975b76 Bluetooth: controller: Fix to use correct anchor for scanner
Fixed a defect wherein anchor for first scanner event was in
the past (when looking for a free timeslice to avoid
overlapping with master role events) when actually there
were no master roles active. This defect caused the scanner
role to assert, when started with other roles active (eg.
advertiser), when trying to catch-up to current tick.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada 449295eee3 Bluetooth: controller: Revert fix for assert due to stale tick
This reverts commit 3c23c6f53d ("Bluetooth: controller:
Fix assert due to stale tick count") as this leads to
connection events to be skipped, failing conformance tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada de6ed122a8 Bluetooth: controller: Revert fix for scanner Rx window hang
This reverts commit b5235207d3 ("Bluetooth: controller:
Fix for scanner Rx window hang") as this leads to
connection events to be skipped, failing conformance tests.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-14 09:23:28 +02:00
Vinayak Kariappa Chettimada b07e7f2b5a Bluetooth: controller: Fix T_Terminate and other timeout calc.
Fix calculation of T_Terminate and other procedure timers by
using ceil on calculated connection interval units.

This fixes TP/CON/MAS/BI-02-C [Master T_Terminate Timer] and
TP/CON/SLA/BI-02-C [Slave T_Terminate Timer] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Vinayak Kariappa Chettimada 2800961fe1 Bluetooth: controller: Fix supervision timeout countdown
Add missing supervision timeout countdown initiation on CRC
error.

This fixes TP/CON/ADV/BI-01-C [Connection Supervision
Timeout during Fail Connection Setup] and TP/CON/INI/BI-02-C
[Slave Packets Invalid CRC] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Vinayak Kariappa Chettimada 97bfb1d9f4 Bluetooth: controller: Fix slave conn. failed to be established
Fix implementation so that both slave and master behave same
during connection setup and generate disconnection complete
with reason 0x3e (connection failed to be established).

This fixes TP/CON/ADV/BV-02-C [Accepting Connections
Timeout] in LL.TS.5.0.0.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Ulrich Solli Myhre <ulmy@nordicsemi.no>
2017-07-13 15:39:42 +03:00
Carles Cufi 6886f979cf Bluetooth: controller: Allow devices not in resolving list
Whenever not using the whitelist the resolving list is traversed to
verify that the device is allowed depending on its current privacy mode.
In the case where the device is not found by address in the resolving
list, allow the request to go through, since we are then dealing with an
unknown devices and the resolving list restrictions do not apply.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-13 14:07:27 +03:00
Carles Cufi 4666015323 Bluetooth: controller: Fix regression in WL filter population
Erroneous check conversion triggered a regression when populating the
whitelist filter.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-13 09:29:16 +02:00
Luiz Augusto von Dentz 16e6abbcfb Bluetooth: L2CAP: Don't reuse RX buffers to respond
This causes num of packets command handling to dead lock since it
is done on RX buffer destroy if used on TX it may not be destroyed
on time causing.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-12 17:37:45 +03:00
Carles Cufi c9bd30aa90 Bluetooth: controller: Check AdvA in scan requests
The specification states that the AdvA in a Scan Request packet should
be identical to the one sent in the original advertising packet, so
check this when processing a Scan Request.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 486dad9e4c Bluetooth: controller: Fix RL permission check
When the initiator is using an RPA and we match it using the filtering,
we should return early and allow the device packet through instead of
going through the whole resolving list.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 7b02b06b41 Bluetooth: controller: Fix directed adv filtering
The specification states that filter policies shall be ignored for
directed advertising, so reflect this behaviour in the code.
Additionally when the local device is using RPAs but the peer uses an
identity address, the resolving list index needs to be updated when
traversing the RL to reflect that there has indeed been a  device match
even though the IRK match did not happen.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02:00
Carles Cufi 968e4089d1 Bluetooth: controller: Fix AdvA checks in advertiser
The AdvA in the CONN_IND packet must match the AdvA in the advertising
packet that triggered it regardless of the advertising type.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-12 14:53:29 +02: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
Luiz Augusto von Dentz a864436559 Bluetooth: Shell: Add second vendor service
This adds a second vendor service testing if service changed indications
works with more than one change in a row and as a bonus it implements
echo attribute which notifies any data that is written to it:

> ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Command (0x52) len 4
        Handle: 0x0013
          Data: 0000
< ACL Data RX: Handle 3585 flags 0x02 dlen 9
      ATT: Handle Value Notification (0x1b) len 4
        Handle: 0x0013
          Data: 0000

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-11 08:22:22 +03:00
Luiz Augusto von Dentz 17b340cc13 Bluetooth: Shell: Implement support for gatt-metrics off
With introduction of bt_gatt_service_unregister it is now possible to
unregister service at runtime.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-11 08:22:22 +03:00
Luiz Augusto von Dentz 42c2b2ea81 Bluetooth: GATT: Rework Service Changed indications
There could be situations where many services are changed in a row which
would cause k_sem_take to block on the second change, but if the calling
thread is actually the RX thread then this will deadlock since the RX
thread is the one processing the confirmations of indications and it is
blocked k_sem_give is never called.

To solve this the services changes are now offloaded to the system wq
and the code will attempt to consolidate the range being changed so only
one indication is send. If for some reason another changes is caused
while confirmation is pending we just reschedule it to run later to
avoid blocking the system wq in the same way.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-07-11 08:22:22 +03:00
Carles Cufi f6260d6adb Bluetooth: controller: Rename whitelist arrays
For consistency with the Resolving List, rename the whitelist filter to
match its type and the privacy-enabled version to align it with the
short name used in the RL.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-10 20:47:51 +02:00
Carles Cufi a99d1f8fe6 Bluetooth: controller: Fix resolving list error handling
To correctly handle the allocation and deallocation of resolving list
items, the ll_rl_find and wl_pees_find functions have been modified to
return an invalid index instead of a negative value in case of error.
This is to avoid the ambiguity when mixing indices and negative numbers,
which does not play well with the first index 0.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-10 20:47:51 +02: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
Vinayak Kariappa Chettimada be003be10a Bluetooth: Decrease Rx processing priority
The following error and warning is received when connecting
to certain central devices:
[bt] [ERR] hci_num_completed_packets: packets count mismatch
[bt] [WRN] bt_att_recv: Ignoring unexpected request

This could happen if Tx-ed packet is not added to pending
list before a num of completed packets event and/or new Rx
packet is received.

This is fixed by reducing the Rx thread priorities in the
Host and the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-07 10:33:55 +03:00
Johan Hedberg 58d87ff530 Bluetooth: conn: Fix notifying all pending tx packets in send_frag()
The code in send_frag() depends on being able to allocate a new
pending tx contexts with 100% certainty. We must therefore notify
*all* connections instead of the current one in order to ensure that
there are free contexts available in free_tx.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-06 20:46:25 +03:00
Johan Hedberg 4f62c07960 Bluetooth: Fix bogus decoding of 8-bit num_handles as 16-bit
The num_handles parameter of the Number Of Completed Packets event is
8-bits and not 16-bits, so no helper variable or byte order conversion
is needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-06 15:57:10 +03:00
Johan Hedberg baf4f0c912 Bluetooth: conn: Switch order of tx_notify & tx_queue
In case both conn->tx_notify and conn->tx_queue have data in them we
should first process the notify queue and only then new outgoing
packets.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-06 14:58:35 +03:00
Vinayak Kariappa Chettimada b56768b626 Bluetooth: controller: Fix first interval to be within +/-16us
Due to the missing remainder support in the ticker_start
function for first interval, fix implementation so as to
round the first interval/offset during master connection
setup and connection update to within +/-16us.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-06 14:48:32 +03:00
Johan Hedberg 259701149b Bluetooth: Clean up struct bt_conn
Fix alignment of rx_len, and move err & state to a better location to
minimize padding.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-05 12:40:11 +03:00
Johan Hedberg 30beef9419 Bluetooth: GATT Introduce BT_GATT_CCC_MAX helper define
The worst-case maximum number of CCC entries we need is actually
MAX_CONN + MAX_PAIRED. Provide a helper define for it and use it
whenever appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-04 17:30:40 +03:00
Johan Hedberg cf1f3c26a5 Bluetooth: Kconfig: let MAX_PAIRED be 0 if SMP is not supported
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-04 17:30:40 +03:00
Carles Cufi d990079f15 Bluetooth: controller: Fix HCI remote version structure
The HCI Read Remote Version Information Complete event structure was
incorrect, leading to qualification test failures. This patch fixes the
structure and also the storing of the data in an endianness-agnostic
manner.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 13:43:48 +03:00
Carles Cufi 269a828cb1 Bluetooth: controller: Use RL indices in adv ISR
To avoid manipulation of the irkmatch_ok and irkmatch_id, rely instead
on Resolving List indices for all checks in the advertising ISR.
Although we do incur in a small overhead to look it up initially, the
overall gains are worth the change.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 09:30:46 +03:00
Vinayak Kariappa Chettimada 2dd375ef45 Bluetooth: controller: Fix advertisement event lengths
The Controller reserved more than required time for
advertisement event length. Due to this, directed
advertisements did not meet the required <= 3.75ms
interval. It is now fixed by having event lengths based
on the advertisement PDU types.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-04 08:16:29 +03:00
Vinayak Kariappa Chettimada 879c49ce91 Bluetooth: controller: Rename chl_* to chan_*
Rename use of chl_* namespace to more commonly used chan_*.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-04 08:16:29 +03:00
Carles Cufi 389736277b Bluetooth: controller: Fix Event Mask Page 2 handling
Correct the default value (0x0) for the Event Mask Page 2 and add the
command to set it to the list of supported commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-04 08:15:52 +03:00
Carles Cufi fc14bfbe2f Bluetooth: controller: Filter Auth Payload timeout exp
Correctly filter out the Authenticated Payload Timeout Expired event
based on the bit present on page 2 of the Event Mask.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Carles Cufi 73378e1cad Bluetooth: controller: Add support for Event Mask Page 2
In order to be able to filter events present in Page 2 of the Event
Mask, this command allows the Host to set the Page 2 of the bitmask
through the corresponding command.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Carles Cufi b97a4670a6 Bluetooth: controller: Reset filters correctly
Reset and initialize filters correctly based on whether privacy is
enabled in the controller. Particularly relevant in the case of the
whitelist, which is handled in a completely different way if privacy is
enabled. Additionally reset the peer IRK list in the resolving list
whenever the list itself is cleared.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
Vinayak Kariappa Chettimada 3779fb626a Bluetooth: controller: Increase ticker operations in thread mode
When flashing in synchronous mode with BLE roles active,
ticker function calls will be deferred to avoid radio ISR
latencies. Increase the total operations supported by 1, to
accommodate flash driver's use of ticker operations.

It has been observed, without this increase, either the
flash driver returned -ECANCEL or the BLE Controller
asserted on data transmit as a slave (trying to force data
transmit on earliest connection event interval).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-07-01 13:21:38 +02:00
Johan Hedberg 2684775d0f Bluetooth: monitor: Remove interrupt locking from monitor_console_out()
Locking interrupts for a long duration is in general bad design, and
is particularly bad for the controller which depends on low latency
interrupts. Instead of using interrupt locking introduce a new flag to
track the shared buffer usage and simply drop characters if the flag
is set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-30 17:19:56 +03:00
Carles Cufi 803eab08ec Bluetooth: controller: Privacy filtering in advertiser
Implement privacy-enabled filtering in the advertiser role. This
includes all required checks when running address generation and
resolution so that the advertiser complies with the relevant
specification sections.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-30 17:19:30 +03:00
Vinayak Kariappa Chettimada 4362eda4aa Bluetooth: controller: Fix missing re-initialization of ret_cb
Fix missing re-initialization of ret_cb to
TICKER_STATUS_BUSY before every new call to ticker interface
functions' with operation's callback.

One issue was undirected advertisement disable to return
failure status in the scan_adv sample.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada b5235207d3 Bluetooth: controller: Fix for scanner Rx window hang
With the fix in commit 3c23c6f53d ("Bluetooth: controller:
Fix assert due to stale tick count") it is required that a
skipping event shall abort the previous role in order to
enable the ticker_job to resume and reschedule next ticker
expiry.

In the scan_adv sample, with continuous scanning, an
advertiser would pre-empt it, but if the advertiser skipped
its event without aborting the scanner, the scanner is hung
with its rx window without a timeout, and HCI command to
stop the advertiser will wait forever to complete.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Vinayak Kariappa Chettimada 80a796b493 Bluetooth: controller: Fix scanner to use correct slot ticks
The scanner was reserving a little less slot ticks which
caused other roles to overlap before scan window could
close.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-30 13:42:33 +03:00
Johan Hedberg c55870e885 Bluetooth: hci_ecc: Use ATOMIC_DEFINE() for the flags
This doesn't make much practical difference, however it should resolve
Coverity CIDs 170740 and 170748.

Jira: ZEP-2343

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-30 12:55:33 +03:00
Vinayak Kariappa Chettimada 2f29d7904f Bluetooth: controller: Fix hardfault, out-of-range ticker access
With the ticker for flash driver added, the Controller was
corrupting memory outside its allocations by incorrectly
using the flash ticker instance to be a BLE role and
corrupting memory. This is now fixed by checking for the
ticker ids to be within the Controller's use before using
them.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-29 16:54:34 +03:00
Johan Hedberg a5ae267e92 Bluetooth: Introduce new BT_LE_ADV_OPT_ONE_TIME advertising option
In some cases applications may want better control of advertising
instead of the stack doing automated re-enablement. Introduce a new
option that can be used to do more "manual" advertising control.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-29 15:08:00 +03:00
Johan Hedberg 3cb4d295d0 Bluetooth: Fix KEEP_ADVERTISING flag treatment in bt_le_adv_stop()
The BT_DEV_ADVERTISING flag already does a suffient job with tracking
the actual advertising state, so there's no need for bt_le_adv_stop()
to return an error if KEEP_ADVERTISING is set. We still need to clear
KEEP_ADVERTISING, but it should not be considered an error if it was
not set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-29 15:08:00 +03:00
Vinayak Kariappa Chettimada ed85dea358 Bluetooth: shell: Fix compile warnings when CONFIG_DEBUG=y
Fixed uninitialised auto variables, that had caused compile
errors under CONFIG_DEBUG=y.

Jira: Zep-2334

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-29 07:43:54 +03:00
Johan Hedberg 4040610244 Bluetooth: shell: Fix incorrect #define
This should have been upper case and not lower case.

Fixes: ZEP-2322

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-28 09:52:26 -04:00
Vinayak Kariappa Chettimada 040b85bfbc Bluetooth: controller: Temporarily disable scan req notification
Temporarily, disable scan request notification reports when
LE Advertising Extensions feature is enabled; as support for
enabling scan request notification is not yet added to the
Controller's Link Layer interface functions, yet.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-28 15:00:47 +02:00
Andrzej Puzdrowski 9f964ba8d3 bluetooth: shell: add module for testing NRF5x flash driver
Intention is to test flash driver along with BLE radio.
Added flash shell module with commands for erase, write-check, read and
co-operation with radio stress test.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-06-28 12:29:50 +02:00
Andrzej Puzdrowski 7e6b9fa841 Bluetooth: controller: support for code exe. in co-operation with radio
Extend radio ticker nodes for support in-timeslice execution
Added interface for abort the radio
Added interface for check whether the radio is idle

Added interface for get ticker IDs for timeslice ticker node
Added interface for check whether radio ticker is running
Added interface for check whether radio ticker is initialized

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2017-06-28 12:29:50 +02:00
Carles Cufi 386c524f93 Bluetooth: controller: Keep track of IRK to RL indices
In order to associate a hit on the hardware IRK filtering with an entry
of the resolving list, add an array of correspondance between the IRKs
and the resolving list entries.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 59ff81ca28 Bluetooth: controller: Add wl bit in resolving list
In order for some of the required checks in the ISR to be performed, we
need to keep track of which of the items in the resolving list are in
the whitelist as well. Track them using a single bit in the resolving
list entries.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 4a016db283 Bluetooth: controller: Add device match ID radio API
In order to obtain the ID (index) of the device matched in a hardware
filter, a new API call has been added along with the required
implementation for nRF5x devices.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Carles Cufi 1a07179a3c Bluetooth: controller: Generate RPAs for scanning and initating
Start RPA generation when enabling the scanner either for observing or
for initiating.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-27 22:26:43 +03:00
Vinayak Kariappa Chettimada 4ba2bb0d1c Bluetooth: controller: Be fair when pre-empting a ticker
When force scheduling a ticker use the number of times the
tickers have already skipped their intervals to decide if
the forced ticker can pre-empt the colliding ticker. This
introduces a fairness amongst tickers contesting for the
overlapping time slice.

Flashing in co-operation with Radio needs to be fair in
order to avoid connection supervision timeouts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-27 21:16:56 +02:00
Vinayak Kariappa Chettimada 95d55a2bfc Bluetooth: controller: Do not skip one-shot tickers with slot
In preparation towards mesh advertise implementation, avoid
one-shot tickers with slots, that have been scheduled to
expire, from being removed by a forced start or update
operation on another ticker.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-27 21:16:56 +02:00
Vinayak Kariappa Chettimada 07270e52ba Bluetooth: controller: Coding style and refactoring
Refactoring of ticker implementation to conform to Zephyr
coding style.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-27 21:16:56 +02:00
Johan Hedberg 8f9c305a15 Bluetooth: Move PRNG initialization a bit later in HCI init
Move the PRNG initialization after reading local supported commands,
so that we don't send HCI_LE_Rand if the controller doesn't support it
(we still need to fail the init however). The patch also removes a few
unnecessary #ifdefs related to crypto.h.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-27 13:16:16 +03:00
Carles Cufi 0f0c45ce7c Bluetooth: controller: Optimize RL addition
To avoid iterating twice through the list, have ll_rl_find() return the
first free empty slot on the list.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi 2c1dbd21f4 Bluetooth: controller: Handle Privacy Modes
Add handling of the LE Set Privacy Mode HCI Command along with the logic
required to take it into account when populating the hardware filters.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-26 15:04:16 +03:00
Carles Cufi bd31ad11de Bluetooth: controller: Add RL filter
In order for privacy to work correctly with and without peer IRKs, an
additional hardware filter is required to help match the peer device in
the case address resolution is not possible for a peer since the Host
has not provided a peer IRK for it.

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-25 14:26:08 +03:00
Carles Cufi cb8be12595 Bluetooth: Fortify role dependency
Since the peripheral role depends on the broadcaster one, and the
central role depends on the observer one, select them automatically
instead of using defaults.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-25 14:26:08 +03:00
Johan Hedberg 9b1653061a Bluetooth: conn: Add pending tx before calling bt_send()
It's possible that the controller will emit the number of completed
packets event before bt_send() returns, or possibly preempt
send_frag() before it manages to call add_pending_tx(). We have to
therefore add the pending TX entry before calling bt_send().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-23 18:02:08 +03:00
Vinayak Kariappa Chettimada 3c23c6f53d Bluetooth: controller: Fix assert due to stale tick count
Fixed assert due to stale tick count in role event
preparation. This happens when ticker timeout expiry is
delayed from the requested realtime anchor, due to thread
mode processing overheads and occurring interrupts therein,
if any, that added a delay between requested anchor tick
and actual scheduling for the requested ticker timeout.

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 21:37:22 +03:00
Luiz Augusto von Dentz a6b37b072b Bluetooth: GATT: Rename bt_gatt_unregister_service
Rename bt_gatt_unregister_service to bt_gatt_service_unregister to be
consistent with other APIs such as bt_gatt_service_register.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-20 15:32:16 +03:00
Carles Cufi 4053470f62 Bluetooth: controller: Add inital support for Controller-based privacy
This initial commit adds the following:

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

Follow-up commits will expand the functionality.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Carles Cufi 1506b24fb8 Bluetooth: Correctly select RPA and TINYCRYPT options
Enforce the logical dependency between SMP, RPA generation and privacy
in the Kconfig files for the Bluetooth subsysem.

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-20 15:20:09 +03:00
Anas Nashif 397d29db42 linker: move all linker headers to include/linker
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-06-18 09:24:04 -05:00
Vinayak Kariappa Chettimada f4242b0723 Bluetooth: controller: Use find_lsb_set instead of custom ffs
Use globally available find_lsb_set in Zephyr instead of a
custom find first set function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-16 09:40:41 -05:00
Johan Hedberg 9703927f84 net: buf: Move net_buf_pool objects to dedicated linker area
Moving the net_buf_pool objects to a dedicated area lets us access
them by array offset into this area instead of directly by pointer.
This helps reduce the size of net_buf objects by 4 bytes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-16 17:05:06 +03:00
Luiz Augusto von Dentz 272b3a5c99 Bluetooth: Shell: Add gatt-show-db command
gatt-show-db shows the current set of attributes available in the GATT
database:

bt> gatt-show-db
attr 0x0011ce80 handle 0x0001 uuid 2800 perm 0x01
attr 0x0011ce94 handle 0x0002 uuid 2803 perm 0x01
attr 0x0011cea8 handle 0x0003 uuid 2a00 perm 0x01
attr 0x0011cebc handle 0x0004 uuid 2803 perm 0x01
attr 0x0011ced0 handle 0x0005 uuid 2a01 perm 0x01
attr 0x0011cde0 handle 0x0006 uuid 2800 perm 0x01
attr 0x0011cdf4 handle 0x0007 uuid 2803 perm 0x01
attr 0x0011ce08 handle 0x0008 uuid 2a05 perm 0x00
attr 0x0011ce1c handle 0x0009 uuid 2902 perm 0x03
attr 0x0011c9a0 handle 0x000a uuid 2800 perm 0x01
attr 0x0011c9b4 handle 0x000b uuid 2803 perm 0x01

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 01eeb5ea0b Bluetooth: Shell: Add gatt-unregister-service command
gatt-unregister-service can be used to remove the test service at
runtime causing service changed to be indicated:

00:1b:dc:07:31:88 (public)> gatt-unregister-service
[bt] [DBG] gatt_indicate: (0x0011e100) conn 0x0011d880 handle 0x0008
[bt] [DBG] bt_att_req_send: (0x0011e100) conn 0x0011d880 req 0x0011db00
[bt] [DBG] att_send_req: (0x0011e100) req 0x0011db00
Unregistering test vendor service

< ACL Data TX: Handle 3585 flags 0x00 dlen 11
      ATT: Handle Value Indication (0x1d) len 6
        Handle: 0x0008
          Data: 0a001000
> ACL Data RX: Handle 3585 flags 0x02 dlen 5
      ATT: Handle Value Confirmation (0x1e) len 0

Jira: ZEP-2225
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 3602590b9c Bluetooth: GATT: Add bt_gatt_unregister_service
With the introduction of Service Changed support it is now possible to
unregister services at runtime.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 79af35991b Bluetooth: GATT: Add bt_gatt_register_service
This adds bt_gatt_register_service using bt_gatt_service which contains
the attribute array that is then added to the database saving a pointer
in each and every attribute declared.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 79a723b3fa Bluetooth: GATT: Indicate Service Changed when a service is added
If the database is changed indicate the range changed to all peers
subscribed.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz aa5b47fc3f Bluetooth: GATT: Add GATT service by default
GATT is mandatory service and now that the db can only be build
dynamically there is no reason to keep the applications registering it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz d837a6ec4b Bluetooth: GATT: Add GAP service by default
GAP is mandatory service and now that the db can only be build
dynamically there is no reason to keep the applications registering it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 6058c699b4 Bluetooth: Kconfig: Add CONFIG_BLUETOOTH_DEVICE_APPEARANCE
This makes applications able to select the value used for the
GAP appearance attribute.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz b3cfabab63 Bluetooth: Remove CONFIG_BLUETOOTH_GATT_DYNAMIC_DB
Removes CONFIG_BLUETOOTH_GATT_DYNAMIC_DB in preparation to the
introduction of bt_gatt_unregister.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 21:53:00 +03:00
Luiz Augusto von Dentz 3910056505 Bluetooth: ATT: Fix adding timeout for NULL request
In certain cases a response may happen even before number of complete
packets is generated by the controller:

[bt] [DBG] att_req_destroy: (0x0011cfe0) req 0x0011daa0
[bt] [DBG] att_process: (0x0011cfe0)
[bt] [DBG] att_req_sent: (0x0011d780) conn 0x0011d820 att 0x0011d9a0
 att->req 0x00000000

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-15 19:26:50 +03:00
Vinayak Kariappa Chettimada 1dd5462320 Bluetooth: controller: Move scan response data swap outside tIFS
In preparation towards Privacy 1.2, move implementation that
swapped scan response PDU double buffer to same place as
where adv data PDU double buffer is swapped. So that, change
in AdvA in adv data PDU can be reflected in scan response
PDU buffer.

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-15 15:54:24 +02:00
Carles Cufi 7d075f527b Bluetooth: Enforce cooperative priorities in Bluetooth threads
The Bluetooth subsystem assumes execution of its system threads in
cooperative priority, including the system workqueue and the thread
that interact with the controller (i.e. calling bt_send). This commit
adds a compile-time check for the system workqueue priority and
documentation for the bt_send API call.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-06-15 16:37:49 +03:00
Vinayak Kariappa Chettimada 8877348aec Bluetooth: shell: Fix compile error with LL cmds included
Fixed compile error due to the missing header file
dependency on bluetooth/hci.h, for bt_addr_le_t, in the
Link Layer header file.

Merge of PR #475 introduced the new dependency that broke
compilation after merge of #474.

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 17:42:27 +02:00
Vinayak Kariappa Chettimada dc11c9c315 Bluetooth: shell: Add Extended Scan command
Add shell scanx command to start Extended Scanning on 1M or
Coded PHY.

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

Jira: ZEP-2238

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-14 18:40:40 +03:00
Vinayak Kariappa Chettimada 128a0613cd Bluetooth: shell: Add LE Adv. Ext. advx command
Add Bluetooth Link Layer LE Advertising Extensions commands
for manual testing the feature during development. First one
being advx command to start non-connectable non-scannable
extended advertising.

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

Jira: ZEP-2238

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

Jira: ZEP-2073

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-09 10:33:06 +02:00
Vinayak Kariappa Chettimada 0998cdfba1 Bluetooth: shell: gatt-write-without-response with repeat
Add a repeat param to gatt-write-without-response so that
it covers what gatt-write-without-response-repeated was
doing. gatt-write-without-response was removed in the
commit 26eae70da.

gatt-write-signed too will have repeat param with this
change.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-04 09:34:08 +03:00
Andrei Emeltchenko f1f5275779 bluetooth: Allow to specify Logging Domain
At the moment all bluetooth logs are prefixed with [bt] making it
difficult to understand where the logs belong to.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2017-06-02 21:52:17 +03:00
Johan Hedberg 67faa3fe98 Bluetooth: L2CAP: Remove redundant checks for chan->ops
It's mandatory to set chan->ops so explicit checks for it are
redundant. What's worse, inconsistent checking for this triggers
static code analyzer warnings. This patch fixes Coverity CID 151984.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-06-01 15:09:16 +03:00
Jaganath Kanakkassery 7ac75784d1 Bluetooth: SDP: Fix possible out of bound memory access
buf->len should be validated before accessing it since remote can
send invalid frame_len which can result in out of bound memory
access.

This also fix the len check wrt cstate, since current check is
not considering the cstate length size and frame_len size.

Jira: ZEP-2110
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-06-01 12:36:09 +03:00
Vinayak Kariappa Chettimada a3cba8bb90 Bluetooth: shell: Add controller's ticker shell module
Added shell module for the Bluetooth Controller's ticker
interfaces.

For now, info command enumerates active tickers' details.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-06-01 12:32:47 +03:00
Luiz Augusto von Dentz da86ae0cb6 Bluetooth: Shell: Rework gatt-write-signed
This makes gatt-write-signed to reuse cmd_gatt_write_without_rsp since
it is quite similar and that adds the ability to send multiple octecs
instead of just a single byte.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz a5aa904f90 Bluetooth: Shell: Fix help of gatt-write-signed
gatt-write-signed does not have an offset parameter.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 26eae70da2 Bluetooth: Shell: Remove gatt-write-without-response-repeated
This removes gatt-write-without-response-repeated and makes
gatt-write-without-response similar to gatt-write which was the
intention of gatt-write-without-response-repeated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 6107f61d8c Bluetooth: Shell: Fix help of gatt-write-without-response
gatt-write-without-response does not have an offset parameter.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 6abccb6d40 Bluetooth: Shell: Split GATT command to its own file
This makes it simpler to organize the GATT command implementation.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 54d917f767 Bluetooth: Shell: Add shell subdir if CONFIG_BLUETOOTH_SHELL=y
All the files under shell subdir shall only be build if
CONFIG_BLUETOOTH_SHELL is selected.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 16:39:05 +03:00
Luiz Augusto von Dentz 7b9013140d Bluetooth: GATT: Fix not queuing writes to CCC
In order to properly queue request there need to be a bt_att_req
storage but none of the calls to gatt_write_ccc were using the params
causing gatt_send to use bt_att_send and not bt_att_req_send.

To fix this now all the callers of gatt_write_ccc do set the params
properly but this means that bt_gatt_unsubscribe has to wait for it
to be completed before the application can reuse the
bt_gatt_subscribe_params.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 14:34:11 +03:00
Vinayak Kariappa Chettimada 5d91b2ffe9 Bluetooth: controller: Explicitly compare radio event registers
While returning 32-bit values from radio status interfaces,
explicitly compare radio h/w event registers to be non-zero,
dont just return the direct 32-bit h/w register content.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-30 11:03:05 +03:00
Johan Hedberg a7ebfa948b Bluetooth: ATT: Fix canceling ATT timeout upon response
For some write requests, such as CCC, the code doesn't use an ATT
request context but we still need to clear the request timeout when
the response comes. Move the k_delayed_work_cancel() call to the right
place and add some debug logs that helped pinpoint this issue.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-29 21:50:34 +03:00
Johan Hedberg 8068b9ad65 Bluetooth: ATT: Improve response logging
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-29 21:50:34 +03:00
Vinayak Kariappa Chettimada fe3aeebcfa Bluetooth: shell: Fix scan on to use active scanning
Both scan on and scan passive performed passive scanning,
fixed scan on command to use active scanning.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-29 18:21:36 +03:00
Johan Hedberg 1e5cd1c69b Bluetooth: Add kernel call stack analysis upon disconnection
It's useful to see all stack usages and not just the Bluetooth
internal ones.

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

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

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-29 17:08:52 +03:00
Luiz Augusto von Dentz 737a9dc306 Shell: bt: Use SHELL_REGISTER_WITH_PROMPT
This replaces the use of shell_register_prompt_handler with
SHELL_REGISTER_WITH_PROMPT which doesn't overwrite other modules
prompt.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz 12d1b2aa32 Shell: bt: Fix build without CONFIG_BLUETOOTH_GATT_CLIENT
If CONFIG_BLUETOOTH_GATT_CLIENT is not defined disable command that
would depend on it.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz a6f75bebc7 Shell: bt: Add command supported by btshell
This adds existing commands support by btshell test application to bt
module.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Luiz Augusto von Dentz 1c4561925c Shell: Add initial code for bt shell module
This adds the config option and files of the bt shell module.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-29 10:42:21 +03:00
Johan Hedberg 6597896f0a Bluetooth: Fix missing test for BLUETOOTH_CONN with DLE
There's no point in doing anything about DLE if connection support is
not enabled.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-28 16:12:18 +03:00
Carles Cufi d6513eeda3 Bluetooth: controller: Increase RX prio stack size
Due to several changes in the way stacks are calculated, 320 bytes is no
longer enough for the controller-only build. After measuring usages of
up to 320 bytes (locally) and 376 (reported by Ricardo Salveti), the
stack size is increased by 128 bytes, up to 448 bytes.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-26 08:51:04 -07:00
Johan Hedberg a61cf369bf Bluetooth: AVDTP: Remove dead code
The msgtype value is created using 'hdr & 3' which means that the
resulting value can never be greater than 3. This fixes Coverity CID
166771.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-25 09:14:05 -07:00
Vinayak Kariappa Chettimada a730686b7d Bluetooth: Auto-update LE data length to max. supported
Added implementation to auto-update LE Data Length to max.
Tx octets supported by the local and peer controllers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:16:41 -07:00
Vinayak Kariappa Chettimada c6dd9d5ef6 Bluetooth: controller: Handle Rej Ext Ind for Length Req PDU
Added implementation to handle an incoming Reject Ext Ind PDU in
response to a sent Length Req PDU.

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

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

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-24 11:15:47 -07:00
Vinayak Kariappa Chettimada ed187ebccd Bluetooth: Fix auto PHY update on connection
Since the PHY update complete event can be generated due to the
procedure being initiated by the peer, use a flag to
differentiate between local auto update initiated on connection
complete versus peer initiated anytime in the connection. This
is necessary to avoid repeated initiation of auto-update
procedures intended only to be issued on connection complete.

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-16 15:30:51 +03:00
Carles Cufi 6d1ea67144 Bluetooth: hci_core: Log incoming LE Meta Event's subevents
To better debug the flow of events into the Host, log the subevent code
whenever processing an LE Meta Event.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-15 21:02:44 +03:00
Vinayak Kariappa Chettimada 14365080d2 Bluetooth: l2cap: Fix initial credit calculaton for MTU < MPS
When required Rx MTU is less than configured Rx MPS, the
resultant initial credits was 0 which prevented any L2CAP
packet to be received.

Fixed by ceiling the initial credits count in the credits
calculation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-14 09:57:13 +03:00
Vinayak Kariappa Chettimada a891415d97 Bluetooth: Print PHY update complete with status
When HCI core debug is enabled, print PHY update complete
with status on console.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-13 15:27:24 +03:00
Vinayak Kariappa Chettimada dbdc8a24b0 Bluetooth: kconfig: Use menu instead of menuconfig
To be consistent with other subsystem menu, use menu for
Bluetooth support in Kconfig instead of menuconfig which
showed up as checkbox.

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

Jira: ZEP-2132

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

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

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

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

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

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

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-10 08:23:25 +03:00
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
Vinayak Kariappa Chettimada c1041a89a0 Bluetooth: Add PHY auto-update to 2Mbps on connection
Added implementation to auto-update Bluetooth PHY to 2Mbps
if the local Controller supports it.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Chettimada c3adc7b0c7 Bluetooth: controller: PHY Update Procedure
Added support for Bluetooth v5.0 PHY Update Procedure in the
Controller.

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

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

Jira: ZEP-2086

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

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Kariappa Chettimada 2a40bf6a87 Bluetooth: Add LE Features test macro
Added HCI macros to check LE Features. Also, added test
macros for 2M and Coded PHY support in HCI Controller.

Earlier a common test macro was used between BR/EDR and LE,
but since LE features do not use pages for feature, an
explicit macro for testing LE feature is added now.

Also, features field in LE device structure is now a single
dimension array of 8 octets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Carles Cufi 6821df1ef0 Bluetooth: Fix hci_raw's RX buffer alloc
The APIs for allocating RX buffers were modified recently and hci_raw
had not reflected those changes properly.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-08 21:11:08 +03:00
Carles Cufi d34c10725b Bluetooth: Enable events based on features
The event mask population used to let the Controller know which events
are relevant to the Host needs to take into account the features
supported by the Controller itself, in order to only enable those that
are indeed valid.

Jira: ZEP-2050

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

Jira: ZEP-2073

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-04 18:09:31 +03:00
Johan Hedberg b484c1eeed Bluetooth: (Re)introduce ACL host flow control
This feature was removed some time ago, but turns out it's important
to have it available for split host-controller setups.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-05-04 16:38:34 +03:00
Johan Hedberg 70e09b11ea Bluetooth: Introduce buffer type parameter to bt_buf_get_rx
This is preparation for re-introducing host flow control.

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

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

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

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

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

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

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

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

Jira: ZEP-1735

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-03 22:23:42 +03:00
Luiz Augusto von Dentz 024de97473 Bluetooth: ATT: Respond with not support error for unknown PDUs
This ensures that an unknown request won't cause ATT to timeout since
no response is currently generated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-02 12:56:53 -04:00
Vinayak Chettimada b29b3e2fdb Bluetooth: controller: Rename ll_address_* to ll_addr_*
Rename ll_address_* to ll_addr_*. Also, update ll_addr_get
to return reference to stored public or random address.

Change-id: I22cb0135d2223f679c4d9321f4724f8b7de0aede
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Michael Scott c8cb20a5b8 bluetooth: host: fix compile break with CONFIG_ASSERT in gatt.c
Fix the attr->handler reference to attr->handle.

Change-Id: I4a6ccee7860abf800f51df404979eac18eb26e8e
Signed-off-by: Michael Scott <michael.scott@linaro.org>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 3666fb81f5 Bluetooth: hci: Consistently use bt_hci_evt_*
Rename occurences of bt_hci_ev_* to more widely used
bt_hci_evt_* namespace.

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

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

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

Change-id: I6ca665e298b343200c65405739f3998bc78b84e7
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 65e07099a7 Bluetooth: l2cap: Use global conn tx pool for segmentation
L2CAP Dynamic Channel feature uses the global connection Tx
pool for segmentation either when there is no free buffers
in the original application pool or when the original data
buffer has no headroom to add L2CAP headers.

This eliminates the need for a dedicated fallback pool for
Dynamic Channel segmentation.

Change-id: Ia5452c814169d17ef261ecef425a8fcf2e7e1e84
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Johan Hedberg 890bf82aff Bluetooth: conn: Remove shadow iterator variable
This function already has an 'i' variable on the top-level, so no need
to declare a second one that'd just shadow the original.

Change-Id: I5dfa4df2c4793be220a40ac642b19bf440e80220
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Johan Hedberg 512d2ac433 Bluetooth: L2CAP: Fix unnecessary NULL check
The segment allocation function can't fail (it eventually waits with
K_FOREVER for a buffer to become available), so there's no point in
checking its return value for NULL. Also, the connection state check
is because of this particular waiting and not the semaphore waiting
(which is done with K_NO_WAIT).

Change-Id: I9698760541de810869cffc1c60cf97c5f8f7df8d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 27bad8743f Bluetooth: l2cap: Decouple segmentation size
L2CAP Tx segmentation used BT_L2CAP_RX_MTU value which is
the value used by fixed channel protocols. Decoupling the
buffer size provides the opportunity to reduce RAM used per
connection.

Change-id: Id064f9b2e3f02073402815d09c3ea13a35df2a6c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Vinayak Chettimada 3807a9529d Bluetooth: l2cap: Dont use BT namespace in internal MPS/MTU macro
Remove BT_ prefix from BT_L2CAP_MAX_LE_MPS and
BT_L2CAP_MAX_LE_MTU as they are internal to l2cap.c file.

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

Change-Id: I1448b159ab1afe50ff88b7a6bd1b254c44858d4c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-29 11:39:13 -04:00
Johan Hedberg d1bb961bcf Bluetooth: Remove unnecessary bt_dev_esco struct
This information should be part of the main BR/EDR context struct,
rather than there being a separate member in struct bt_dev. If/when
the needed ESCO information grows we can consider having a separate
struct, but even then it should be part of the main BR/EDR struct
instead of sitting directly in bt_dev.

Change-Id: I3edf120606ea6c6974f515bba90de2b25fc6fac6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04: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 61de8f892b spell: Kconfig help typos: /kernel /misc /subsys
Fix misspellings in Kconfig help text

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

Jira: ZEP-2051

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

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

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

Jira: ZEP-2051

Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 16:07:08 +00:00
Johan Hedberg 2ec180aef5 Bluetooth: ATT: Start response timer only after actual transmission
If there are many connections there may be some delay before an ATT
PDU really gets transmitted over the air. Use the TX callback to
start the response timer so that it doesn't expire too soon.

Change-Id: Ibdd5bc1029ae4034caf329bf03892ac2093a0c67
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 13:00:57 +00:00
Johan Hedberg d893d31c16 Bluetooth: Introduce flow control for outgoing ATT packets
In order to not overload the TX buffer pool and potentially run out of
them, enforce flow control for outgoing ATT packets so that the send
functions block until the PDU has actually been transmitted over the
air.

Change-Id: Ic065bb88aec8c2d0ac2def8ef62131a427f7051f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 13:00:40 +00:00
Johan Hedberg ea9a067a9a Bluetooth: ATT: Fix bogus CONTAINER_OF() usage
This CONTAINER_OF() worked by chance, but was actually wrong, since it
makes it look like bt_l2cap_le_chan is the parent container of bt_att.
Instead bt_l2cap_le_chan is simply a member of bt_att, i.e. we can
dereference it directly.

Change-Id: I7307517bae823e54b45db31f75462655ce6eb50d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 13:00:04 +00:00
Johan Hedberg e2eb446b7b Bluetooth: Introduce a timeout for synchronous HCI command sending
There is no command that should take more than a couple of seconds. If
it does there's something severely wrong with the system. Catch such
situations with a clear assert rather than silently blocking the
sending thread.

Change-Id: Ie981fddcc27059df3e4df586e86ceac2e348f509
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 14:23:15 +03:00
Johan Hedberg a20464727f Bluetooth: SMP: Track when last key distribution PDU has been sent
According to the SMP specification the pairing is only to be
considered complete once the last SMP PDU has been transmitted over
the air. Take advantage of the new TX callback to notify completion
only once the packet has really been transmitted.

Change-Id: Ic87e598cd0e040d99f38344b98e476f67e4d9762
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 12:59:56 +03:00
Johan Hedberg 4a57bf6e6c Bluetooth: ATT: Enforce flow for incoming requests & indications
It's not valid for a peer to send another request before getting the
response to a previous one, or to send another indication without
getting the confirmation to a previous one. Take advantage of the
recently introduced TX callback to track when it's ok to accept these
ATT PDUs again.

The HCI USB transport has a potential issue here since a race
condition can occur between the ACL data and HCI event endpoints,
leading to dropping data when in fact both peers were behaving
correctly. To avoid hitting this issue, disable the flow enforcement
by default on the qemu targets that commonly use a USB-based
controller on the host OS.

Change-Id: I2791aaec6f6c0f8fd78a9a809a25e3ce129106c7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 12:59:56 +03:00
Johan Hedberg 4be4c60ab6 Bluetooth: Add support for tracking transmitted packets
Protocols/profiles may want to know when exactly their PDU has been
transmitted over the air. To make this possible, introduce support for
a callback that will get called when the controller reports that a
packet has been transmitted (through the Number of Completed Packets
HCI event).

Change-Id: Ia3a19b93c5b2111f144bfabe5861187c41525f30
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 09:59:33 +00:00
Johan Hedberg ac9a2398d8 Bluetooth: hci_raw: Fix ECC support
When the ECC code was last time refactored hci_raw.c was forgotten
about. This fixes the issue so that ECC works again with hci_raw.

Change-Id: I1b1df66f1b2a311db611b9936ec074c88caf4143
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-20 11:29:08 +03:00
Luiz Augusto von Dentz fd09c4aacf Bluetooth: L2CAP: Reuse request buffer to respond
This reduces the pressure on TX pool which may constantly block in case
of heavy traffic causing the RX thread to block as well.

Change-Id: Icfdde32031715e882085b7fa371191f157954156
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Luiz Augusto von Dentz 661c033124 Bluetooth: L2CAP: Try to allocate segment from the original pool
This makes the code attempt to allocate from the original buffer pool
before relying on le_data_pool which shall only be used as last resort
as it is configure with minimal possible buffers (1 per connection).

Change-Id: I85b581627f5c3b1bf1ee7c5fa69099c5aca13d4a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada 392b5deacb Bluetooth: controller: Channel Selection Algorithm #2
Add Bluetooth 5.0 LE Channel Selection Algorithm #2 feature

Jira: ZEP-2033

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

Change-id: I9ae15d6d90fa7a3de186905d3c68088ee22d2911
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada a6f6adbd6b Bluetooth: Fix missing LE conn param req bit in set LE evt mask
With the introduction of event mask implementation in the
Controller, it is discovered that peer centrals
initiating LE connection parameter requests timed out as
the Host did not get/enable the HCI LE connection parameter
request event in the set LE event mask command.

Fix by adding the LE connection parameter request event bit
mask while creating set LE event mask command.

Jira: ZEP-2027

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

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

Change-id: I196ffea79e7e10b0253363949051fdf82be62cb4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Kumar Gala f52a0341ba Bluetooth: AT: Fix building with newlib
Since the type of int, uint32_t, etc change with newlib we get the
following error:

subsys/bluetooth/host/at.c: In function ‘cme_handle’:
subsys/bluetooth/host/at.c:272:25: error: passing argument 2 of ‘at_get_number’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (!at_get_number(at, &val) && val <= CME_ERROR_NETWORK_NOT_ALLOWED) {
                         ^
subsys/bluetooth/host/at.c:46:5: note: expected ‘uint32_t * {aka long unsigned int *}’ but argument is of type ‘int *’
 int at_get_number(struct at_client *at, uint32_t *val)
     ^~~~~~~~~~~~~

We we can easily address by making val a uint32_t.

Change-Id: Ie6988368bd862afd4075baede7cb0a66c1628c18
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 08:58:09 +03:00
Kumar Gala 819d3ae9c9 Bluetooth: AT: use explicit unsigned char to avoid array subscript error
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Being explicit about the char being unsigned char deals with this.

Change-Id: I348189e1df11a1fcc58e5810b010b602fd2df33e
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-20 08:58:09 +03:00
Carles Cufi 8f9776073f Bluetooth: HCI: Naming consistency tweaks
For consistency, "chan" and "param" are used wherever "channel" and
"parameters" are the words in the specification.

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

Change-Id: I3efff6f5fa26f87d1e658d6336fef01ce45f5bb0
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 18:44:06 +00:00
Luiz Augusto von Dentz d8008533a9 Bluetooth: GATT: Fix wrong check for empty database
This fixes regression introduced by
87f2f7afec.

Change-Id: I4a1177ad42c7bb20fe66f8927cd00a30236152af
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-10 17:45:46 +00:00
Johan Hedberg be7c9fabae Bluetooth: AVDTP: Remove unused define
This is not used anywhere.

Change-Id: I943a3f28f1bdd619360215633dc66368e4b193a4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 17:05:51 +03:00
Johan Hedberg 17efbba7b4 Bluetooth: conn: Set initial responder address when connecting
If the connection process fails the user may still need to do
bt_conn_get_info() in its connected callback, so this needs to give a
meaningful value for the remote address. Start off with the one that
was given to bt_conn_create_le().

Jira: ZEP-2005

Change-Id: I4e9a033dec7c55fa549f5b6746c3bd81c0ccade5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 09:09:26 +00:00
Luiz Augusto von Dentz 87f2f7afec Bluetooth: GATT: Use sys_slist_t to represent the database
This replaces custom made list manipulation with sys_slist_t which makes
the code more readable.

Change-Id: I9ee024ad83da3e28f2ecab74b001bf0e795fe489
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-10 09:08:52 +00:00
Vinayak Chettimada 7a10c35f6b Bluetooth: controller: Use defined keyword in #if cond compiles
Use #if defined(...) constructs while using conditional
compilations of advanced event preparation and advanced
scheduling implementations.

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

Change-id: I3df07e667029c7d2571270db442ecb7241a417c2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-10 09:08:34 +00:00
Johan Hedberg 71d0843c7d Bluetooth: conn: Pass disconnect error properly to the conn struct
The bt_conn_set_state() function will not notify the connected
callback of the connection error if conn->err isn't properly set.

Jira: ZEP-2005

Change-Id: Idc30e736f4d8ba00156bf5c0e37dcccdb151742f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-10 08:20:53 +00:00
Carles Cufi 923c470f5d Bluetooth: controller: Fix warning with no dup filter
Conditionally declare the iterator variable to avoid a warning when
compiling the controller without any duplicate filter entries.

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

Change-id: Ib54209cdf381ba53217eb425696c24d797fe0a30
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg d2ac4a263a Bluetooth: hci_ecc: Fix ECDH API usage
The main issue is that after the latest update to TinyCrypt the
ecc_make_key() API expects a twice as big random number. Fix this, but
also move the variables to the static context since we're limiting one
HCI command at a time. Also place the variables in a union based on
their temporal dependencies. Thanks to this, we can now further reduce
the ECC stack size by 40 bytes (on ARM this then reports 12 bytes of
unused stack after key-pair generation and DHKey calculation).

Change-Id: I1036e0ca15f7c08063cba9e568d7df99e65c9156
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Carles Cufi 9a9699ebdb Bluetooth: controller: Implement event masks
HCI event masking allows the host to choose which events are reported to
it to avoid interruption and excessive traffic. This patch implements
masking to drop any non-enabled events as specified by the host.

Jira: ZEP-1769

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

Jira: ZEP-1246

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

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

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

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

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

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

Change-id: I053ad75a4328c51cfe651b820a2fa961e42ae48f
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada cced2aea30 Bluetooth: Permit connectionless host-controller combined build
In a host plus controller combined build, if no connection
is required, deselect CONFIG_BLUETOOTH_MAX_CONN. This will
reduce RAM and ROM usage in the controller.

Also, make BLUETOOTH_PERIPHERAL, BLUETOOTH_CENTRAL and
BLUETOOTH_CONN switches accessible by the controller kconfig
to select the right roles to enable.

Change-id: I164cf696ab2a6f4859086d2cb18f6d3f2b1399d3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 981f2d3fdb Bluetooth: Compile BR/EDR independent of BLUETOOTH_CONN check
BR/EDR sources that was compiled under BLUETOOTH_CONN
if-clause is moved out as independent conditional
compilation based on selected BR/EDR feature support.

Change-id: Iedfafc6056132654a9150ed235b245f8be62b4b1
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg 563fdd784b Bluetooth: SMP: Remove redundant ';'
Change-Id: I889b1768c40b630e00c9856630001dbf7557abba
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 9d7552f8f6 Bluetooth: AT: Fix - chance of missing UNSOLICITED state
If during hfp_hf_send response callback is not filled with NULL
and you receive unsolicited callback. which will not be taken care.
This patch fixes this issue.

Change-Id: I04007059d62273b9cdddf29e2d4a9086b07a01e5
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 9319e441b8 Bluetooth: HFP HF: Support to send hf AT command
A initiation to send AT commands is given in the application
with prefered AT command as the argument.
This patch supports to send the command within the profile stack.

Change-Id: Id5caa3ce64070fc17e60f4ea61a8c83a961099ba
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Luiz Augusto von Dentz a91238aca6 Bluetooth: L2CAP: Fix accounting SDU header len as data
This cause packets that are up to 2 bytes off segment maximum length
to be considered transmitted when in fact that could be some bytes left
to be transmitted which cause any subsequent packet to trigger invalid
SDU on the remote end:

[ 3612.376068] l2cap_le_data_rcv:6757: SDU fragment. chan->sdu->len 66 skb->len 68 chan->sdu_len 67
[ 3612.376073] Bluetooth: Too much LE L2CAP data received

Change-Id: Id2f3469ce1c0b27bb87c4d5bc18e6ede9d93dbde
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 5f69bde72b Bluetooth: Kconfig: Move BLUETOOTH_MAX_SCO_CONN to BR/EDR
Move the Kconfig option BLUETOOTH_MAX_SCO_CONN to BR/EDR if
clause.

Change-id: Iead2bc5a70a9499125f9edf22e85ade4dda8f5ac
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 2d6b82d44d Bluetooth: Kconfig: Group HCI_RAW related options
Move the BLUETOOTH_UART_TO_HOST_DEV_NAME options to after
BLUETOOTH_HCI_RAW option to group it together in the
Kconfig while using menuconfig.

Change-id: I21da080a5ffa30a08b1a1aa148ce8116e63a3c18
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 74cddf9393 Bluetooth: Kconfig: Group stack size related options
Group the stack size related options together to represent a
better order when using menuconfig.

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

Change-id: Iead760c22a0fbbda11e4558c4943b3366ecc8769
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Luiz Augusto von Dentz 57a99f6b7a Bluetooth: GATT: Be consistent with error in case SMP is disabled
This makes the code consistent with respect of errors, so instead of
checking directly on bt_gatt_write_without_response let this up to
bt_smp_sign.

Change-Id: Iea8d0bd2020df427b7542e2878ce8d9fd8b94170
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-08 20:11:54 +03:00
Johan Hedberg 757fd755a6 Bluetooth: Remove unnecessary controller-side buffers tracking
When there's no support for connections there's also no need to track
the controller side buffers.

Change-Id: I7eac3af486f139f1ab32efda8ccfa188ed8359eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Luiz Augusto von Dentz 3136aa2ced Bluetooth: GATT: Fix using write command when signing was requested
Checking both if signing has been requested _and_ conn->encrypt can
bypass signing leading to the caller to assume that a proper signature
was send in when fact it was not.

To fix now the code explicitly checks if SMP is enabled and in case it
is and signing was requested fails.

Change-Id: Ie17df4a4c2191f2da0172c687db7999395839a97
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-04-08 20:11:54 +03:00
Johan Hedberg dd1ba28726 Bluetooth: Controller: Introduce rate-limiting on stack analysis
In case the controller is receiving PDUs very rapidly, prevent it from
spamming the logs by limiting its stack analysis to at most once every
5 seconds.

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

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

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

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

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

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

Change-id: I16e4e6c3ca99f93987ab86924af0cb9d76bdbc7e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg 9028e8e75b Bluetooth: ECC: Fix command status emission from wrong thread
HCI drivers are obliged to send HCI Command Status/Complete events
from a separate context than all other data, however the ECC wrapper
was violating this rule (sending everything from the same ECC thread).
This could lead to a deadlock if e.g. the ECC API user decides to
generate a DHKey from the same callback that it got notified of local
key-pair generation.

The obvious solution is to emit the Command Status directly from the
send function, before passing the command to be processed by the ECC
therad (through a k_fifo). However, this is not quite so simple since
bt_buf_get_cmd_complete() reuses the original command buffer, meaning
we'd loose the original parameters after sending a Command Status.

To work around this limitation with bt_buf_get_cmd_complete() we stop
passing the command buffer to the thread and instead store the
parameters in static variables and do the thread communication using
flags and a semaphore. One side effect is that only one command can be
pending at a time, however that works out fine for all of the users of
ECC.

A nice side effect of moving some things to static variables is that
we end up reducing call stack usage in the ECC thread, allowing it to
be shrunk by 180 bytes (verified to be sufficient for both ARM and
x86 boards).

Change-Id: Ic41f0316d3fe4d14b64fd3d0a549b221d168411a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 646726518f Bluetooth: controller: Kconfig for advanced event preparation
Added Kconfig option to enable advanced event preparation
feature.

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

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

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

Change-id: I19e640f7395ac7938873ef4bfac38acf8d6f7e0e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-04-08 20:11:54 +03:00
Johan Hedberg 46e649c536 Bluetooth: monitor: Add support for logging packet drops
The monitor protocol provides support for logging packet drops with
the help of the extended monitor header. Implement support for this.

Change-Id: I7ef7894816cb8d1bd876842d0253ef0980471e69
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 1f5a809178 Bluetooth: HFP HF: Add support for RING indication cb
This patch adds support for incoming RING indication callback to
notify application.

> ACL Data RX: Handle 256 flags 0x02 dlen 16   [hci0] 167174.600312
      Channel: 65 len 12 [PSM 3 mode 0] {chan 1}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 8
         FCS: 0x9a
        0d 0a 52 49 4e 47 0d 0a 9a                       ..RING...

Change-Id: I0469590a77d619f2a842df647d84f4d56dbd4883
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Johan Hedberg 19d740c162 Bluetooth: monitor: Drop data instead of holding IRQ lock for long
The IRQ lock should never be held for long periods of time. Instead of
using the IRQ lock to prevent monitor protocol corruption simply drop
the data. Follow-up patches will add additional drop count tracking so
that these get reported properly over the protocol.

Change-Id: If498125b29f1b58bed676c78ad2062e2aa206318
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-08 20:11:54 +03:00
Sathish Narasimman 86d64b4f92 Bluetooth: HFP HF: Lookup table for unsolicited commands
Using lookup table to search for unsolicted command and its
handler function.

Change-Id: Id677dad3918d7187e0065ada2985ec12a97f8ed9
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-04-08 20:11:54 +03:00
Vinayak Chettimada 611460b913 Bluetooth: controller: Fix race waiting for ticker job to complt
Same volatile status variable as return and being updated
in ISR would modify the variable in two context which
caused the variable to be set to a stale value.

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

Jira: ZEP-1941

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

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

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

Change-id: Ia356419462d1fb4e38f4a20c720974143f12fdb6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-24 17:06:43 +00:00
Luiz Augusto von Dentz 9f76ce6f88 Bluetooth: L2CAP: Use sys_slist_t for fixed channels
Change-Id: I1a244c3f7d7a9b48844179515e19e71814f2b782
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-23 17:47:43 +02:00
Luiz Augusto von Dentz 194c4b9af6 Bluetooth: L2CAP: Use sys_slist_t for server channels
Change-Id: I1de0ed8fe82426d9a2049ab5f8c476863f3ea591
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-23 17:42:14 +02:00
Luiz Augusto von Dentz 41a55893f7 Bluetooth: L2CAP: Use sys_slist_t for connection channels
This avoid having duplicated code for list manipulation in both LE and
BR channels.

Change-Id: I734635e8e51d4b826a3d45cda8551e1e509bd913
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-23 14:52:52 +02:00
Mariusz Skamra aa435c951f Bluetooth: L2CAP: Fix TX queueing for LE CoC
This fixes an issue found on automated testing. If IUT had no credits
to send data, the TX request was not queued, because -EAGAIN error was
not returned to bt_l2cap_chan_send (which was responsible for queueing).

Scenario:
1. IUT was out of credits
2. Tester requested to send some data
3. Credits was given
4. No data was sent

Fixes: ZEP-1896

Change-Id: Ie9d0945d1e6b628cd978ede8105b37b838a61f1a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2017-03-21 17:05:43 -07:00
Vinayak Chettimada 0efd38885a Bluetooth: controller: Cleanup makefiles
Cleanup controller's root makefile and add folder level
makefile to have better control over dependencies.

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

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

Change-id: Idf9d7cdf7c60d74816ef2b093c4ae457df16e9a9
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:43 -07:00
Johan Hedberg bb975d3af6 Bluetooth: ATT: Refactor PDU handling
Mark each PDU type explicitly instead of using BT_ATT_OP_CMD_FLAG for
this. For simple "error response or not" selection the command flag is
sufficient, but to prepare for support for enforcing both request and
indication flow control it's useful to easily look up the type of the
PDU.

Additionally, refactor the handler lookup to make the flow a bit more
streamlined.

Change-Id: I575848356934b6d636dcda8d10b7e7fde1095355
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:43 -07:00
Johan Hedberg 6a2d57d90e Bluetooth: ATT: Reorder handler struct for compactness
Move the uint8_t members together to save 4 bytes for each struct.

Change-Id: I522be86397c57fd062018e409b65835912c6e7bc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada bd80affa3f Bluetooth: Support connection parameter update as central
bt_conn_le_param_update returns -EBUSY when used in central
role if peer did not support LE connection parameter
request.

This commit allows a central role to use either LE
connection parameter request, if local controller supports
it, else use LE connection update.

Jira: ZEP-1773

Change-id: I72b9c77440459672fd50216a74ffcbd59c5f38f6
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada f2f50d8bff Bluetooth: Fix checks for changes in connection parameters
Added checks for latency and timeout changes requested in
bt_conn_le_param_update, to decide if connection parameter
update is needed.

Change-id: I9de9f566158c5ade808ed356cb90b27186aa0243
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Johan Hedberg 7ce85104b8 Bluetooth: Use specific pointer type for conn->channels
There's no need to be opaque about this. Use the right type and let
the compiler catch errors for incorrect assignments.

Change-Id: If745354f514cbecfe6c0d845ebeaf3b93208b9b8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 24c7397160 Bluetooth: Controller: Increase default TX buffer count
Only 1 TX buffer is sub-optimal for performance since the controller
would always have to wait for the host TX thread to give it another
buffer. Increase the value to 2 so the controller can keep
transmitting data without waiting for the host.

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

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

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

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

Change-Id: I815f74549caffd5ac387b5bb84e5851aa96639b9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman f5383b07a2 Bluetooth: AT: Fix reset the state during error
1. Reset the state when error occurs
2. This patch avoids checking for the AT_STATE_UNSOLICITED_CMD state
as the loop exits with possix error. So check for at->state
AT_STATE_START is sufficient for loop termination.
3. Fix different sign warning.

Change-Id: I80a1ca582112f1783690ac8a4125036bb706705f
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman d33ea09968 Bluetooth: HFP HF: SCO Initiate Audio connection
This patch adds support to initiate audio connection from the stack.

< HCI Command: Setup Synchronous... (0x01|0x0028) plen 17  [hci0]
        Handle: 256
        Transmit bandwidth: 8000
        Receive bandwidth: 8000
        Max latency: 7
        Setting: 0x0060
          Input Coding: Linear
          Input Data Format: 2's complement
          Input Sample Size: 16-bit
          # of bits padding at MSB: 0
          Air Coding Format: CVSD
        Retransmission effort: Optimize for power consumption (0x01)
        Packet type: 0x003e
          HV2 may be used
          HV3 may be used
          EV3 may be used
          EV4 may be used
          EV5 may be used

Change-Id: I4f4c0788760c9bdaf75651825511ff6bcd06df59
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman dcf9a97b18 Bluetooth: HFP HF: SCO: Handle SCO Disconnect
This patch handles the SCO disconnection part also unref the connected
corresponding ACL conn.

Change-Id: Ic2de68560cfd7d847e6011578c4424e24800d2ac
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman e0363fd45b Bluetooth: SCO: Rename 'conn' to 'acl'
This patch renames the 'conn' variable to 'acl' which is reference
to ACL connection for SCO connection.

Change-Id: I5f0a60bc5d80de08fa5b963cf545c71552909401
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 495ff6730c Bluetooth: SDP: Server: Support ServiceSearchAttributeRequest
This change adds support for handling Service Search Attribute
Requests.

> ACL data: handle 256 flags 0x02 dlen 24
    L2CAP(d): cid 0x0040 len 20 [psm 1]
        SDP SSA Req: tid 0x0 len 0xf
          pat uuid-16 0x1002 (PubBrwsGrp)
          max 65535
          aid(s) 0x0000 - 0xffff
          cont 00
< ACL data: handle 256 flags 0x00 dlen 109
    L2CAP(d): cid 0x0040 len 105 [psm 1]
        SDP SSA Rsp: tid 0x0 len 0x64
          count 97
          record #0
              aid 0x0000 (SrvRecHndl)
                 uint 0x10000
              aid 0x0002 (SrvRecState)
                 uint 0x0
              aid 0x0006 (LangBaseAttrIDList)
                 < uint 0x656e uint 0x6a uint 0x100 >
              aid 0x0005 (BrwGrpList)
                 < uuid-16 0x1002 (PubBrwsGrp) >
              aid 0x0001 (SrvClassIDList)
                 < uuid-16 0x111f (Handsfree AG) uuid-16 0x1203 (Audio)
              aid 0x0004 (ProtocolDescList)
                 < < uuid-16 0x0100 (L2CAP) > <
                 uuid-16 0x0003 (RFCOMM) uint 0x3 > >
              aid 0x0100 (SrvName)
                 str "HFP AG Service"
              aid 0x0311 (SuppFeatures)
                 uint 0x0
          cont 00

Change-Id: Ib742b09b70271f79aa6462acce25f4c08a9e1a15
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada a91dd34830 Bluetooth: Make LE Encrypt helpers public
Expose LE Encrypt helpers to applications. If software-
based controller is compiled-in, then controller's AES
hardware will be used by the exposed helper interface.

Change-id: I2bac9dfa5ccb3dd50447079affb52d920ae5bd81
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>.
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 3994f4d5b7 Bluetooth: SDP: Server: Send ServiceAttributeResponse
Now that we have all the requested attributes of the service, form
the response packet and send it.

This also renames create_attrib_resp() to create_attrib_list() since
it is basically creating the list of attributes based on the filter.

> ACL Data RX: Handle 256 flags 0x02 dlen 21
      Channel: 64 len 17 [PSM 1 mode 0] {chan 0}
      SDP: Service Attribute Request (0x04) tid 28258 len 12
        Record handle: 0x10000
        Max attribute bytes: 4096
        Attribute list: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            Unsigned Integer (1) with 2 bytes [0 extra bits] len 3
              0x0004
        Continuation state: 0
< ACL Data TX: Handle 256 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 0}
      SDP: Service Attribute Response (0x05) tid 28258 len 23
        Attribute bytes: 20
          Attribute list: [len 17] {position 0}
            Attribute: Protocol Descriptor List (0x0004) [len 2]
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  L2CAP (0x0100)
              Sequence (6) with 5 bytes [8 extra bits] len 7
                UUID (3) with 2 bytes [0 extra bits] len 3
                  RFCOMM (0x0003)
                Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                  0x05
        Continuation state: 0

Change-Id: I54ba00f7700cbb72182dce745d61f5281f83437a
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Vinayak Chettimada 32f03a42c7 Bluetooth: controller: Move bt_rand into separate file
Move crypto related interface provided by the
software-based Controller bt_rand into separate file,
crypto.c.

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

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

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

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

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

Change-Id: Iac74f5ee9bee097bbb34c11bd13d1d886700f5cc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 61706ca021 Bluetooth: SDP: Server: Find the attributes in the record
Retrieves the record specified by the record handle, go over each
attribute in the record and check whether the attribute is there
in the list provided in the request.

Change-Id: I8f09e0fbb7811a20bb25dc0029cd7c79a9345c88
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Carles Cufi 841c5432cc Bluetooth: controller: Introduce BLUETOOTH_LL_SW
In preparation for future hardware implementations of the BLE
Link Layer, this patch introduces the BLUETOOTH_LL_SW
configuration option to specify that the default software
LL is to be built.

Change-Id: I8b9d5b5e0d2926d18f9e8c8f042a74326895bf95
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Sathish Narasimman befc6510f1 Bluetooth: HFP HF: SCO: Handle synchronous_conn_complete
Handle the synchronous connection complete event received from the
controller and update the event details received.

> HCI Event: Synchronous Connect Complete (0x2c) plen 17
        Status: Success (0x00)
        Handle: 266
        Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
        Link type: eSCO (0x02)
        Transmission interval: 0x06
        Retransmission window: 0x02
        RX packet length: 30
        TX packet length: 30
        Air mode: CVSD (0x02)

Change-Id: I4bcd0488f798b112af504245e80180a70b32a882
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 383bc7712d Bluetooth: SDP: Server: Handle ServiceAttributeRequest
Handles the ServiceAttributeRequest, populates the attributes to be
searched in the record specified by the record handle.

Change-Id: I3b702eaf05615f795d32aa30dbfaf91f5b2ce560
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-21 17:05:42 -07:00
Carles Cufi be060208e9 Bluetooth: controller: Rename downstream API calls
Rename all LL downstream API calls from radio_ to ll_ so that they
reflect the layer they are actually targeting. Additionally they have
been moved to ll.h so as to expose a proper interface.

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

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

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

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

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

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

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

Change-id: I04f8f11cbc3530f7b85ffa72f27373e213b6e35e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-21 17:05:42 -07:00
Kaustav Dey Biswas 4b534bc403 Bluetooth: SDP: Server: Send service search response
Now that we have all the records which has the uuids in the
service serach pattern, take the handle of each of those records,
prepare and send the service search response.

> ACL data: handle 256 flags 0x02 dlen 17
    L2CAP(d): cid 0x0040 len 13 [psm 1]
        SDP SS Req: tid 0x6b6f len 0x8
          pat uuid-16 0x0100 (L2CAP)
          max 256
          cont 00
< ACL data: handle 256 flags 0x00 dlen 26
    L2CAP(d): cid 0x0040 len 22 [psm 1]
        SDP SS Rsp: tid 0x6b6f len 0x11
          count 3
          handles 0x10000 0x10001 0x10002
          cont 00

Change-Id: I85ec8ee384d0bf8090265577ec3ef805e75d4766
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-21 17:05:42 -07:00
Sathish Narasimman e51a19fdc2 Bluetooth: HFP HF: SCO: Accept eSCO conn request
1. Accept the incoming Synchronous connection request and establish
a new sco connection object.
2. Enable sco conn complete in event_mask

> HCI Event: Connect Request (0x04) plen 10           [hci0] 126.198264
        Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
        Class: 0x7a020c
          Major class: Phone (cellular, cordless, payphone, modem)
          Minor class: Smart phone
          Networking (LAN, Ad hoc)
          Capturing (Scanner, Microphone)
          Object Transfer (v-Inbox, v-Folder)
          Audio (Speaker, Microphone, Headset)
          Telephony (Cordless telephony, Modem, Headset)
        Link type: eSCO (0x02)
< HCI Command: Accept Synchronous Co.. (0x01|0x0029) plen 21
        Address: 48:9D:24:1F:4D:1D (BlackBerry RTS)
        Transmit bandwidth: 8000
        Receive bandwidth: 8000
        Max latency: 7
        Setting: 0x0060
          Input Coding: Linear
          Input Data Format: 2's complement
          Input Sample Size: 16-bit
          # of bits padding at MSB: 0
          Air Coding Format: CVSD
        Retransmission effort: Optimize for power consumption (0x01)
        Packet type: 0x0006
          HV2 may be used
          HV3 may be used
> HCI Event: Command Status (0x0f) plen 4           [hci0] 126.205171
      Accept Synchronous Connection Request (0x01|0x0029) ncmd 1
        Status: Success (0x00)

Change-Id: I71597aef94e945a9c07be1960994ad20c1b44bb3
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:35:28 +00:00
Sathish Narasimman 5490c80383 Bluetooth: HFP HF: SCO: Add esco supported pkt type
From the response of read_local_supported_feaatures check if local
device supports eSCO packet type and update it to bt_dev.
Also added sco field in bt_dev

Change-Id: If85b3d24d327a6243318fad89a07375a8253f89b
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:35:06 +00:00