Commit graph

8508 commits

Author SHA1 Message Date
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
Sathish Narasimman
83bb08fbd9 Bluetooth: HFP HF: Handling AG Network error
This patch includes handling AG network error i.e +CME ERROR and
report the error number.

Change-Id: I19a3158e44568ad0ad21fb0dd790ac2f554c0625
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:34:31 +00:00
Sathish Narasimman
1d44e345be Bluetooth: AT: Fix 'signed' warning
Jira: ZEP-1857

Change-Id: Ie9647048544442a004f9b55e3ae889f472b08281
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-03-08 15:34:08 +00:00
Vinayak Chettimada
16608e9a51 Bluetooth: Controller: mayfly enable to supercede over disable
If mayfly enable is called before mayfly could be disabled,
then enable shall supercede disabling, the mayfly will
remain enabled. Any new mayfly enqueued by the caller that
tried to disable mayfly will be chain for deferred
executon under this condition.

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

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

Jira: ZEP-1839

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

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

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

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

Jira: ZEP-1852

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

Change-Id: I2c4f702117f99a42c9eef0133b46556a1c6d1496
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 14:51:54 +01:00
Luiz Augusto von Dentz
a9655eee4b Bluetooth: L2CAP: Add TX queueing for LE CoC
This allows to queue buffer to sent later in case it runs out of
credits so it no longer blocks the caller thread.

Jira: ZEP-1776

Change-Id: Ifa9b412f98889b50c0b889655d910520d11a4718
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 13:24:58 +02:00
Luiz Augusto von Dentz
03ff07ea7f Bluetooth: L2CAP: Move functions in preparation for queuing
This moves necessary functions that will be needed for queuing packets
while waiting for more credits.

Jira: ZEP-1776

Change-Id: I030c696d432ec5be1b8e6b649e953da145929777
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada
966fbbcd04 Bluetooth: Controller: Run all enqueued mayfly before disable
Controller asserted in preparation of a role event due to
the previous (same or another) role event preparation being
not complete.

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

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

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

Jira: ZEP-1839

Change-id: I3e0d31422db8e47b819189110b11ebd07dd09a7c
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg
0ed68c7680 Bluetooth: Relax minimum advertising interval for 5.0 controllers
The 100ms limit is only valid for controllers before version 5.0. For
a 5.0 controller the minimum is 20ms (0x00a0) which is already checked
for later in the valid_adv_param() function.

Change-Id: I0566a38ff855800d2e46e1d2c0a5c7bc9bc610cd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi
ff3e6e333f Bluetooth: controller: Report 5.0 compliant controller
Since there are no mandatory features in 5.0 when compared to a 4.2
compliant controller, report 5.0 as the current specification
implemented by the controller, to allow for features such as short
advertising intervals (< 100ms) which are already supported.

Change-Id: I1b138a86290a0422760a5e265cdd7b72d68f0048
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Johan Hedberg
f253f4e14c Bluetooth: Add support for Bluetooth 5.0 version specifier
Add support for detecting version 5.0, i.e. 0x09.

Change-Id: Ia2da513b65c420142fe97a4fa173bfa8045e9d75
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas
f7a4d112ae Bluetooth: SDP: Server: Filter records based on requested uuids
Filters the service records by going through all the records and
removes the one which does not have the uuid. So finally, only
the records which has all the uuids in the service search pattern
will be present in matching recs.

Change-Id: I1daa7c1b645efae2af66962999cc4c541891eff7
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz
480cdbd6d3 Bluetooth: GATT: Add bt_gatt_get_mtu API
bt_gatt_get_mtu can be useful when GATT is used to transport another
protocol on top.

Change-Id: I328ef49138ccc4ce642b0019d08060f6022d5aa7
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas
e3705b2f60 Bluetooth: SDP: Server: Handle Service Search request
Handles the service search request from peer, parses the service
search pattern (which is a data elem seq of uuids to be searched)
and populate the uuids.

This also populates the registered records which will be filtered
based on the uuids in the pattern (which will be done in the subsequent
patch).

Change-Id: I9a232a7cfdd159325214ed13e98cc20be39a2e3b
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Jaganath Kanakkassery
85b2a7e056 Bluetooth: SDP: Server: Introduce private define for max services
This is mainly done to avoid VLAs for looking up the service to handle
service search requests so that we can make sure that RX stack size
is sufficient for the defined no of services.

Change-Id: Ia99072615d9094a35bd7605ed2901e8018c0ecb2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Arun Jagadish
d0c78ce6d4 Bluetooth: AVDTP: Rename of variables
Renaming the params in bt_avdtp_req.

Change-Id: Ibc84931d0fa1d3af0a017f25a9893e51fb06bd1b
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Arun Jagadish
7f27599aba Bluetooth: AVDTP: Fix discover param struct
Changed bt_avdtp_req variable from pointer to variable

Change-Id: Ie1270b7da4f6130e89259c6b5c999407d56b33d8
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz
a05cea3a22 Bluetooth: GATT: Use __ASSERT for invalid parameters
Instead of returning -EINVAL at runtime assert in case of invalid
parameters.

Change-Id: I40505f06a4c12445bfb1f1846ace1b592b6bc342
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas
c25df73c5a Bluetooth: SDP: Server: Refactor data element structure header
Separate out data element structure header into type and size fields

Change-Id: I869ee1ea82db1f6d669bb905055135b7d63f3fa2
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas
690d455b78 Bluetooth: SDP: Server: Set security level to NONE
Change-Id: I67e18ba3060d0cbe703be9cd0b31e72e2b18d429
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2017-03-07 12:21:29 +01:00
Kaustav Dey Biswas
6699f5a52f Bluetooth: SDP: Server: Fix MTU setting after l2cap connection
L2CAP TX and RX MTUs will be exchanged during configuration req/rsp.
It should not be modified after connection.

Change-Id: I1e291c9e093561f349bcdcbb75cd7ff22b4163a5
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi
3141dcf3b4 Bluetooth: controller: Introduce debug pins Kconfig option
A new Kconfig debug option now controls the usage of pin toggling to
debug the BLE controller.

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

Change-Id: Ia76d6298985b1d367b7ad193d8261f5403446371
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Piyush Itankar
edb32b74d1 Bluetooth: A2DP: Stream End Point Registration
Added an API to allow addition of stream end points by the application.

Change-Id: I91b95fc5dc3b9b2950e8d55b5846e460e55f2453
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-03-07 12:21:29 +01:00
Vinayak Chettimada
c78601481d Bluetooth: Controller: Fix LE Ping PDU dispatch
It was observed that due to possible CRC errors, one
connection interval was not sufficient by the peer to
respond to LE Ping PDU which caused the Controller to
generate the Authenticated Payload Timeout event to host.

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

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

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

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

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

Jira: ZEP-1038

Change-id: Id3d09df7bdbdfea090f21f6f58aaded8c5f1e10d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Arun Jagadish
4efe5eb5b1 Bluetooth: AVDTP: Add AVDTP Receive Function
Added AVDTP Receive function, to recieve L2CAP Data.
Handlers added to parse AVDTP Signal ID

Change-Id: Iedfc4b6883d6cf27615d90a0d37ed10869e47ff3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-03-07 12:21:29 +01:00
Carles Cufi
727987276e Bluetooth: controller: Use direct ISRs
The new hard real-time (direct) interrupt support in the kernel allows
ISRs to be run directly with no significant latency overhead.

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

Jira: ZEP-1038

Change-Id: Ief9dacbea4c4c2e8a1c77893a0d6175a91819ffb
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-03-07 12:21:29 +01:00
Szymon Janc
767cd577dc Bluetooth: GATT: Fix subscriptions removal
This fix not removing subscription if it was first element on the list.
In that case prev was NULL resulting in passing garbage node to
sys_slist_remove.

Change-Id: I9452af08409692f9a331afd514fbac8cc727d289
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc
8637c23e41 Bluetooth: GATT: Remove not needed variable
prev is not used.

Change-Id: I735be33a3a763fcdee316fdf6cacfaa26e216210
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc
da9f9cc3f7 Bluetooth: Fix connection object leak
When canceling outgoing connection initial reference was not dropped.

btshell> connect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_set_state: (0x0011a1ac) disconnected -> connect-scan
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 3
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
Connection pending
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
btshell>
btshell> disconnect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 3
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_set_state: (0x0011a1ac) connect-scan -> disconnected
[bt] [DBG] bt_conn_prepare_events: (0x0011b3a0)
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
btshell>
btshell> connect 11:22:33:44:55:66 public
[bt] [DBG] bt_conn_ref: (0x0011a1ac) handle 0 ref 2
[bt] [DBG] bt_conn_unref: (0x0011a1ac) handle 0 ref 1
Connection failed
btshell>

Change-Id: I0c38bbed8d1712d07a579275355e7dcd8d6b0b38
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Szymon Janc
48b9c97b8f Bluetooth: SMP: Fix passkey entry for legacy pairing
This fix legacy pairing with passkey entry model when passkey
is fisr entered on local side. Replying with error in that case
is bogus as we should just wait for remote confirm.

Change-Id: I75480802928fd29d21617aa9250f90df647eb9a2
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-03-07 12:21:29 +01:00
Luiz Augusto von Dentz
b4b395845a Bluetooth: GATT: Fix compilation error
List container changes apparently were merged in the wrong order causing
leaving it with a compilation error.

Change-Id: Ib9d9502ddb39330c262e495a33592d0340713d83
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 20:54:34 +02:00
Anas Nashif
8c7aa9aa85 Merge "Merge bluetooth branch into master" 2017-02-10 16:37:56 +00:00
Luiz Augusto von Dentz
a8ed185615 Bluetooth: Convert FOR_EACH macro instances to use CONTAINER
Change-Id: I02c31842db5df10dda3e15bff370d2e459cc909d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 16:16:15 +00:00
Arun Jagadish
40f91b7105 Bluetooth: AVDTP: Moving structures to headerfile
Moving AVDTP structure - bt_avdtp_req,to header file.

Change-Id: I6e3bbc9e5b45ae7009cc5d94ae50a08b0490f4fa
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-10 10:37:05 +00:00
Johan Hedberg
6c995a5053 Bluetooth: Fix missing connection cleanup in some scenarios
If the TX thread is not in k_poll() when conn->state gets set to
DISCONNECTED and a dummy buffer is pushed to conn->tx_queue the
bt_conn_prepare_events() function would have failed to add the
connection to the poll list for cleanup. To ensure the cleanup always
happens introduce a new flag that indicates that a cleanup must
happen. The extra benefit of the flag is that we no-longer need a
dummy buffer, but can simply use the conn_change signal to wake up the
TX thread.

Change-Id: I369584d305261ab3666b931c786daff9d131d228
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-10 10:09:10 +02:00
Szymon Janc
fb3317b7a1 Bluetooth: Fix not clearing signaled flag for conn_change signal
From k_poll_signal_init() documentation:
The poll signal contains a 'signaled' field that, when set by
k_poll_signal(), stays set until the user sets it back to 0. It thus
has to be reset by the user before being passed again to k_poll() or
k_poll() will consider it being signaled, and will return immediately.

Change-Id: I55daac92dd6293ac653fd7fa0f907b0b7fd99d65
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-10 06:18:05 +00:00
Luiz Augusto von Dentz
92e8d91332 Bluetooth: GATT: Fix not updating previous node
When iterating to the subscriptions to be removed the code has to keep
a reference to the previous node but it case the subscription matches but
doesn't need to be removed it doesn't update the prev node which may
corrupt the list in case the next node end up being removed.

Change-Id: Ic5448f01bf78d293f93b9a7078a0147385ea1d23
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-10 08:16:41 +02:00
Arun Jagadish
93e28c75fe Bluetooth: AVDTP: Add AVDTP Discover Function Definition
Implementation of Send AVDTP_DISCOVER functionality

< ACL Data TX: Handle 256 flags 0x00 dlen 6
      Channel: 64 len 2 [PSM 25 mode 0] {chan 0}
      AVDTP: Discover (0x01) Command (0x00) type 0x00 label 0 nosp 0

Change-Id: Ieb6d1e5379d8933d57f3b1399f091378ce3c0756
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-08 11:02:09 +00:00
Jonathan Gelie
048a15bcc8 Bluetooth: GATT: fixing unsubscription
If subcription was found within the subscription list,
we have check if remains identical subscription
from the next node.
Otherwise none unsubscription is realized.

Change-Id: I38132d7c80575801885b8057902f3d4666b08aea
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-08 11:00:06 +00:00
Johan Hedberg
ce2d74a58a Bluetooth: Fix incorrect checks for command buffer user data
If the buffer given to hci_cmd_done() is not from the command buffer
then using the cmd(buf) macro is not valid. Simply bail out from
hci_cmd_done() if this is an event that didn't have a matching command
buffer.

Change-Id: Id8357a23a307f4ef3a9214a4e1f7d853a18cb907
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-08 11:59:50 +02:00
Johan Hedberg
5b80603dbd Bluetooth: Controller: Use LL_ASSERT instead of BT_ASSERT
The controller code should not use BT_ASSERT directly.

Change-Id: If0b7d8e21d2ab4569a564bd03e36e4eb9204c595
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-07 12:29:58 +00:00
Szymon Janc
afab7e1c01 Bluetooth: L2CAP: Make l2cap_br_send_conn_rsp return void
This function cannot fail.

Change-Id: I6b3393e0cfe1c334536e26c2715d5aff44c6dfd8
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:46 +00:00
Szymon Janc
7ee83b6c62 Bluetooth: SDP: Make bt_sdp_create_pdu static
It is not used outside of sdp.c and has no declaration.

Change-Id: I420a6b98d1b46fedffa29d042267b9c606d04c46
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:35 +00:00
Szymon Janc
22ada7b063 Bluetooth: L2CAP: Remove dead code
l2cap_create_le_sig_pdu always returns valid pointer.

Change-Id: I1510dc9ae387b426d7280f213e9d22b9a6a8418a
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:24 +00:00
Szymon Janc
69a52d82c9 Bluetooth: Remove some dead code
bt_l2cap_create_pdu always returns valid pointer.

Change-Id: Id525d19c096407150a7370396ed557290fbc35c5
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:13 +00:00
Szymon Janc
295e8e575c Bluetooth: Use assert when getting net buf with K_FOREVER
net_buf_alloc called with K_FOREVER should always return valid pointer.
Returning NULL indicated kernel bug.

Change-Id: I6c317de2d98723d0c1a0618e91490a2128f69f06
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-02-07 12:29:01 +00:00
Sathish Narasimman
54eedffd58 Bluetooth: HFP HF: Remove unused variable 'buf'
'buf' variable of type struct net_buf was one of the arguments for
finish callback in response to each AT command sent. 'buf' variable
not used in that function. So removed 'buf' variables from the argument
list.

Change-Id: I7d6aa6082f524012ae13a04426915076130ddf69
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 18:19:31 +00:00
Jonathan Gelie
a42e4f694f Bluetooth: GATT: set subscribe value to zero for unsubscription
Subscribe value is set to zero before calling notify callback,
to distinguish a subscription failure from an unsubscription
on disconnection (when flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE is set).

Change-Id: Ia91220492d82041b2c385bf88a15180387e7a483
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:44:01 +00:00
Sathish Narasimman
ccecfaac6a Bluetooth: HFP HF: Disconnect rfcomm on SLC error
If found error during service level connection disconnect rfcomm.

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

Change-Id: I1bc2bbbb4bc86f58905e44a7eb267ca0871f2fdb
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:43:18 +00:00
Sathish Narasimman
8fe69090e5 Bluetooth: HFP HF: Indicate disconnect to application
Invoke disconnected application callback when rfcomm is disconnected.

Change-Id: Icdefa8ee0b8f061f7db75a73e7f7ed4044817c5a
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 13:01:07 +00:00
Luiz Augusto von Dentz
31016448b4 Bluetooth: GATT: Fix not removing subscriptions safely
The subscriptions callback may free or reuse the subscription so all
instances that where this could happen need to safely fetch the next
element which is why this changes switch to use sys_list_t as it has
SYS_SLIST_FOR_EACH_NODE_SAFE.

Change-Id: I37d51f27116ea0c057b560924a9416676477597b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-06 11:18:57 +00:00
Sathish Narasimman
7fe2a96fc2 Bluetooth: HFP HF: Enable extended AG Error Result Code
Send standard AT+CMEE command used to enable the use of result
code +CME ERROR.

< ACL Data TX: Handle 256 flags 0x00 dlen 18           [hci0] 23.101226
      Channel: 67 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x40
        41 54 2b 43 4d 45 45 3d 31 0d 40                 AT+CMEE=1.@
> ACL Data RX: Handle 256 flags 0x02 dlen 15           [hci0] 23.127140
      Channel: 64 len 11 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 6
         FCS: 0x86
         Credits: 1
        0d 0a 4f 4b 0d 0a 86                             ..OK...

Change-Id: I246c25252440c9c973e1f90156dab44c48f02c3a
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 10:32:24 +00:00
Sathish Narasimman
ece5865b2e Bluetooth: HFP HF: Service level connection completed
Once the service level connection is done call the connected
callback.

Change-Id: I7541e221d4c03c939682ec70f1d9c093f87ceb09
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-02-06 09:36:54 +00:00
Johan Hedberg
dc70415dc4 Bluetooth: Merge HCI command and connection TX threads
We can go further with taking advantage of k_poll and merge the
connection TX thread together with the HCI command thread, thereby
saving even more memory.

Change-Id: I1792056fd4621d62c7cd05929094033acca45c74
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
1fb0351f9a Bluetooth: Merge bt_conn TX threads into a single one with k_poll
Now that the k_poll API is available we can use it to have single
connection TX thread instead of multiple ones, which helps reduce the
per-connection memory overhead by a substantial amount.

Change-Id: Icb5d4da87cf0d660bba8da43186d1e76f41c825a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Arun Jagadish
aa16b02bb5 Bluetooth: AVDTP: Remove buffer pool
Removing the module specific buffer pool. If future, use common acl_tx_pool.

Change-Id: Ie1452f981ef43642715be395315845cc2d9bb285
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
192db7179c Bluetooth: conn: Use delayed work for LE connection timeout
Detaching the timeout from the tx_thread lets us prepare for merging
all TX threads into a single one with the help of k_poll(). There's no
need to define a new delayed work object since the existing connection
parameter update object and connection timeout will never need to run
in parallel. Additionally, but some CONFIG_BLUETOOTH_CENTRAL guards to
void pulling in unnecessary code when Central role is not enabled.

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

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

Change-Id: I1f614fb9f02ed1886ca84198fbc8c64abc29e44f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
743379c21f Bluetooth: Kconfig: Merge headroom reserve variables into a single one
A subsequent patch will start reusing HCI command buffers for
receiving the response, so the distinction of received vs sent data
headroom would just make the code unnecessarily complex. Instead, just
merge these two variable into a single one.

Change-Id: I31d846331939f1a2270df7ed0c75112825e16493
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
be139268b3 Bluetooth: Add convenience macros for common header sizes
The C pre-processor doesn't allow using sizeof() in comparisons such
as "#if FOO < sizeof(bar)". To make it possible to use such
comparisons where the sizes of headers are involved, introduce helper
macros for the headers instead of always having to hard-code magic
numbers into the code.

Change-Id: Iaf654cb4aaa49e83360901f5b01225ba4b952854
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
800ed72293 Bluetooth: Fix buffer leak when HCI driver send() fails
If the driver send() fails we need to free up bt_dev.sent_cmd.

Change-Id: I41b6293dfe09f1d94d7f85663ddbebed40cf6e90
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa
178482fdb1 Bluetooth: SDP: Add API to get SupportedFeature attribute
Adds API to allow user get SupportedFeatures attribute ID.

Jira: ZEP-1112

Change-Id: I91a1bf548d99c5c7cc75682aed19e89390350533
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa
a7e4eaafaa Bluetooth: SDP: Add API to get ProfileDescriptorList attribute
Adds API enabling retrieve remote profile version.

Jira: ZEP-1112

Change-Id: I9b1a9a15848d5c485ec3dd2b405a6d51ce9b020e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Arkadiusz Lichwa
15520c5ce9 Bluetooth: SDP: Get ProtocolDescriptorList attribute internals
Adds API to get available specific information included in protocols UUID
tree during parsing Protocol Descriptor List attribute. Usually it's to
be remote Server Channel/PSM number operating on applicable protocol.
There're a few helper functions added to be able parse and retrieve such
information from raw record data.

Jira: ZEP-1112

Change-Id: I736a780b95ba54821d36e6011b739f5ff37cd64f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
e5305f1ab5 Bluetooth: Fix using correct variable type for interrupt mask
The irq_lock() API returnes unsigned int.

Change-Id: I12d2e980dca621d44ac9776e2961f504cb747c94
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg
54e34f4431 Bluetooth: Fix checking for invalid public address
Both all-zeroes and all-ones addresses are invalid. Fix the check for
this so that we fall back to a static random identity address when
needed.

Change-Id: I17cf903e0f3ed321311d86d09bed19343c2c801a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Jaganath Kanakkassery
43a5810793 Bluetooth: RFCOMM: Use common tx pool for control packets
This will reduce memory consumption by 23 bytes per session.

Change-Id: I1831b59881eaefb68f93c30e298b8f97d63c7428
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-02-05 22:39:25 +02:00
Jaganath Kanakkassery
c5bb728d66 Bluetooth: RFCOMM: Fix session timer during acl disc
Session idle timer should not be started in dlc destroy if
session is already disconnected (which can happen in scenarios
like acl disconnection where in dlc is detached from session and
destroy will be called from tx thread) otherwise timer function will
get invoked for a disconnected session.

This patch moves starting of idle timer from dlc destroy to
the point dlc disconnect is recieved from remote since idle
timer is to handle only that scenario.

Change-Id: I94501515a182ff0e2348ba4e2df63100f2f52209
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-02-05 22:39:25 +02:00
Carles Cufi
2093c1ccf0 Bluetooth: hci_core: Use nRF5x FICR address
The nRF5x come preprogrammed from manufacturing with either a public or
random static BLE address in the FICR register. Use the random static
one when present instead of generating one during Bluetooth
initialization.

Change-id: Ic733cb926e0414e56d6f8be65b033692e914b72a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-02-05 22:39:25 +02:00
Johan Hedberg
f23acadffe Bluetooth: Fix trivial coding style issue
Change-Id: I8a50fb6fe46d7a7deb6538f6a23bf5e58db2d52d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Kumar Gala
edcb6ceb12 Bluetooth: hci_raw: Make bt_buf_get_rx args consistent
The hci_raw version of bt_buf_get_rx was expecting an int for timeout.
Let us int32_t instead so we match both the hci_core version and the
type that net_buf_alloc expects.

This addresses a possible build issue if/when int32_t differs from our
default (ie, newlib).

Change-Id: I69374c48da8f2b96fa2bd418ff505fbaacda11f0
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-28 08:43:41 +02:00
Johan Hedberg
4153b6ca1f Bluetooth: Kconfig: Make device name variable generic
Change BREDR_NAME to DEVICE_NAME so it can also be used as the LE
device name.

Change-Id: I9ef55d9dff098372d47d9d5754ad7a7163a65bc0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-28 08:43:41 +02:00
Piyush Itankar
4a014f3e81 Bluetooth: A2DP: Stream End Point Structure
Added structure definition for stream end points
and the a2dp stream.

Change-Id: I6d0cc08611f5179397bea6200eb9244d7c1cc8d6
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-28 08:43:41 +02:00
Sathish Narasimman
730b4f89d2 Bluetooth: HFP HF: Handle +CIEV reponse
The +CIEV reponse received from the AG is handle and value is
updated to the application.

> ACL Data RX: Handle 256 flags 0x02 dlen 22         [hci0] 114.667753
      Channel: 64 len 18 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 14
         FCS: 0x9a
        0d 0a 2b 43 49 45 56 3a 20 32 2c 30 0d 0a 9a     ..+CIEV: 2,0...

Change-Id: I771cdb422d201293d356151fa33ec485083b2356
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-28 08:43:41 +02:00
Arun Jagadish
1806804ad8 Bluetooth: AVDTP: Add AVDTP Discover API Prototype
Added AVDTP Discover Request API Prototype.

Change-Id: I661331634b64099e352efe12cacc9af5d4c7ce16
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-28 08:43:41 +02:00
Luiz Augusto von Dentz
278bd910d5 Bluetooth: L2CAP: Only set state for dynamic channels
Fixed channels don't really use channels state as they don't need
connection setup.

Change-Id: Ie8b1327db0269a45e9ccb6049f8dda87aa445fb5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-28 08:43:41 +02:00
Piyush Itankar
42a175f300 Bluetooth: A2DP: Adds accept state callback handlers
Adds state callback handler to allocate memory to AVDTP on an incoming
connection. Also, abstracts searching of free session as a function call.

Change-Id: Idee6b7a0507b0b75c0007717e351ca12de0cb5be
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-28 08:43:41 +02:00
Jaganath Kanakkassery
91f9c9cf1c Bluetooth: RFCOMM: Implement MSC Flow Control
This is mainly for backward compatibility with 1.0b devices and for
spec compliance. CFC is mandatory post 1.0b spec where in MSC FC
shall not be used.

FC bit in MSC is used to manage the flow control. If FC is 1 then
the device is unable to accept frames.

Implementation is done by reusing "tx_credit" as a binary semaphore
wherein it will be blocked if MSC is recieved with FC bit 1 and
unblocked if FC bit is 0. Once tx thread is scheduled then semaphore
should be always available until all the buf in queue is sent.

Change-Id: I91181668ec0f46ff0b02905dd97e4503fc1fa7a7
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-28 08:43:41 +02:00
Jaganath Kanakkassery
17ea79e733 Bluetooth: RFCOMM: Fix v24_signal in MSC response
v24_signal in MSC response should be the copy of it received
in the command.

Change-Id: I9723ba182bf5911025c7a57220cd70687ca785f3
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-28 08:43:41 +02:00
Sathish Narasimman
d903b53e6b Bluetooth: AT: HFP HF: Handle unsolicited reponse
This implemnts the feature to handle the unsolicited response
received from the AG. In the hfp_hf.c file the unsolicited_cb function
process it.

Change-Id: I3ca6c8d4a1522d02f7160e2fe4ae1598cd93ce7e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-28 08:43:41 +02:00
Kumar Gala
8d4c1787bf Bluetooth: Controller: Use CMSIS NVIC APIs directly
Convert driver to use the CMSIS NVIC APIs rather than the internal
ones so we can remove them in the future.

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

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

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

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Johan Hedberg
1f35d47204 Bluetooth: Don't select TinyCrypt RNG for combined builds
For combined builds with Controller+Host the Controller's HW RNG is
used instead of TinyCrypts PRNG.

Change-Id: I4dbe85e547c057cf57ae0934b10866f2bb9f610d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 17:03:44 +00:00
Luiz Augusto von Dentz
bfc0c35387 Bluetooth: L2CAP: Fix always using RX_BUF_COUNT as initial credits
In case the channel provides its own MTU and allocator it should be
able to store as much data as set in the MTU, based on that the code
can give enough credits to fill the entire channel MTU.

Change-Id: I291cf1bb643f200bde191914e814f681f4f65c3e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-18 17:03:34 +00:00
Lee Jones
e74a91ce5a Bluetooth: Kconfig: Specify stack size for Bluetooth SPI
This value was found using trial and error.

Change-Id: I8dc3ea0759244bd28b97542f67a037f074d7b871
Signed-off-by: Lee Jones <lee.jones@linaro.org>
2017-01-18 12:24:52 +00:00
Arun Jagadish
d5b5af07be Bluetooth: AVDTP: Added params to AVDTP Request structure
Added pointer to store the callback function
from the application in the Request structure.

Added userdata param, to be used to fill AVDTP resp.

Change-Id: I8f3289545fdbbd91e4ed7f9983f4f4331d9b59a6
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-18 12:10:37 +00:00
Luiz Augusto von Dentz
514c9fa55f Bluetooth: L2CAP: Make sure state is correctly updated
This makes l2cap_chan_add updates the state to CONNECT so it doesn't
have to be done manually for both incoming and outgoing code paths.

Change-Id: I7331e49c675c83c6c1b184eeecc49c75c446a1ff
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-18 11:58:24 +00:00
Johan Hedberg
6cc35a751e Bluetooth: SMP: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I330769204914286bb98583dd89a3d849d4fcc128
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 11:57:23 +00:00
Johan Hedberg
eb085514e3 Bluetooth: L2CAP: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I77d2e53f7aa7f2832513f235a63ad2cf14e73cb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:33:12 +00:00
Johan Hedberg
fcc1fada58 Bluetooth: conn: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I78a3ccc6fcb84b431198f1a6c46aa6d50e9e9cd1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:23:36 +00:00
Johan Hedberg
f036dd9ae8 Bluetooth: hci_core: Take advantage of IS_ENABLED whenever possible
Try to use IS_ENABLED instead of #ifdefs whenever possible.

Change-Id: I4da93076a27a33b15a9b9119cfe5a1ff68acba0b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 10:21:08 +00:00
Johan Hedberg
645f867444 Bluetooth: Take advantage of IS_ENABLED macro for BT_DBG
The new IS_ENABLED macro allows exposing conditionally enabled code
always to the compiler, even though it may not ultimately end up being
built. This is in particular useful for letting the compiler catch any
logging format string errors. Introduce a new BT_DBG_ENABLED macro
that c-files need to define before including <bluetooth/log.h> in
order to choose whether BT_DBG() logs are enabled or not.

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

Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 08:28:06 +02:00
Johan Hedberg
1adc58fd79 Bluetooth: Introduce a new connection parameter request callback
Introduce a new callback to bt_conn_cb that allows the application to
decide whether the accept or reject an incoming connection parameter
request. If the request is accepted the callback allows the
application to also adjust the values to what it thinks are more
appropriate.

The Zephyr Bluetooth API allows multiple registered connection
callbacks, so in principle there may be multiple le_param_req()
callbacks. It's recommended for an app to just use one (for clarity),
but if there are multiple the app is responsible for managing
potentially different requirements. In the case of multiple callbacks
each callback will receive the modified parameters in case a previous
callback modified them.

Jira: ZEP-1474

Change-Id: I098db5791aac521f1edfa9fefdf847db0a27e3a5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
68732ef9d5 Bluetooth: L2CAP: Remove RECV_RESERVE from BT_L2CAP_RX_MTU
The BT_L2CAP_RX_MTU is counted starting with the BLUETOOTH_RX_BUF_LEN
variable, which doesn't include the BLUETOOTH_HCI_RECV_RESERVE
contribution (this would only be valid if we started subtracting from
BT_BUF_RX_SIZE).

Change-Id: I1ab3eaf8907946c56c2a9fe16b2074f3a3027a0f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
6f114e0a62 Bluetooth: Remove ACL details from BT_BUF_RX_SIZE
BT_BUF_RX_SIZE is used for the RX buffer pool which is used for both
ACL data and HCI events. It should therefore not contain any
ACL-specific details. This patch removes the ACL header size from the
macro and instead makes taking it into account the responsibility to
the Kconfig option. Since buffer sizes are anyway rounded up to the
nearest multiple of 4 the default goes up from 70 to 76.

Change-Id: I41274d9131e7529d41c16bd66de95637fb150a29
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Luiz Augusto von Dentz
27fb0aab10 Bluetooth: L2CAP: Fix using CONFIG_BLUETOOTH_RX_BUF_LEN as MTU
CONFIG_BLUETOOTH_RX_BUF_LEN shall not be used as RX MTU since it doesn't
account for ACL and L2CAP headers.

Change-Id: Ic3ebb4bd13d86a39174840f0ab625b66e863018a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-17 08:44:21 +02:00
Jaganath Kanakkassery
461591728f Bluetooth: RFCOMM: Implement Aggregate Flow Control
This is mainly for backward compatibility with 1.0b devices and for
ICS & spec compliance. CFC is mandatory post 1.0b spec where in
Aggregate FC shall not be used.

Aggregate FC is managed using FCOFF and FCON messages. This is for
the entire session which means that all the dlcs in that session
will be affected.

Implementation is done using binary semaphore wherein it will be
blocked when FCOFF is recieved and unblocked in FCON.
Once tx thread is scheduled then semaphore should be always available
until all the buf in queue is sent.

Change-Id: Ibfd2c4d033cef64c238ead83474f9e171572de1e
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-17 08:44:21 +02:00
Carles Cufi
93d7512215 bluetooth: hci_core: Fix conn params validity check
Bluetooth Core Specification v5.0, Vol 2, Part E, 7.8.12:

"The Supervision_Timeout parameter defines the link supervision timeout
for the connection. The Supervision_Timeout in milliseconds shall be larger
than (1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is
given in milliseconds."

Let's remember that:
conn_interval is given in units N * 1.25 ms
sup_timeout is given in units N * 10 ms

sup_timeout_ms > (1 + latency) * (conn_interval_ms * 2)
yields:
sup_timeout_n * 10 > (1 + latency) * (conn_interval_n * 1.25 * 2)
yields:
sup_timeout_n * 10 > (1 + latency) * (conn_interval_n * 2.5)
yields:
sup_timeout_n * 4 > (1 + latency) * (conn_interval_n)

Change-id: I30ac1d375a1baaa3e61f4c29b1165110599e1f7c
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-17 08:44:21 +02:00
Johan Hedberg
e564de0deb Bluetooth: Prefer struct bt_le_conn_param over individual values
This reduces stack pressure a little bit, and also paves the way for
introducing an application callback for accepting an incoming
connection parameter update request.

Change-Id: Ib02c14e27cbe34f85d663f36abd0597683ae1dc1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
a54292afc9 Bluetooth: GATT: Fix missing connection address comparison
When receiving notifications we should be properly matching against
the remote address of subscribed peers.

Change-Id: Ibcba1101aac418fd02f9068667f84e8294aade07
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
1dccc36428 Bluetooth: Remove unused bt_hci_driver_unregister() API
There are no users of this API and no (currently) envisioned use cases
for it. Remove it for now - it can always be brought back later if
there's a need for it.

Change-Id: I6530e096e3671c844a3f7dea8856147ffc716d71
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Sathish Narasimman
10bb3bbba5 Bluetooth: AT: Rename enum at_cmd_type elements
Rename the elements of 'enum at_cmd_type' in order to follow the
name spacing. Which should have prefix of 'AT_' for each elements.
This patch also involves the renaming, corresponding handler
function of 'enum at_cmd_type' with prefix 'at_' i.e 'cmd_start' as
'at_cmd_start'.

Change-Id: I722a25954163c06e131b94042c6a18e1e3458f6e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
815e15e3b2 Bluetooth: Controller: Rename hci_le_rand to bt_rand
Rename hci_le_rand to bt_rand and make its parameter types compatible.
This also includes updating rand_get() to use size_t instead of
uint32_t & uint8_t.

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

Change-Id: I7570d18f3e84dae3d5c2d3322b5d37cd3e8f3b6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
767c92e176 Bluetooth: Consolidate most outgoing ACL TX buffers into a single pool
Having TX buffers split into numerous pools has the downside of
increased memory consumption. This patch takes the initial step to
consolidate these pools into a single one, saving about 248 bytes of
RAM for a basic configuration.

Change-Id: I449ba18b44a9a6af68e9a2c44f19a9286eb88b14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Arkadiusz Lichwa
4880e717b1 Bluetooth: ATT: Fix redundant sys_slist call
Uses sys_slist_get function to get node and automatically, if valid,
remove one from the list.

Change-Id: I4cee6fbb064bf9644efdb7e6771e702b1f08678a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-17 08:44:21 +02:00
Arkadiusz Lichwa
53fde44046 Bluetooth: UUID: Fix format specifier in 128-UUID
Fixes not supported now format specifier.

Change-Id: Ia01ea3fd18acfeed6f4a3899334911dac1b76643
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg
696b89da0f Bluetooth: Fix potential race condition in bt_pub_key_gen()
It's possible for the Public Key to be available by the time that the
bt_hci_cmd_send_sync() returns, so we need to make sure the flags have
the right values no matter what.

Change-Id: I053093b6611af360f52b14ddca50d409388f9475
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 14:48:01 +02:00
Arun Jagadish
231050a966 Bluetooth: AVDTP:Add Accept Incoming connection cb
Added Accept Incoming connection callbacks for the A2DP layer

Change-Id: I8aee32a97916ed9fc9c4050151e7395e288c404c
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2017-01-05 11:33:24 +00:00
Jaganath Kanakkassery
c37b59b3bb Bluetooth: RFCOMM: Implement timer in session
As per the spec, the station which disconnects the last dlc
should disconnect session also. In case if remote does not
do it we need to disconnect otherwise rfcomm will be connected
without any dlc. So this starts an idle timer to handle the
above scenario.

This also starts a disconnect timer to handle in case remote
does not respond to session disconnect request.

Change-Id: I3b45aa5bf4c35fd81dc10974f2b0b6d4cfe4ea7d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 09:36:08 +00:00
Sathish Narasimman
b5891d1ddf Bluetooth: HFP HF: Rename cind_status_handle_values
Rename cind_status_handle_values to ag_inidcator_handle_values.
Because the same function will be reused internally for +CIEV
Callbacks.

Change-Id: I875064de17700d72ea89dbbe0f5cb6554c813a5e
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Sathish Narasimman
4b323cd72e Bluetooth: AT: Reset AT and CMD state
Reset AT and COMMAND state to process unsolicited response received
after processing result recieved for AT command sent to AG.

Change-Id: Id2a5827ce5b098336291696157027699479478cf
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Sathish Narasimman
166a8f762a Bluetooth: HFP HF: SLC Enable indicator status report
End of service level connection(call waiting or 3-way calling bit
and HF Indicators bit not set at present). AT+CMER is sent to
enable indicators status reporting in the AG side.

< ACL Data TX: Handle 256 flags 0x00 dlen 24                  [hci0] 102.898017
      Channel: 68 len 20 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 16
         FCS: 0x40
        41 54 2b 43 4d 45 52 3d 33 2c 30 2c 30 2c 31 0d  AT+CMER=3,0,0,1.
        40                                               @
> ACL Data RX: Handle 256 flags 0x02 dlen 15                  [hci0] 102.942198
      Channel: 64 len 11 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 6
         FCS: 0x86
         Credits: 1
        0d 0a 4f 4b 0d 0a 86                             ..OK...

Change-Id: I1630bf40f0f84e6e037b405854eb0c1c4ea691c4
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 12:35:21 +05:30
Szymon Janc
46a7989a5d Bluetooth: hci_ecc: Verify LE Generate DHKey command parameters
Reply with Invalid Parameters Command Status if incomplete command
was received.

 HCI Command: LE Generate DHKey (0x08|0x0026) plen 60
        invalid packet size
        f6 0f 79 a0 3c 4f 3e 90 40 66 6b 1d 93 64 af ed  ..y.<O>.@fk..d..
        03 ec b4 5f 29 cf 6d 26 42 02 61 b9 29 9a bf 0b  ..._).m&B.a.)...
        5e da 86 8b 3a ef aa e8 13 3d 87 de a7 dc 36 57  ^...:....=....6W
        25 89 56 43 e8 2a 73 56 62 60 fa 81              %.VC.*sVb`..
> HCI Event: Command Status (0x0f) plen 4
      LE Generate DHKey (0x08|0x0026) ncmd 1
        Status: Invalid HCI Command Parameters (0x12)

Change-Id: I9c4e798096023f0807e8d353ac3318e3d13dc6f7
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2017-01-05 08:49:17 +02:00
Piyush Itankar
4b5e19d21c Bluetooth: A2DP: Removes confirmation callback registration
Confirmation callbacks needed not be registered with AVDTP
during A2DP initialization

Change-Id: I2cdf8c5a283775e49fa6e7e9404024e26d05a767
Signed-off-by: Piyush Itankar <piyush.t.itankar@intel.com>
2017-01-05 08:49:17 +02:00
Jaganath Kanakkassery
665937a19f Bluetooth: RFCOMM: Implement timer in dlc
This basically implements timer for connection and disconnection.

Conn timer will be started when dlc is initialized and stopped
when it is connected. Authentication if any, will be also included
in this timer.

Disc timer will be started during disconnect initiation.

Change-Id: Ia4b74e478fefa42db21aef528e623a24c72ddf7f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:17 +02:00
Jaganath Kanakkassery
3b397076ab Bluetooth: RFCOMM: Rearrange fns to avoid forward declaration
Moves rfcomm_send_disc() and rfcomm_session_disconnect() to call it
while doing timer implementation.

Change-Id: I5805d31fb45181193385f055716c8518d68cc4a1
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:17 +02:00
Arkadiusz Lichwa
b11f30a246 Bluetooth: SDP: Update 'no records found' code comment
Adds more descriptive comment to the code responsible for handling no
resolved UUID case.

Jira: ZEP-1112

Change-Id: I1af07949e19246d51bab9df05504a90f5fb22bb2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:17 +02:00
Arkadiusz Lichwa
7ec0c37ec3 Bluetooth: SDP: Add UUID reference to user callback
User may want to know when getting called user UUID callback handler
on what UUID the result data was retrieved from server.

Jira: ZEP-1112

Change-Id: Iabb2dbdf0f3cfdb24244e052f094c7549164b199
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:17 +02:00
Vinayak Chettimada
2d064eef89 Bluetooth: Controller: revert to event callback inside radio ISR
In order that host can continue a connection event by
enqueuing packets, the number of completed packets event
needs to be generated as soon it arrives on air. Hence, the
Controller now calls the radio_event_callback on every radio
Rx complete ISR.

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

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

Change-id: I9d356bd297d0504cb16a032fb5fe5530693546e2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:17 +02:00
Luiz Augusto von Dentz
ae6d92a4ef Bluetooth: ATT: Fix using k_fifo API with net_buf
net_buf shall not be used with k_fifo since net_buf_unref will assume
unused bytes in the beginning are actually fragments causing it to
unref them as well.

Jira: ZEP-1489

Change-Id: I5ce420de73b245dc20eb15ea4d8d0b6ba346e513
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
d64f47d956 Bluetooth: Create separate bt_recv_prio() API
Since callers of bt_recv() have so far anyway been required to know in
which context to call it (based on e.g. bt_hci_evt_is_prio) it's
cleaner to have two separate APIs: bt_recv and bt_recv_prio.

Change-Id: Icd0d9aed9c51ffd2def31432c4ffcc16a9f13ccd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
1094f00253 Bluetooth: Reduce the minimum RX buf count to 2
The recent redesign of the H:4 HCI driver means that the smallest
safest RX buffer count goes down to 2. Default is left at 3 however to
get a bit better performance.

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

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

Change-Id: I927b20c1a0afaea8d000df28cc220a69ae817d59
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
533d544d95 Bluetooth: Remove unused prio pool and buffer helpers
These are no longer used by anything.

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

Change-Id: I130f2c44a2f28af1284290e6a0b17dcba438862f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
38eef90d01 Bluetooth: hci_ecc: Delay event buffer allocation
Allocate the event buffers after the ECDH operations rather than
before them. This way we don't hold on to the buffer for potentially
multiple seconds while the buffer could be used for other things.

Change-Id: I0fcc34ec4bea2265b7df3c1de3587c2a850c974e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
8f766efc2f Bluetooth: Use bt_buf_get_rx in hci_ecc.c
There's no need to use the type-specific helpers since those anyway
map to the same pool.

Change-Id: I74750f545c989bb921abca58166fe591ed325856
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
53b1503ac8 Bluetooth: Kconfig: Fine tune options for RECV_IS_RX_THREAD
Give more sensible values when RECV_IS_RX_THREAD is configured.

Change-Id: I40b5bd88213d224cc29f63fccef6cecee5868f77
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
0174200cd0 Bluetooth: Add bt_buf_get_rx() helper API
The separate ACL & event pools will soon be removed, and it's already
now convenient to have a generic API when the exact type of the
incoming packet is not yet known.

Change-Id: I84cb65d17ea69ebeaeb21532fbf76689e4fb59a0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:17 +02:00
Johan Hedberg
bc8564bddc Bluetooth: Remove support for host flow control
The controller doesn't support this feature and the only driver that
was needing it (h4.c) will be converted not to rely on it in the next
patch.

Change-Id: Ia514b79b6d05aa128768c2355353b7797e8b8977
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg
0a3a108762 Bluetooth: Introduce support for HCI driver-side RX thread
Add support for using the context bt_recv() is called in as the RX
thread, rather than having a separate host-side RX thread.

Change-Id: I256bfe5dece5272c816f2292e58747553189963d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg
ea0dcd7587 Bluetooth: Refactor bt_recv() logic
Refactor the bt_recv() logic to make it easier to insert #ifdefs to
remove the RX queue and thread when the context calling bt_recv()
itself is sufficient enough.

Change-Id: Ie8c5a4dfe9533a4464a2e4909c94d3e1b185b55b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg
57de98daf6 Bluetooth: Kconfig: Introduce BLUETOOTH_COMBINED_RX_BUF option
If the controller doesn't need ACL host flow control it may want to
optimize and use a single pool for incoming data.

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

Change-Id: I53e0ce5155eebc352b84ba41b30ecb9d9958699f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
5d3d13f4a4 Bluetooth: SDP: Send resolved UUID data to user
After getting whole UUID response for SSA PDU request the user can be
informed about discovery results. Result data feeding the user is
splitted to logical record chunks if more than one record was found.
Every such portion represent unparsed SDP record prestripped from record
length. Each response record data passed to user starts from first raw
attributes data and the record response buffer's length tells exactly
about each record length. User UUID callback handler's return result
can drive delivery (dis)continuation of every such portion to the user.

Jira: ZEP-1112

Change-Id: Icec518ca7bab3c8dfef4a966d98e9d9004894bcc
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery
51e71ea0fd Bluetooth: RFCOMM: Increase dlc stack size to 256
This analyzes the dlc stack using stack_analyze() which is coming
as 188 with BLUETOOTH_DEBUG_LOG off.

dlc stack (real size 320):     unused 68       usage 188 / 256 (73 %)

So increase the stack size to 256.

Change-Id: Ie5d5f267f4f618747551f0bfd0e05ffb47e0bb91
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
164aa00f0f Bluetooth: SDP: Check room needed against user allocated
When getting very first SSA PDU response for given UUID we can extract
from it the counter telling us how much data will be delivered by server
to collect all complete response for given UUID. Let's use that
information to check if the room allocated by app is big enough for
collecting resolved data.

Jira: ZEP-1112

Change-Id: I91515da668d89e05755d64e427dee0936bf20323
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman
7eacb0477c Bluetooth: HFP HF: SLC query indicators present value
Service level connection sending AT+CIND? and parse the response
to get the present value of the available indicators.
This patch also providing callback interface to application for
the indicators value received.

Also added doxygen comment for connected and disconnected callback.

< ACL Data TX: Handle 256 flags 0x00 dlen 17                   [hci0] 25.251358
      Channel: 67 len 13 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 9
         FCS: 0x40
        41 54 2b 43 49 4e 44 3f 0d 40                    AT+CIND?.@
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 25.262012
        Num handles: 1
        Handle: 256
        Count: 1
> ACL Data RX: Handle 256 flags 0x02 dlen 33                   [hci0] 25.293028
      Channel: 64 len 29 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 24
         FCS: 0x86
         Credits: 1
        0d 0a 2b 43 49 4e 44 3a 20 30 2c 30 2c 31 2c 33  ..+CIND: 0,0,1,3
        2c 30 2c 33 2c 30 0d 0a 86                       ,0,3,0...
> ACL Data RX: Handle 256 flags 0x02 dlen 14                   [hci0] 25.295006
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I7b2a89487e2d481391c51201e32b3287808f82dc
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman
7782ccbd76 Bluetooth: AT: Change API name skip_whitespace to skip_space
skip_whitespace() API name is changed to skip_space(). Where the
skip_space function is to skip only SPACE(ASCII Dec: 32).

Change-Id: Ib28ffa45295912505bc27a986803ed0ae2b0002c
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman
128ef4dd99 Bluetooth: HFP HF: SLC Connection send/parse CIND
Part of service level connection initilization. Sending AT+CIND=?
and parsing its response.

< ACL Data TX: Handle 256 flags 0x00 dlen 18                   [hci0] 20.888273
      Channel: 76 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x40
        41 54 2b 43 49 4e 44 3d 3f 0d 40                 AT+CIND=?.@
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 20.914998
        Num handles: 1
        Handle: 256
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5         [hci0] 20.916863
        Num handles: 1
        Handle: 256
        Count: 1
> ACL Data RX: Handle 256 flags 0x02 dlen 142                  [hci0] 20.945835
      Channel: 64 len 138 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 1024
         FCS: 0x86
         Credits: 1
        0d 0a 2b 43 49 4e 44 3a 20 28 22 63 61 6c 6c 22  ..+CIND: ("call"
        2c 28 30 2c 31 29 29 2c 28 22 63 61 6c 6c 73 65  ,(0,1)),("callse
        74 75 70 22 2c 28 30 2d 33 29 29 2c 28 22 73 65  tup",(0-3)),("se
        72 76 69 63 65 22 2c 28 30 2d 31 29 29 2c 28 22  rvice",(0-1)),("
        73 69 67 6e 61 6c 22 2c 28 30 2d 35 29 29 2c 28  signal",(0-5)),(
        22 72 6f 61 6d 22 2c 28 30 2c 31 29 29 2c 28 22  "roam",(0,1)),("
        62 61 74 74 63 68 67 22 2c 28 30 2d 35 29 29 2c  battchg",(0-5)),
        28 22 63 61 6c 6c 68 65 6c 64 22 2c 28 30 2d 32  ("callheld",(0-2
        29 29 0d 0a 86                                   ))...
> ACL Data RX: Handle 256 flags 0x02 dlen 14                   [hci0] 20.947764
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I33126a19641b889f1749b642cbc5e63984d85b6d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Sathish Narasimman
39e7350a13 Bluetooth: AT: Rename API's which uses term 'stream'
Rename the API's with 'list' which uses the term 'stream'.
For example 'at_open_stream' is renamed to 'at_open_list' and
the same applies for other API's which uses 'stream' in it.

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

Change-id: I93aa1da2145a33095c220c863ed1457bb27a7aec
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Johan Hedberg
34cff06a72 Bluetooth: hci_ecc: Fix incorrect private_key size
The private_key parameter to generate_keys is supposed to be 32 bytes
in size, i.e. an array of 8 uint32_t variables.

Change-Id: Ia891fd68bfd8662983b898084e5a8524b7a9b8e2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
c97220c1d6 Bluetooth: SDP: Allocate user delivered memory for resolved data
Adds driven by user params buffer location to be populated by UUID
resolved data. Corresponding handlers responsible for connected and
disconnected states of L2CAP transport channel used by SDP PSM traffic
automatically allocates and unrefs such memory. Data receiving handler
performs buffer fill up.

Jira: ZEP-1112

Change-Id: I8aa97e6e69344dca0f241a4e9097acac75e14a7c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
3304cbc41b Bluetooth: SDP: Validate SSA response PDU
Adds two extra checks against invalid length of attribute payload
frame.

Jira: ZEP-1112

Change-Id: I089442a5b9631471f9f394860681f1483e021c43
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
7c6063c4ec Bluetooth: SDP: Enable resolve all user delivered UUIDs
Iterates all UUID params list delivered by user. When iteration finish
release SDP client L2CAP transport channel.

Jira: ZEP-1112

Change-Id: I0602e32a5296a05719ad1385b4aff537350b3e7d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada
d5d473b0f8 Bluetooth: Controller: replace work with mayfly
This commit introduces a very light-weight and lock-less
scheduling of the Controller's deferred function calls
called the Mayfly.

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

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

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

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

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

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

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

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

Change-id: Idab40b1371488e06a6f2009fb553f7655b7b86f3
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
d333b3892b Bluetooth: SDP: Handle SSA PDU response
Adds initial handling of SDP Service Search Attribute response PDU.
Currently attributes data are not collected. Main focus was done on
proper handling PDU continuation state to be able receive whole
requested SDP record(s) if found for given UUID.

< ACL Data TX: Handle 74 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 1 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 1 len 59
        Attribute bytes: 48
        Continuation state: 8
        cd 91 5a 58 30 00 00 00                          ..ZX0...
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 2 len 23
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 8
        cd 91 5a 58 30 00 00 00                          ..ZX0...
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 2 len 59
        Attribute bytes: 48
        Continuation state: 8
        cd 91 5a 58 60 00 00 00                          ..ZX`...
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 32
      Channel: 64 len 28 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Request (0x06) tid 3 len 23
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 8
        cd 91 5a 58 60 00 00 00                          ..ZX`...
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 74
        Count: 1
> ACL Data RX: Handle 74 flags 0x02 dlen 19
      Channel: 64 len 15 [PSM 1 mode 0] {chan 3}
      SDP: Service Search Attribute Response (0x07) tid 3 len 10
        Attribute bytes: 7
        Continuation state: 0
        Combined attribute bytes: 103
          Attribute list: [len 99] {position 0}
            Attribute: Service Record Handle (0x0000) [len 2]
              0x00010001
            Attribute: Service Class ID List (0x0001) [len 2]
              UUID (3) with 2 bytes [0 extra bits] len 3
                OBEX Object Push (0x1105)
            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
                  0x09
              Sequence (6) with 3 bytes [8 extra bits] len 5
                UUID (3) with 2 bytes [0 extra bits] len 3
                  OBEX (0x0008)
            Attribute: Browse Group List (0x0005) [len 2]
              UUID (3) with 2 bytes [0 extra bits] len 3
                Public Browse Root (0x1002)
            Attribute: Bluetooth Profile Descriptor List (0x0009) [len 2]
              Sequence (6) with 6 bytes [8 extra bits] len 8
                UUID (3) with 2 bytes [0 extra bits] len 3
                  OBEX Object Push (0x1105)
                Unsigned Integer (1) with 2 bytes [0 extra bits] len 3
                  0x0100
            Attribute: Unknown (0x0100) [len 2]
              OBEX Object Push [len 16]
            Attribute: Unknown (0x0303) [len 2]
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x01
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x02
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x03
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x04
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x05
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0x06
              Unsigned Integer (1) with 1 byte [0 extra bits] len 2
                0xff

Jira: ZEP-1112

Change-Id: Ie282782fba6ef06c6826b3e624f83c8f4c94ebbe
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Carles Cufi
4b7cdd499f bluetooth: Tune stack sizes after measuring with hci_uart
The following readings were obtained after running the peripheral and
central_hr apps in qemu combined with the controller (hci_uart) on nRF51
and nRF52:

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

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

Change-id: Ice7ad7f081502e0ea1accf856a7937c0bf0783b2
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
ce61122cdf Bluetooth: SDP: Introduce ContinuationState of PDU
Adds initial handling of PDU Continuation State. It has crutial role
to interact with SDP server when receiving partial SDP PDU responses.

< ACL Data TX: Handle 77 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Request (0x06) tid 3 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
> ACL Data RX: Handle 77 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Response (0x07) tid 3 len 59
        Attribute bytes: 48
        Continuation state: 8
        8d 55 59 58 30 00 00 00                          .UYX0...

Jira: ZEP-1112

Change-Id: I53ea9ae64c3f2685c9a12be3683dfc3a95aa8bf9
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery
5f3ce62eed Bluetooth: Fix reserve param of bt_l2cap_create_pdu()
reserve parameter of bt_l2cap_create_pdu() is incorrectly passed
as timeout.

Change-Id: Ieed293f52c2e98f16f1e43c498140178703236db
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Carles Cufi
80f000ab43 Bluetooth: Rename SEND_STACK to TX_STACK_SIZE
For consistency with RX_STACK_SIZE and the rest of stack sizes, rename
to use the normal naming scheme.

Change-id: Ib8d484482466fa8d629e6329e07b927abdd6f598
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
714718a33d Bluetooth: SDP: Validate Transaction ID of PDU
Adds check on receiving side whether current SDP PDU response matches
correcponding SDP PDU request.

Jira: ZEP-1112

Change-Id: Ide8da54fe38f12d3bcb1e7d056050c038b7ec065
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada
b37e285c03 Bluetooth: Controller: Kconfig LE Ping feature
Add Kconfig configuration to conditionally enable LE Ping
feature in the Controller.
This will save CPU time, flash and RAM, if this feature is
not desired.

Change-id: I5fbbdbe8f45ac01c9b0d7b11e002a0d1db4d272e
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
7fc2a8a4e2 Bluetooth: SDP: Implement ServiceSearchAttribute request PDU
Initial implementation one of basic UUID resolving request PDU based on
Service Search Attribute PDU specification [Core 4.2 Vol 3 Part B 4.7.1]
The request applies approach to query using single only UUID pattern
and getting all attributes for given UUID. The initial PDU transaction
is requested on PSM SDP L2CAP channel connected state.

> ACL Data RX: Handle 77 flags 0x02 dlen 18
      L2CAP: Configure Response (0x05) ident 12 len 10
        Source CID: 64
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 64
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
< HCI Command: Host Number of Completed Packets (0x03|0x0035) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
< ACL Data TX: Handle 77 flags 0x00 dlen 24
      Channel: 64 len 20 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Request (0x06) tid 3 len 15
        Search pattern: [len 5]
          Sequence (6) with 3 bytes [8 extra bits] len 5
            UUID (3) with 2 bytes [0 extra bits] len 3
              OBEX Object Push (0x1105)
        Max record count: 65535
        Attribute list: [len 7]
          Sequence (6) with 5 bytes [8 extra bits] len 7
            Unsigned Integer (1) with 4 bytes [0 extra bits] len 5
              0x0000ffff
        Continuation state: 0
> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 77
        Count: 1
> ACL Data RX: Handle 77 flags 0x02 dlen 68
      Channel: 64 len 64 [PSM 1 mode 0] {chan 0}
      SDP: Service Search Attribute Response (0x07) tid 3 len 59
        Attribute bytes: 48
        Continuation state: 8
        8d 55 59 58 30 00 00 00                          .UYX0...

Jira: ZEP-1112

Change-Id: I0ed1d989a5abe030f1c70d4d1f104d488eafb2b3
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2017-01-05 08:49:16 +02:00
Louis Caron
9055f57850 Bluetooth: fix write cmd handling
The data pointer and length was not updated before invoking the
write_rsp function therefore providing pointer to the handle.

Change-Id: I5c27ab7a793979dffb8f1f2c68def027c45f2376
Signed-off-by: Louis Caron <louis.caron@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg
fce1938a24 Bluetooth: Fix another incorrect memcpy call
This should also have been net_buf_add_mem(). Otherwise the buffer
gets corrupted.

Change-Id: I4687584777f446d398182c3e8c2cde5946987da4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Vinayak Chettimada
1921b53484 Bluetooth: Controller: refactor ISR to reduce critical path code
Move code that can be executed after radio tx/rx packet ptr
has been assigned in the radio h/w.

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

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

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

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

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

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

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

Change-id: I4396c482e5546d78239cf41d88728de996e48d7d
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery
41984c7577 Bluetooth: RFCOMM: Handle non supported message types
If peer sends any non supported message then it has to be
responded with NSC (Non Supported Command) response.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Unknown CMD (0x33)
           Length: 8
        01 22 34 55 67 88 9a bb 70

< ACL Data TX: Handle 256 flags 0x00 dlen 11
      Channel: 64 len 7 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 3
         FCS: 0xaa
         MCC Message type: Non Supported Command RSP (0x04)
           Length: 1
           cr 1, mcc_cmd_type 33

Change-Id: I7be3b64a9cf437276c10868d52e0b9c555018df0
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery
fb07eb9022 Bluetooth: RFCOMM: Respond to Test command
Test command is to test the connection between two stations.
The pattern recieved should be sent back in the response.

> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x70
         MCC Message type: Test Command CMD (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

< ACL Data TX: Handle 256 flags 0x00 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0xaa
         MCC Message type: Test Command RSP (0x08)
           Length: 4
           Test Data: 0x 5f 54 65 73

Change-Id: I16beb4cf857cc8bbc049514dbf840d84e13c8fb5
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-01-05 08:49:16 +02:00
Johan Hedberg
14472d757d Bluetooth: Fix incorrect call to memcpy()
This call was supposed to be net_buf_add_mem().

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

Change-Id: If44cf9cd651aba5e544e36567869f147468663eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa
4de2bad817 Bluetooth: SDP: Check SDP error when receiving PDU response
Stops handle data if server responds with SDP Error PDU

Jira: ZEP-1112

Change-Id: Iaddb740f71fa86384753ab32956fc69b89faeea0
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
d460181eb0 Bluetooth: SDP: Start receiving response data on SDP PSM
Adds handler responsible for receiving SDP data on SDP client request.
For now simple validation are done on SDP response header data.

Jira: ZEP-1112

Change-Id: Ic6009030db34e26dfdbd57fa1b0a22f6e27b6a11
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Szymon Janc
fa8a27fc03 Bluetooth: L2CAP: Fix possible endless loop
cid is uint16_t and L2CAP_BR_CID_DYN_END is 0xffff so doing
"cid < L2CAP_BR_CID_DYN_END" comparisong is always true resulting
in for loop not being terminated as expected. Check against cid
overflow instead. Code comment is also added for clarity.

Change-Id: I15d6d838ed8b731824e602d089d765614c96c6c1
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
fe7d3392cd Bluetooth: SDP: Check params validness
Validates user driven bt_sdp_discover_params data.

Jira: ZEP-1112

Change-Id: I7d560f80df80708906d91e541385ddf804bfdeb6
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
b04f3a2b17 Bluetooth: SDP: Reset context on disconnection
Resets SDP client session data on related L2CAP transport channel
disconnection state. Leave the channel itself reset to L2CAP layer.

Jira: ZEP-1112

Change-Id: I4d8a8f10908f5e599ba6506470b98508869cb21b
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
6d89dd897e Bluetooth: SDP: Queue user UUID to be resolved
Makes possible to append user UUID to context to be able later iterate
it on subsequent resolving process.

Jira: ZEP-1112

Change-Id: I193ff1cee199045c9686dc4ca200adf19db377e4
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
4aca00220b Bluetooth: SDP: Refactor bt_sdp_discover API
Renames and refactors helper get_client_session to sdp_client_get_session
to follow existing naming convention and adds second helper creating
new SDP client session. Then simplifies using them the API implementation.

Jira: ZEP-1112

Change-Id: I6b919f521e6665a7117fa06208b3fa2ae5f77fda
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery
c7346c4c93 Bluetooth: RFCOMM: Respond to RPN command
Peer sends Remote Port Negotiation command to set port
communication settings. Currently we accept all the settings
sent by remote.

If there is only one value byte in the request then current
port settings has to be returned for which we returns the
default settings defined in ETSI.

Note that RPN may be sent even before a dlc is opened.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: Remote Port Negotiation Command CMD (0x24)
           Length: 8
           dlci 10
           br 3 db 2 sb 0 p 0 pt 0 xi 0 xo 0
           rtri 0 rtro 0 rtci 0 rtco 0 xon 17 xoff 19
           pm 0x3f7f

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0xaa
         MCC Message type: Remote Port Negotiation Command RSP (0x24)
           Length: 8
           dlci 10
           br 3 db 2 sb 0 p 0 pt 0 xi 0 xo 0
           rtri 0 rtro 0 rtci 0 rtco 0 xon 17 xoff 19
           pm 0x3f7f

Change-Id: I73b7d8577e7e2bc3e436f4db86a91e12db440f1f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery
61f34fd966 Bluetooth: RFCOMM: Pass session instead of dlc in make_uih_msg()
rfcomm_make_uih_msg() only needs session to get the role while creating
msg. This is mainly done since some commands like Test and RPN may come
even before dlc is created.

Change-Id: Ifd5a2ceaf17c20db3f00604cd2b4f1759155123e
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Szymon Janc
ba2adb70b2 Bluetooth: L2CAP: Fix use of uninitializer pointer
l2cap_br_conn_req_reply expects valid bt_l2cap_chan pointer but this
is achieved only on accept() callback. Use l2cap_br_send_conn_rsp
instead for rejecting cases where no channel was accepted. This also
makes success path being 'primary' function path ie erros all always
handled inside if() statements.

Jira: ZEP-1405

Change-Id: I890b4fcf029afce65eba4f2ebae0b1094feb007f
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2016-12-24 08:42:15 +02:00
Johan Hedberg
f3c632bf44 Bluetooth: Add timeout to event & ACL buffer allocation functions
Not all users are in an ISR context where we can't block, so give the
callers the freedom to choose if they want to block or not.

Jira: ZEP-1481

Change-Id: I19bd7e2df94c4eeb60886a17a78f872bd7bea887
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
3cbce90936 Bluetooth: SDP: Attempt reuse existing SDP client session
Adds validation check when 'sdp discovery' API is to be called
by client, to reuse existing connection if valid or initiate new one
if posssible to set SDP L2CAP link to remote.

Change-Id: I47ce33cb5e95cf2616f9b23712641b912ce40f37
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish
71fdc901e3 Bluetooth: AVDTP: Add AVDTP_Timer & Handler
Added AVDTP_TIMER = 6secs for tracking sent
Singalling Request.
Timeout handler function added.

Change-Id: I76ddcdcfba2b5e9317f66f9815e0d9d3f4cc87e7
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish
129a844d63 Bluetooth: AVDTP: Add AVDTP Pending Request
Added a Pending Request structure, this will keep
a track of the last sent AVDTP Singnalling Message.
This will be used to verify the response from the remote device
Memory will be allocated by the application.

Change-Id: Ic31df154b52ce9013e5039ab195a9651d1811a7a
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
f2c44466a4 Bluetooth: SDP: Add connected and disconnected handlers
Adds for now stubs of handlers responsible for taking a connected and
disconnected state of SDP L2CAP channel.

Change-Id: I21b76b755168fb63f6cade5f6b0c0bab93d0a01f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa
b71e34da81 Bluetooth: SDP: Initial implementation of bt_sdp_discover API
Adds basic functionality to be able to trigger establishing outgoing
L2CAP channel to remote using as PSM SDP channel. The number of such
outgoing connections is limited by configured pool of connections.

Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>

Change-Id: Ie5428e5b1b5f5c57f473ee0adfd4621cd9fe6e3e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Sathish Narasimman
9abbc61e4a Bluetooth: AT: Command parsing for range of values
This patch contains API's which is used to parse range of values
eg. (0,3). This patch also parses the string, reads, process and
move the buffer accordingly.

Change-Id: I8dba5b7d630f65b87967c101557c5c7ffd297dd1
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-12-24 08:42:15 +02:00
Szymon Janc
bddf039736 Bluetooth: Make BR/EDR discovery be limited only by time
If more inquiry results were received during discovery than fits in
storage results with lowest RSSI will be skipped. This is to improve
API usefulness in busy environments where results with low RSSI (likely
more far away than high RSSI) could consume provided result space,

Change-Id: I1e9ca901b693f608d58575916809e8bd8bfe710f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Sathish Narasimman
77446839ad Bluetooth: AT: Improve API() to work with buffer increment
at_get_number which converts the string into number now operates on
at_client to get the string buffer. This patch also improves API()
skip_whitespace to be operated on at_client. Also the the API's
get_cmd_value, get_response_string are updated to work with buf
increment.

Also in this patch the return type of the function str_has_prefix
is changed from 'int' to 'bool'.

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

Change-id: I76c82df895c6daaffef52786b0c900ee15acb0aa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery
0b1e6fb231 Bluetooth: RFCOMM: Respond to RLS command
If remote sends RLS command then it should be responded with the
value received.

> ACL Data RX: Handle 256 flags 0x02 dlen 12
      Channel: 64 len 8 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 4
         FCS: 0x70
         MCC Message type: Remote Line Status CMD (0x14)
           Length: 2
           dlci 10 error: 5

< ACL Data TX: Handle 256 flags 0x00 dlen 12
      Channel: 64 len 8 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 4
         FCS: 0xaa
         MCC Message type: Remote Line Status RSP (0x14)
           Length: 2
           dlci 10 error: 5

Change-Id: Ib70e02aede2088bca748d1eb68bee9b1bc47a65d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Jaganath Kanakkassery
e03f2e249e Bluetooth: RFCOMM: Remove unneeded NULL checks
rfcomm_make_uih_msg() does not return NULL anymore.

Change-Id: I8f49b85df8924af1e0d382e699e655a1ffe70662
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-24 08:42:15 +02:00
Johan Hedberg
2b410afac1 Bluetooth: Fix priority event buffer availability when ECC is used
The ECC emulation synthesizes its own HCI events so we may need up to
two available priority buffers at any point in time.

Change-Id: I88b37c7e9e9f64483d80cde9243470a7f0477321
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arun Jagadish
a535880505 Bluetooth: AVDTP: Fix Coding style
Fix modifies the comment section.

Change-Id: Ie105a12f613a1c179aa01eb39298df2ee51c2da3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-24 08:42:15 +02:00
Carles Cufi
fc479e03e0 Bluetooth: controller: Use SERIES config instead of NRF52
In preparation for the new Nordic MDK and nRF52840 IC support we switch
to using the SERIES config instead of the old "NRF52" macro that will be
deprecated in the new MDK.

JIRA: ZEP-1418

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

Change-Id: I496f4d05d26801eddd21fae53bdd4fcdc3246fe3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Szymon Janc
83874836ac Bluetooth: SMP: Add support for CT2 auth bit
This allows to use H7 function for key derivation if both sides declare
support for it.

< ACL Data TX: Handle 77 flags 0x00 dlen 11
      SMP: Pairing Request (0x01) len 6
        IO capability: NoInputNoOutput (0x03)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, No MITM, SC, No Keypresses,
                                    CT2 (0x29)
        Max encryption key size: 16
        Initiator key distribution: EncKey IdKey Sign LinkKey (0x0f)
        Responder key distribution: EncKey IdKey Sign LinkKey (0x0f)
> ACL Data RX: Handle 77 flags 0x02 dlen 11
      SMP: Pairing Response (0x02) len 6
        IO capability: NoInputNoOutput (0x03)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: Bonding, No MITM, SC, No Keypresses,
                                    CT2 (0x29)
        Max encryption key size: 16
        Initiator key distribution: IdKey Sign LinkKey (0x0e)
        Responder key distribution: IdKey Sign LinkKey (0x0e)

Jira: ZEP-1431

Change-Id: I74ecfdd38a69bada0927907a0ef9ed6d59212e47
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Szymon Janc
a2d8cee2cf Bluetooth: SMP: Add H7 crypto implementation and unit tests
This adds H7 function implementation and test based on sample data
from Core Specification 5.0 Vol 3. Part H. Appendix D.8.

Jira: ZEP-1431

Change-Id: I49d44ee7a352d1092f6379829d747c7e0ec5e83c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Vinayak Chettimada
f0bd2805bc Bluetooth: Controller: tune the xtal and hard realtime radio start offsets
Reduce the time limit for active clock startup and increase
the CPU usage time limit before hard real-time radio
transmit/receive.

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

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

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

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

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

Change-id: Id58322ad76a0dbc284738cdd9a7c0437c9e8c423
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery
c776791ed0 Bluetooth: RFCOMM: Rename tmp with next
"next" is more relevant since its used to save next pointer

Change-Id: Ic0a8d543944681ba4291c5aa06125f565ab6115c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery
3ec7df34c1 Bluetooth: RFCOMM: Handle DM from peer
Outgoing connection request would be rejected by peer because
of various reasons like server channel not registered etc.
This handles that by destroying the dlc and informing the same
to user.

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 4 frame_type 0 credit_flow 15 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 5

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect Mode (DM) (0x0f)
         Address: 0x13 cr 1 dlci 0x04
         Control: 0x1f poll/final 1
         Length: 0
         FCS: 0xbc

Change-Id: I98288db045001bb73ecfd54e7677d88b2bda9c13
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Jaganath Kanakkassery
a95de4360c Bluetooth: RFCOMM: Disconnect session after last dlc disconnection
As per the spec the station which disconnects last dlc should initiate
session disconnection and then l2cap disconnection.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0xfd

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xb6

Change-Id: I2d1d7d284995529d5d1522e0ca6082097db19bc2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg
bc8ec12977 Bluetooth: Remove unnecessary NULL check
Change-Id: I6ec661cdd64c3c22d85f84c6246e4dcd5db71815
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg
758e220cdc Bluetooth: Remove inline declaration from bt_le_conn_params_valid
The function is not particularly small, and is used from several
places, so remove the inline declaration. This also prepares the way
for the possibility of having an application callback for letting the
application choose whether it's fine with the proposed parameters, and
thereby influence the response we send to the remote device.

Change-Id: I5848b179318b6fb6ee37fcbd479a919204f559f1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Szymon Janc
8d759fcec4 Bluetooth: SMP: Fix key_id length in smp_h6_test
key_id is 4 bytes value.

Change-Id: I2550f3c2b5ab328562fa4375d215b04d2fc76e6f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-16 10:27:48 +02:00
Arun Jagadish
7f6a059a36 Bluetooth: AVDTP: Add AV-Stream data structure
AV-Stream Data structure added to AVDTP structure.

Change-Id: Icb6ae80e84b49e8a800c99e7f004b43a0fa6c043
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg
6ca9390e4d Bluetooth: Kconfig: Fix logging dependency on printk
Now that all logging methods use printk as a backend the respective
Kconfig options should declare the right dependencies.

Change-Id: I65c759db0ec7ba6333b76d8d20aea0e374fd4947
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg
d659bb020e net: buf: Remove redundant user_data_size from buffers
Since the user data size is now stored in the pool there's very little
value in storing it as well per-buffer.

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

Change-Id: Ia126af101c2727c130651b697dcba99d159a1c76
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-15 09:58:02 +02:00
Johan Hedberg
45bc46d42e net: buf: Introduce net_buf_destroy() wrapper
This is only for use with custom destroy callbacks, so that the
application gets isolated away from the details of how exactly the
buffers are managed. This opens up the possibility of switching away
from k_fifo to potentially better solutions, such as k_lifo.

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

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

	NET_BUF_POOL_DEFINE(pool_name, ...);

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

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

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Johan Hedberg
3fcb9c4ec2 Bluetooth: Use _vprintk() instead of _prf()
The Bluetooth thread stack sizes are optimized based on the assumption
that printk is used for logging and not printf. Using _prf() (the
printf backend) risks overflowing the stack, so use the recently
exposed _vprintk instead.

Change-Id: Ibcbe0af2994c83114d12aa27a8bc29c77bb8c4c8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-11 04:26:06 +00:00
Arkadiusz Lichwa
24b03e75f3 Bluetooth: Remove not needed header in uuid.c file
Now printk family from <misc/printk.h> already included should handle
BT_DBG() like expansion.

Change-Id: I5e03f786530e4bbbdb94a13a4cd77db580268c11
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 19:34:59 +01:00
Arkadiusz Lichwa
c4fa607499 Bluetooth: Fix format specifier in UUID DBG helpers
Replace precision formatter (.) in printk with padding flag like %04x
since for now precision is not handled properly in printk family.

Change-Id: Ib63198e407ef584c5650d6452518b1767047630f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 19:33:56 +01:00
Johan Hedberg
26056c8318 Bluetooth: Fix left-over printf usage
These should have been converted to using printk instead.

Change-Id: I62323704dad4fc51cc14ee4734acb6b325dcda14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 12:26:02 +00:00
Jaganath Kanakkassery
4349141935 Bluetooth: RFCOMM: Implement Disconnect API
This will be used by the user to disconnect or cancel connect dlc.
This also defines an internal close function which will take
appropriate action based on the dlc state.

In case of user initiated disconnection if some pending packets are
there in queue then it has to be sent before sending DISC packet.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x2b cr 1 dlci 0x0a
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0x6d

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x29 cr 0 dlci 0x0a
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x26

Change-Id: Ie4fa3bd8f6b279fee6fb56ddce198d82c5047849
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-09 06:52:56 +00:00
Arkadiusz Lichwa
5c0a502e9f Bluetooth: L2CAP: Fix uninitialized pointer
When PSM server doesn't have BR/EDR L2CAP resources to assign and handle
incoming request properly, local channel pointer may stay uninitialized.
This fixes such scenario. The fix refactors main connection request
reply handler to additional helper which can be used to send response
unconditionally for situation when local channel is not allocated
to setup L2CAP link between.

Jira: ZEP-1405

Change-Id: I5caedd63a59ad0d1704ac87fa51616a0770320bf
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg
f53388dbb9 Bluetooth: L2CAP: Fix format specifier for hex uint16_t
Instead of %4.4x we need to use %04x which printk supports.

Change-Id: I0564be5531bb266b328f77231f5d00f43eabe1ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz
4a0c9e86f6 Bluetooth: GATT: Update CCC addresses
If connection destination address has been changed update the addresses
stored by the time it disconnects since in case of RPA it is no longer
mapping to the same device after it has been disconnected.

Change-Id: I0ce966928f605a885125179eaa7b9093989825ab
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz
624a170e8d Bluetooth: GATT: Fix using bt_addr_le_cmp with destination address
The connection destination address may change if the identity address
is resolved.

Change-Id: Id6f7b6494c24ff118043ba5f4ff54e254376eddf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Luiz Augusto von Dentz
ae213a2ea8 Bluetooth: Fix bt_conn_lookup*
bt_conn_lookup shall work both with identity address or initial
destination address as bt_conn may change the destination address with
the identity address.

Change-Id: Ibdd19ec453c3307eb6db188196b7e57a2260b526
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg
a4b6b2417d Bluetooth: Switch from printf to printk functions
There's now snprintk available that's more light-weight on the stack
than snprintf.

Change-Id: I6b3e4409703ca92fe6b8f4146ff47c490ab826cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg
5ac059b6b9 Bluetooth: Extend advertising parameters with optional own address
Applications may want finer control of the NRPA used for
non-connectable beacons, and provide it up-front rather than letting
the stack generate one.

Change-Id: I84d459372cc85ed09a8f9cde16dbb9b98dec2a43
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg
d883fcf814 Bluetooth: Make LE random address helpers public
Expose helpers in hci.h for setting and getting the LE random address
type.

Change-Id: I7c6437051f0b2d1f5f79e19b2616bb643ae6300b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Arun Jagadish
ede69e5d19 Bluetooth: AVDTP: Fix Coding style
Fix modifies the comment section.

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

Change-Id: I4d6f635a0ed61de698727028ea8767dc0ef28bb1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-07 13:15:59 +00:00
Johan Hedberg
299216b2f0 Bluetooth: Controller: Make use of min() convenience macro
Instead of having custom logic for determining the minimum of two
values, use the existing min() helper from misc/util.h.

Change-Id: I9809883d4a31126329373f293897dd49eb91e9ad
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery
e36d58e593 Bluetooth: RFCOMM: Remove send DM from drop()
rfcomm_dlc_drop() can be used from many places to unlink dlc
from session and destroy it. So it is better to send DM
explicitly from relevant places.

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

Change-id: I6ad7196e3db44b303ddf2ec06e0ae579bf2eb774
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Szymon Janc
d1187302e0 Bluetooth: Make bt_send stack requirements a Kconfig option
This allows to fine tune TX stacks size depending on selected HCI
driver. If needed it can be used to tune for monitor too or other
logging mechanism used.

Change-Id: Ib501921da0b786e151083760d85ec58fe3c08b60
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc
b00e747ddf Bluetooth: L2CAP: Fix set but not used variables
If debugs are disabled scid and dcid variables were never read.
This also fix mixed values of scid and dcid in le_disconn_req.

Change-Id: I3b435dd0640c5c65ab5fe68e33dd25e3c9e0026e
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc
efec1aa79d Bluetooth: Fix missing prototype config
subsys/bluetooth/host/hci_ecc.c: At top level:
subsys/bluetooth/host/hci_ecc.c:277:6: warning: no previous prototype
      for 'bt_hci_ecc_init' [-Wmissing-prototypes]
 void bt_hci_ecc_init(void)
      ^
  CC      subsys/bluetooth/host/conn.o

Change-Id: I920d8b6b66c82be932c579461310505c6d402c08
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Johan Hedberg
cb84ad1ad6 Bluetooth: Fix coding style issues in LE address helper functions
Even one-line branches should have {}, and the last two return
statements can be simplified into a single one.

Change-Id: I0f65aeaba867240255eae8e1c461386700444ae6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-03 17:09:38 +00:00
Szymon Janc
70417f1fce Bluetooth: Simplify ncmd handling
With k_sem API it is possible to specify maximum sempahore value
so we no longer need to track semaphore count.

Change-Id: I86744ba63bd3207051ca3466d4f81b816d24f5ad
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Szymon Janc
a081e0a57f Bluetooth: GATT: Fix primary service discovery response
Applications expect service end handle as attribute value in userdata
on discovery response callback.

Jira: ZEP-1354

Change-Id: I664da4a7e054a531ad1c2c8cbc74367cb679ff03
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery
dd94c3b3eb Bluetooth: RFCOMM: Handle security for outgoing DLCs
Security needs to be elevated based on dlc required sec_level
before creating dlc. If L2CAP connection is not created then
setting dlc required sec_level to chan would do the job.

Change-Id: I21debd3559c9ccfb79011160d676932bc2a54604
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-03 17:09:38 +00:00
Carles Cufi
d42987acf4 Bluetooth: Controller: Fix local LE supported features bitmap
Correct the local LE supported features bitmap to actually "or"
together all the bits that correspond to the set of features that
are implemented at this time.

Change-Id: I0c62ec566c775514250fcf062aeef6c9656719e3
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Arun Jagadish
6f3c4bf425 Bluetooth: AVDTP: SEP Definition
Added
SEP structure
SEP Registration function

Change-Id: Ib8c4a1753c85390009c154a50a1a1a2f2794e8a2
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz
30838af5e9 Bluetooth: L2CAP: Fix possibly reading past the end of buffer
If the original buffer cannot be reused, either by no having enough
space for user data or if is fragmented, it can in fact be smaller than
both the segment buffer and MPS.

Change-Id: I59a537aff59c5d56b2883e9bd51f3a1a3932d348
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz
37b0e0ab2e Bluetooth: L2CAP: Fix segmentation
The segments need to be limited by the minimun of the segment buffer
tailroom and tx MPS not the original buf length.

Change-Id: I580a3bb61aa190ac0cdd3717bc06fd6e6e668304
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-12-03 17:09:38 +00:00
Carles Cufi
3b1baa88ef Bluetooth: Controller: Implement ECC commands
Implement the 2 HCI commands that provide ECC public key
and shared secret generation:

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

Jira: ZEP-1246

Change-Id: I79388bfdb9f2e28b9377b4bb6ee2caca25f33f3e
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-12-03 17:09:38 +00:00
Jaganath Kanakkassery
8166de77db Bluetooth: RFCOMM: Initiate DLC
This patch initiate a DLC when user calls connect. It first does
Parameter negotiation and then establish connection to the
dlci derived from channel given by user.

< ACL Data TX: Handle 256 flags 0x00 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 3 frame_type 0 credit_flow 15 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 4

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x01 cr 0 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0xaa
         MCC Message type: DLC Parameter Negotiation RSP (0x20)
           Length: 8
           dlci 3 frame_type 0 credit_flow 14 pri 0
           ack_timer 0 frame_size 30 max_retrans 0 credits 7

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x59

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x92

Change-Id: I62a19f624fc4bb89eb9a109a5352fa763c1241d2
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-18 17:27:01 +05:30
Jaganath Kanakkassery
d9eb0fb2a0 Bluetooth: RFCOMM: Refactor rfcomm_handle_pn()
Handle the scenarios like ignoring a response in non existing dlc,
correctly handle if received a command with invalid mtu etc.

Change-Id: Ib0bce9134bac3a0dead03798f859af54873a70c1
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-18 17:27:01 +05:30
Luiz Augusto von Dentz
1bbb31e201 Bluetooth: L2CAP: Fix regression with move to k_sem API
k_sem_take return differ from nano_sem_take since it return 0 for
successful case instead of 1.

Change-Id: Ia39cd624d56dbc1c8e7f3558244bebf765da191d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Szymon Janc
8217bb1ef6 Bluetooth: Kconfig: Remove deprecated dependency on NANO_TIMEOUT
This is no longer needed after switch to unified kernel.

Change-Id: Ie1f8dadb3f2e43ae6ccfbfaf1f754196f3237471
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Szymon Janc
6cda540a4e Bluetooth: Kconfig: Remove deprecated dependency for ECC support
After switch to unified kernel this is no longer needed.

Change-Id: If9877d3fa038dd873011fb780c7e767e150647ae
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Luiz Augusto von Dentz
58a2b3df7c Bluetooth: GATT: Fix using out of scope variable
This fixes defect found by coverity: 152027 Pointer to local outside
scope.

Change-Id: I50f196a04363ffa6e6654b71a9a1d89034580413
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Carles Cufi
c969e757bc Bluetooth: Controller: Implement missing DLE commands
Implement the 3 missing HCI commands required to support
Data Length Extensions:

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

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

Jira: ZEP-1246

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

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

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

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

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

Change-Id: Id4b2e354961dfb3b45f72fa4e0ab18de7425bbb5
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Szymon Janc
a2ee111aa0 Bluetooth: Fix address type use for passive scanning
This fix using incorrect address type for passive scanning with
privacy enabled. Controller was not reporting directed advertising
to RPA address due to public type being used for passive scan.

This was affecting TC_CONN_GCEP_BV_01_C, TC_CONN_ACEP_BV_01_C and
TC_CONN_DCEP_BV_01_C qualification test cases.

Jira: ZEP-1200

Change-Id: Icc316441fcac1a72d75f9ade27a99030efc846b9
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Luiz Augusto von Dentz
c0edc551b5 Bluetooth: GATT: Fix using att_ prefix
This might create confusions when debugging as usually the prefix is
associated with the file or layer.

Change-Id: Ibf45578c1f54a4bec896acd6042589c815216e1f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-18 07:47:50 +02:00
Szymon Janc
243668dbc4 Bluetooth: Kconfig: Fix BR/EDR dependencies
BR/EDR code should have minimal impact on LE code so to keep it simple
just require peripheral and central to be enabled when selecting BR/EDR
support.

Fix following Kconfig warning:

warning: (NETWORKING_WITH_BT && BLUETOOTH_BREDR) selects
    BLUETOOTH_L2CAP_DYNAMIC_CHANNEL which has unmet direct dependencies
    (BLUETOOTH && BLUETOOTH_HCI && BLUETOOTH_HCI_HOST && BLUETOOTH_CONN
    && BLUETOOTH_SMP)

Change-Id: I7f7cb8794def0df6daaa4abfe4596df460f1a2b2
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-18 07:47:50 +02:00
Szymon Janc
9dde3e02fd Bluetooth: Fix use of deprecated PRIMARY init level
Fix following warning:

  CC      subsys/bluetooth/host/monitor.o
In file included from zephyr/include/drivers/loapic.h:58:0,
                 from zephyr/include/drivers/ioapic.h:22,
                 from zephyr/include/drivers/sysapic.h:20,
                 from zephyr/include/arch/x86/irq_controller.h:33,
                 from zephyr/include/arch/x86/arch.h:28,
                 from zephyr/include/arch/cpu.h:23,
                 from zephyr/include/kernel.h:2458,
                 from zephyr/include/zephyr.h:20,
                 from zephyr/subsys/bluetooth/host/monitor.c:24:
zephyr/subsys/bluetooth/host/monitor.c: In function
    '_deprecation_check_sys_init_bt_monitor_init0':
zephyr/include/device.h:130:16: warning: '_INIT_LEVEL_PRIMARY' is
    deprecated [-Wdeprecated-declarations]
  static struct device_config _CONCAT(__config_, dev_name) __used \
                ^
zephyr/include/device.h:245:2: note: in expansion of macro
    'DEVICE_AND_API_INIT'
  DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \
  ^
zephyr/include/init.h:69:2: note: in expansion of macro 'DEVICE_INIT'
  DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio)
  ^
zephyr/subsys/bluetooth/host/monitor.c:193:1: note: in expansion of
    macro 'SYS_INIT'
 SYS_INIT(bt_monitor_init, PRIMARY, MONITOR_INIT_PRIORITY);
 ^
zephyr/include/device.h:48:31: note: declared here
 static __deprecated const int _INIT_LEVEL_PRIMARY = 1;

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

Jira: ZEP-1282

Change-id: Ifb9ae6807736b5ec2d9f346cf2a590322056bcee
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Mariusz Skmara
2305196461 Bluetooth: Fix not sending L2CAP Connection Parameters Update Request
This fixes issue that L2CAP Connection Parameters Update Request was
not sent. There was check that used LE features of host controller
to determine if L2CAP procedure or LL shall be used. It was failing
with 4.2 controller. The check shall test if remote supports
LL Connection Parameters Request Procedure. If it's not supported,
then L2CAP Connection Parameters Update Procedure will be used.

Closes ZEP-1220

1/4   L2CAP   TC_LE_CPU_BV_01_C      PASS
2/4   GAP     TC_CONN_CPUP_BV_01_C   PASS
3/4   GAP     TC_CONN_CPUP_BV_02_C   PASS
4/4   GAP     TC_CONN_CPUP_BV_03_C   PASS

Change-Id: I61ad544d9568ca6306a845e05c1a2e28d1693ab4
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-18 07:47:50 +02:00
Johan Hedberg
2469bd6f87 Bluetooth: Use convenience macros for timeout durations
Using the K_* macros makes it easier to read what exactly the various
timeouts are.

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

Change-Id: I2f2a16360e816f9f8791eb216deb3c70b8cc87df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 19:27:34 +02:00
Vinayak Chettimada
4812b2d40e Bluetooth: Controller: Fix device whitelist feature
During the initial integration of controller to Zephyr OS,
radio hardware access was abstracted out into hal/radio.c
file. Bug introduced in hal/radio.c has been fixed so that
whitelist feature works again.

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

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

Change-id: Icef88dffc85746f3cc7adb7fb692ae5578274ed2
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-11 11:56:47 +00:00
Johan Hedberg
a14680f7c0 Bluetooth: hci_ecc: Convert to new thread API
Convert from a private task to the thread API, also add stack usage
analysis and tune-down the stack size to avoid wasting memory:

On x86:
ecc stack (real size 1280):	unused 80	usage 1136 / 1216 (93 %)

On arm:
ecc stack (real size 1280):	unused 52	usage 1128 / 1180 (95 %)

Change-Id: Iba84a5a9cb5257c1456663adf4952c5c18650f97
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:52:02 +02:00
Johan Hedberg
81975637dc Bluetooth: Rename left-over mentions of "fiber" to "thread"
Rename left-over mentions in code comments of "fiber" to "thread".

Change-Id: I1af1baf99652434e90eb491c10238b94d26d341d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:06:05 +02:00
Johan Hedberg
916ed6cdd2 Bluetooth: Controller: Stop using deprecated APIs
Switch from fiber_start() to k_thread_spawn() and from NANOKERNEL to
POST_KERNEL init level.

Change-Id: I34fb11cbe20216c8646ebacb07be304a67e3cd0a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 10:04:02 +02:00
Johan Hedberg
8b92cb2d78 Bluetooth: RFCOMM: Switch to using k_thread_spawn()
Use k_thread_spawn() instead of the deprecated fiber_start() API.

Change-Id: I42e798ef3a4276863659c8d97c85224a652be1fd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:55:27 +02:00
Johan Hedberg
500010d369 Bluetooth: Remove need for fiber offload
The bt_recv() function had protections for being called from a
preemptible task context, however nothing was protecting preemption by
ISR. A fairly simple fix is to protect the couple of critical regions
that can be reached from bt_recv() with the help of irq_lock().

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

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

Change-Id: I8f52031f52f7ac8783033a51751dc22decdfa59a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 09:38:40 +02:00
Johan Hedberg
80e04e4fd1 Bluetooth: Use k_uptime_get() instead of deprecated sys_tick_get_32()
Switch to using k_uptime_get() instead of the deprecated
sys_tick_get_32() API.

Change-Id: I737ef0153eff9d283bae840ff5177f8132396e1b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:38:24 +00:00
Szymon Janc
2b16287286 Bluetooth: Use proper timeout defines for net_buf_get_timeout
Use defines from k_fifo intead of legacy API.

Change-Id: Ib8cf0d88240ef145da550b8cf83d2580e7140521
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 06:00:28 +00:00
Szymon Janc
577fe910ae Bluetooth: Remove not needed nano_work.h includes
Those are lefovers from nano_delayed_work usage.

Change-Id: I3f17c7b89b1fa946495e160732457500e2f74f25
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
203897d04e Bluetooth: HCI: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in HCI layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: I953a82a6aa613bb1072a8ad4b01e0f94e5cd64bd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
5aef8dd1ad Bluetooth: conn: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in bt_conn layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: Ia8f34b475051515fd74000cce745ad226aa18aa5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
b96efa9efd Bluetooth: SMP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in SMP layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeout values have been changed.

Change-Id: Ida58ff0f609dc2a8fd415692bc2cec91eb56a294
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
ec57d7cdb2 Bluetooth: ATT: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in ATT layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeouts values changes.

Change-Id: I14d8438c1537febcb7768ef2934042ce38682739
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
b3cece0af1 Bluetooth: L2CAP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in L2CAP layer.

Note that k_delayed_work takes a timeout in miliseconds rather than in
ticks thus the timeouts values changes.

Change-Id: I1e3bd7857248865e34a313dd42862af5f4e3805b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc
47eaaf9f96 Bluetooth: Use unified k_fifo API for FIFOs
Change-Id: I6ddc24575e4bf3c3040945a2bdb62f153b15cdb3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg
3062516a1a Bluetooth: Controller: Improve default RX/TX buffer counts
Currently the ideal buffer counts for a controller-only build are 6 RX
buffers and 7 TX buffers: ATT_MTU of 158 bytes can be sent in one
connection interval of 6 tx/rx -es wherein connection interval is
7.5ms

Change-Id: I64b4620c5e8e7db8d7ed72fa1db82e266e121f27
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc
27cbd586cb Bluetooth: ATT: Fix non-ASCII characters in code comments
Change-Id: Ief28ffbab1f1751344184b35e40f32e1fc1d6ac9
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Jaganath Kanakkassery
00457636f8 Bluetooth: RFCOMM: Initiate session connection
This patch introduces the Connect API which initiates session
connection first. If session is already there with the peer
then it has to reuse it and initiate DLC (which will be done
in the subsequent patch) since there can be only one session
per device.

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x1c

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xd7

Change-Id: I9828e0f3b3ea43bb17df95f0536e15df86f1b4be
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg
e4c5c96a16 Bluetooth: Fine-tune default incoming ACL buffer count
In some SMP + GATT scenarios it's possible we get up to 6 incoming ACL
packets. To handle these efficiently, and more importantly, to not
have to drop data if the controller lacks host flow control (as is the
case currently with Zephyr-based controllers), increase the default
from 5 to 6.

For a controller-build it makes sense to just match up with the
controller-side configured RX buffers.

Change-Id: Id44fa724597b88a51f9085dac009e8d84a439bfc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg
b64e0d4c51 Bluetooth: Kconfig: Remove redundant 'default n' declarations
All boolean options default to 'n' without the need to explicitly
state this. It's only the cases where we want 'default y' where we
need to state this.

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

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

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

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

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

Change-Id: I5bb715cb9d20201cb8b72fbd149c8a09a4b2d7d2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg
1c40b964a0 Bluetooth: Dump the content of unhandled events as hex
This should be particularly useful with the recently added controller
assert functionality that causes vendor events with debug information.

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

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

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

Change-Id: I2722a8b33f5f74be110dc43fbcecc12841f0db84
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
629ab2da6b Bluetooth: ATT: Fix not forwarding error properly
When retrying the request due to a security error that can fail but since
the original buffer was freed in the process the code can no longer verify
if the opcode matches thus it always fails BT_ATT_ERR_UNLIKELY instead of
using the response error, so this not longer cares about the opcode and
just use the response error always.

JIRA: ZEP-1195

Change-Id: I1149b993b97733ab5bb00f347e4f973647e0fdd4
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Luiz Augusto von Dentz
bc3af66a01 Bluetooth: L2CAP: Add helper function to create LE signalling PDUs
This consolidate code around LE signalling header handling which has been
duplicated in many places.

Change-Id: I0c2cd48c155b751e1bbbd26070965d075cdc2cc5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:43:43 +00:00
Carles Cufi
6ccfa64b5c Bluetooth: Controller: Handle LL_UNKNOWN_RSP PDU for remote features
When a peer controller does not recognize one of the LL control
PDUs received, it will issue an LL_UNKNOWN_RSP PDU to let the
peer know that it does not recognize the request.
The controller now handles this incoming PDU and completes the
procedure by issuing the appropriate HCI event in the case of
an LL_FEATURE_REQ and _RSP pair.

Jira: ZEP-1220

Change-Id: I7c04a346441f04deee41198daa6309c11ae1b571
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-09 08:57:52 +02:00
Johan Hedberg
195e1b89b1 Bluetooth: Fix usage of C++ reserved word
'private' is a C++ reserved word and will lead to compilation errors:

  C++     ble.o
In file included from ble.cpp:7:0:
 include/bluetooth/bluetooth.h:284:10: error: expected unqualified-id before 'private'
  uint8_t private[4];

Change-Id: I36aef5a84af4fc66e1c810bd0c56e5ab5f803294
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Sathish Narasimman
c719bfb689 Bluetooth: HFP HF: SLC connection-Send/Parse BRSF
Service Level Connection(SLC) Initialization part. Sending AT+BRSF
and parsing its response.

< ACL Data TX: Handle 256 flags 0x00 dlen 20
      Channel: 75 len 16 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x09 cr 0 dlci 0x02
         Control: 0xef poll/final 0
         Length: 12
         FCS: 0x40
        41 54 2b 42 52 53 46 3d 31 34 38 0d 40           AT+BRSF=20.

.
> ACL Data RX: Handle 256 flags 0x02 dlen 23
      Channel: 64 len 19 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xff poll/final 1
         Length: 14
         FCS: 0x86
         Credits: 4
        0d 0a 2b 42 52 53 46 3a 20 38 37 31 0d 0a 86     ..+BRSF: 871.
> ACL Data RX: Handle 256 flags 0x02 dlen 14
      Channel: 64 len 10 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0xef poll/final 0
         Length: 6
         FCS: 0x9a
        0d 0a 4f 4b 0d 0a 9a                             ..OK...

Change-Id: I51581928d479ea4229b32a07cbea86c1f6fe09c8
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-09 08:57:52 +02:00
Sathish Narasimman
b0d34d83c5 Bluetooth: AT handling error condition
In function at_get_number check for the value if gets computed.
If not return error. Also change the end state handling.

Change-Id: I193b04fa2880dfb44e7727b30b67c1ec2e051cc7
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg
8ed846285e Bluetooth: Implement bt_storage_clear()
Add an implementation for the bt_storage_clear() API.

Jira: ZEP-181

Change-Id: Iae01c571c161317ea0cc44513d108301c7b5a069
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg
77a8516dd2 Bluetooth: storage: Add basic support for internal storage
Add basic implementation of an internal storage handler that uses the
local file system. The root directory for all Bluetooth related data
is /bt. Each remote device has its own subdirectory and each key its
own file. This helps keep the implementation very simple, but does
come with the meta-data overhead for each file.

As an example, the value of a key 0x0001 for a device with a static
random address cc:11:22:33:44:55 would be stored in the following
file: /bt/cc11223344551/0001. Local values such as the identity
address are stored directly under /bt with a file name that matches
the key the same way as remote-device files.

For full functionality the implementation requires a file system that
can support file/directory names of up to 13 characters in length. If
the file system supports less than that (as is the case with FAT12)
then only local values can be stored (in /bt/abcd). Local values
include the identity address as well as the local IRK.

Jira: ZEP-181

Change-Id: I7dc696af6353a154cb00dcd01a5f4ac3d7127e6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc
e18e3ed60a Bluetooth: Controller: Use unified k_sem API for semaphore
Change-Id: I02b4e5f4d0a2995cfae1b9a2edcbdf01d6ec631a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc
8f800a8bfe Bluetooth: Use unified k_sem API for semaphores
Change-Id: I0099c837cc8ad67b8f927b2debd771acfe626eea
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc
8944c25c90 Bluetooth: Controller: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ib72c4038637c303ee32e433706355299ae1b9a13
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz
3808ad0a96 Bluetooth: L2CAP: Limit segments to TX MPS
le_data buffers are no longer limited to the minimun of 23 bytes, instead
it uses CONFIG_BLUETOOTH_L2CAP_IN_MTU which means it can be bigger than
the MPS thus causing invalid data to be sent:

> ACL Data RX: Handle 64 flags 0x02 dlen 18
      LE L2CAP: LE Connection Request (0x14) ident 1 len 10
        PSM: 128 (0x0080)
        Source CID: 64
        MTU: 672
        MPS: 23
        Credits: 65535
< ACL Data TX: Handle 64 flags 0x00 dlen 18
      LE L2CAP: LE Connection Response (0x15) ident 1 len 10
        Destination CID: 64
        MTU: 230
        MPS: 65
        Credits: 4
        Result: Connection successful (0x0000)
< ACL Data TX: Handle 64 flags 0x00 dlen 27
< ACL Data TX: Handle 64 flags 0x01 dlen 2
      Channel: 64 len 25 [PSM 128 mode 0] {chan 0}
        3c 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff  <...............
        ff ff ff ff ff ff ff ff ff

JIRA: ZEP-1219

Change-Id: Id67f1faac8766c66aa24c7421d44112434666a10
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc
3317227437 Bluetooth: Remove workaround for Mynewt firmware bug
This is not needed for Zephyr controller build and should already
be fixed in Mynewt.

Change-Id: I39e81dc3e9b5fd5a3f5f823465527248625caf26
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Arun Jagadish
227b1d4643 Bluetooth: AVDTP: Set Profile Security Level to Medium
Setting AVDTP Profile Security to Medium

Change-Id: I93aa367ac5bfe4e8bfe08f25d0e7e9d65b891350
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz
4f39b4ceb1 Bluetooth: L2CAP: Fix regression causing credits not to be restored
Patch 8c118f8673 causes the wrong semaphore
to checked so receiving credits are never restored which caused the
channel to get stuck after all the credits are consumed.

JIRA: ZEP-1199

Change-Id: I9cd5474b3bcaafcb19d15613939ce30d07befe0a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Vinayak Chettimada
fb032efa90 Bluetooth: Controller: Use configured clock source
Remove hardcoded use of crystal as 32KHz clock source and
20 ppm accuracy; and use the values from config for sleep
clock source and sleep clock accuracy value in Bluetooth
Controller.

Change-id: I1c0d53ecf8ad158153d5186a6680b5eb03d1641b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-07 12:04:03 +00:00
Benjamin Walsh
8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

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

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Johan Hedberg
f26007d212 Bluetooth: Print full controller info upon init
Provide more detailed information about the controller address and
version upon init when debug is enabled.

Change-Id: I5fe9c7c91f95928cb3cc64b801137bb1466e4115
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:06:31 +02:00
Vinayak Chettimada
d62426030c Bluetooth: Controller: Fix re-encryption procedure
During implementation of alternate encryption procedure
usable in nRF51, commited in
c41d3edda8, re-encryption
procedure was broken. This commit fixes the issue, and
now re-encryption should work on both nRF51 and nRF52.

Change-id: Ia41200f42b1d46e1f3f35ff44b582d4ffcc5f4fa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-04 22:06:31 +02:00
Mariusz Skamra
748c00b31e Bluetooth: GATT: Pass data buffer as NULL if length is 0
So that application could check data pointer to see if any
data have been received and if read operation is complete.

Change-Id: I36c3ff81baefbc535374d937e5297938445eafa6
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz
1b7c219f8a Bluetooth: L2CAP: Make use of bt_l2cap_chan_set_state on BR/EDR
This makes use of the same code used by LE to print the state transitions.

Change-Id: I90a04f3c3f426fde1e0987acb572f7371c483c1c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz
5fecf98c8e Bluetooth: L2CAP: Log state transitions
This adds a common function to log state transitions including the caller
function and line in case something goes wrong:

[bt] [DBG] bt_l2cap_chan_disconnect: (0x0011b14c) chan 0x001199c0 scid 0x0040 dcid 0x0040
[bt] [DBG] bt_l2cap_chan_set_state_debug: (0x0011b14c) chan 0x001199c0 psm 0x0080 connect -> disconnect
[bt] [WRN] bt_l2cap_chan_set_state_debug: bt_l2cap_chan_disconnect()1562: invalid transition

Change-Id: I246a9004a04d93a38b8c7f7633705f6c191698b2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz
349230321f Bluetooth: L2CAP: Fix not updating CoC channel state
Channel state shall be updated properly otherwise it may cause unexpected
errors.

Change-Id: Ifd54d6bd3c5b44a40c315fd8a2946b30168aa65f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery
88038d1782 Bluetooth: RFCOMM: Define macro for PF bit
This defines and clarifies PF bit macro for both UIH and
non UIH packets.

Change-Id: Ide7736c0fc8607708824766adbfccf1bd7bc48e9
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery
70f1df22a4 Bluetooth: RFCOMM: Set sec_level to LOW during L2CAP register
Security will be elevated based on the DLC required level
during connection.

Change-Id: I0b63885582f34a5689f7bc8081c1f9f011b2325f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Sathish Narasimman
56392e5c2e Bluetooth: Fix initialization of variable
Initialize the variable to zero before computing.

Change-Id: Iccdf77a085667728dbb68779f001c8d940a7a89d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz
807bd5fec8 Bluetooth: L2CAP: Handle LE connection response security errors
If there are security errors bump the security of the connection and
retry:

7C:7A:91:18:82:5F (public)> l2cap-connect 0x0080
[bt] [DBG] bt_l2cap_chan_connect: (0x0011ae8c) conn 0x0011b940 chan 0x00119700 psm 0x0080
[bt] [DBG] l2cap_chan_tx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] l2cap_chan_rx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] bt_l2cap_chan_add: (0x0011ae8c) conn 0x0011b940 chan 0x00119700
L2CAP connection pending
7C:7A:91:18:82:5F (public)> [bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 2 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0000 mtu 0 mps 0 credits 0 result 0x0005
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 7
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 7
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 65
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 65
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
Security changed: 7C:7A:91:18:82:5F (public) level 2
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 3 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0040 mtu 672 mps 230 credits 10 result 0x0000
Channel 0x00119700 connected

Change-Id: I2402fd86cc6bdf41a537053325e0a1973c23377a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Luiz Augusto von Dentz
d1ae81eddd Bluetooth: L2CAP: Make CoC depend on SMP
This is necessary in order to properly handle security errors which are
part of the testing specification thus can influence qualification.

Change-Id: If444e753be9196f3d5bb36cea00e332a33aa249f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery
5d40ea1d15 Bluetooth: RFCOMM: Introduce helper to initialize dlc
This is to avoid code duplication while implementing outgoing
connection.

Change-Id: I52f882b7be9180f29def59c8ac3ef0a4798b719d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery
e3c258e286 Bluetooth: RFCOMM: Introduce helper to get session
This is to avoid code duplication while implementing outgoing
connection.

This also moves setting initiator flag while allocating, than
doing it when SABM is received.

Change-Id: I8e811c995bf0eaa0bd24715e2e96d8a578a79c5d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery
2eba256fd2 Bluetooth: RFCOMM: Define enum and macros for role and CR
This replaces initiator flag of session and dlc to enum which has
two values INITIATOR and ACCEPTOR.

Also this defines macros for CRs in header. Basically there are
three types fo CRs. Frame header CR has different meaning for
UIH and non UIH packets. Also this renames the existing msg hdr
CR to make it consistent.

These changes are basically done to make it more readable

Change-Id: Ic15e93465b0afbd19d8805f27d7a43f34ef38689
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery
f6f4acbced Bluetooth: RFCOMM: Remove extra tab
Change-Id: I2edafa32711cbac933d719a1ea0736e955bbb12c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg
26d39cd107 Bluetooth: Move controller code to subsys/bluetooth
Move controller code from drivers/controller to
subsys/bluetooth/controller.

Change-Id: I73f675188485aa3267507bad7647796e593a3da0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg
6bc645962a Bluetooth: Move Bluetooth host stack to subsys
Move the Bluetooth host stack from net/bluetooth to
subsys/bluetooth/host. This is preparation for having both host and
controller under the same root, i.e. subsys/bluetooth/.

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