Commit graph

702 commits

Author SHA1 Message Date
Johan Hedberg 8d02ab52ad Bluetooth: Add command opcode to warning about unusual pool id
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +03:00
Johan Hedberg 029780a196 Bluetooth: Mesh: Fix dropping valid proxy configration messages
Proxy configuration messages are allowed (in fact required) to use
unassigned addresses, so they should be exempt from this check.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg a576c4a73b Bluetooth: Mesh: Don't send health status messages if a test fails
The test failure may be e.g. because of an unknown company id, and in
that case the spec expects us to ignore the message.

With this patch it should be possible to pass MESH/SR/HM/RFS/BI-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 8d0ef1eb85 Bluetooth: Mesh: Fix setting health period divider
A previous patch which moved dispatching the health publish callback
to a later moment introduced a regression where the period divider
does not get updated when it should. In fact, having the divider as
part of the Health Server context is redundant, since the same
information is already stored generically in the model publication
context. Switching to using the model publication context makes things
simpler and ensures that the value is always up-to-date.

With this patch it is possible to pass MESH/SR/HM/CFS/BV-02-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 4d3a2c66d1 Bluetooth: Mesh: Fix Set LPNTimeout message handling
We should ignore invalid addresses (helps pass
MESH/NODE/CFG/LPNPT/BI-01-C). Also fix a copy-paste issue in an error
log.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 19c304086f Bluetooth: Mesh: Fix resetting heartbeat subscription expiry properly
Set the value clearly to 0 instead of letting the old expiry time stay
around.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg f1638e0a2b Bluetooth: Mesh: Fix zeroing heartbeat state
The values all need to be zeroed when heartbeat subscription is
disabled. This makes it possible to pass MESH/NODE/CFG/HBS/BV-01-C.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg ea397170d3 Bluetooth: Mesh: Fix spelling of "heartbeat"
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg 53d06a1653 Bluetooth: Mesh: Fix encoding fault count to Health Current Status
There was a missing adjustment to buf->len after fetching the faults
from the app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg a3a481deb1 Bluetooth: Mesh: Fix Health Period Set OpCode
This was a copy-paste mistake.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-29 13:21:40 +03:00
Johan Hedberg d712a4e1a3 Bluetooth: Mesh: Remove local network interface Kconfig option
From section 3.4.5.3 in the Mesh Profile Specification 1.0:

    "A node shall implement a Local Network Interface."

Removing the Kconfig option also helps clean up quite a lot of code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 16:33:06 +03:00
Johan Hedberg 76fd02ee0c Bluetooth: Mesh: Allow TTL <= 1 for the local net interface
The bt_mesh_net_relay() function needs to allow TTL <= 1 for the local
network interface since that's the code path that locally originated
outgoing packets take.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 16:33:06 +03:00
Johan Hedberg 418cdadeab Bluetooth: Mesh: Send ack for every message with matching FCS
Mesh Profile Specification v1.0, 5.3.3:

"On the PB-ADV bearer, when the receiver has received all segments of
a transaction, the receiver shall calculate the FCS for the received
Provisioning PDU, and if it matches the FCS field in the Transaction
Start PDU, it shall send a Transaction Acknowledgment PDU after
a random delay between 20 and 50 milliseconds."

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 7e779ba69b Bluetooth: Mesh: Always set company ID in health status message
The Mesh specification recommends defaulting to the company ID in the
composition data when no other ID is relevant (e.g. in error cases or
if the app has not provided a callback).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg ac5140891b Bluetooth: Mesh: Set timer for periodic publish before publishing
Encrypting and sending a message takes a considerable amount of time
which makes the publication period longer than expected.

With this patch it is possible to pass MESH/SR/HM/CFS/BV-02-C test.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg fc679c50f9 Bluetooth: Mesh: Fix encoding health status when app has no callback
The branch for handling the case when the app has not provided a
callback for health faults was encoding the payload in a wrong way.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 6b966e4b96 Bluetooth: Mesh: Fix copy-paste mistake when assigning to cfg->frnd
The right value is BT_MESH_FRIEND_NOT_SUPPORTED.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 5363f6e765 Bluetooth: Mesh: Drop invalid destination addresses
This is required to pass certain PTS tests.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-27 13:20:28 +03:00
Johan Hedberg 68b459ec41 tests: bluetooth/at: Fix string signedness issues
To avoid signedness issues with some compilers, like icx, use 'char *'
instead of 'unsigned char *' for the at_client buffer.

Fixes #3600

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:50 +03:00
Johan Hedberg c40dc580b0 Bluetooth: Mesh: Fix SDU length check
The code was passing the wrong first parameter to the sdu_len_is_ok()
function.

Fixes #3985
Fixes #3984

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:23 +03:00
Johan Hedberg 3341439f98 Bluetooth: Mesh: Fix string signedness issue
Some compilers (like icx) may complain about unsigned vs signed
strings.

Fixes #3985

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-26 12:56:23 +03:00
Johan Hedberg bac7367b0a Bluetooth: SMP: Fix responding to Pairing Failed PDUs
It makes no sense to respond with Pairing Failed PDU to another
Pairing Failed PDU.

Jira: ZEP-2620

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-25 14:38:34 +03:00
Steve Brown dfebd40ce1 Bluetooth: Mesh: Avoid spurious "No matching AppKey" warning
Signed-off-by: Steve Brown <sbrown@cortland.com>
2017-09-07 14:26:45 -05:00
Łukasz Rymanowski d3862d7b39 Bluetooth: mesh: Clear link TX when ACK arrived on it
Without this fix there is an issue when doing PB-ADV provisioning
with PTS. We keep retransmitting Public Key which is ACKed by PTS and
this leads to transaction timeout as PTS does not send confirm probably
because it keep receiving PK from us.

This patch also makes sure that transaction id is between 0x80 - 0xFF

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-05 09:25:49 -05:00
Łukasz Rymanowski dbb90a1a99 Bluetooth: mesh: Fix failed provisioning response
Needed for following PTS test cases:

MESH/NODE/PROV/UPD/BV-10-C
MESH/NODE/PROV/BI-02-C

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-05 09:25:49 -05:00
Łukasz Rymanowski c90e09aa88 Bluetooth: mesh: Fix for key size
For input method we should use input_size instead of output_size

Signed-off-by: Łukasz Rymanowski <lukasz.rymanowski@codecoup.pl>
2017-09-01 09:31:41 -04:00
Johan Hedberg f7654a787e Bluetooth: Mesh: Fix setting the right value for Static OOB type
The code was setting the wrong bit of the Static OOB Type when a
static value has been provided.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-09-01 09:30:54 -04:00
Luiz Augusto von Dentz 7d01c5ecb7 poll: Enable multiple threads to use k_poll in the same object
This is necessary in order for k_queue_get to work properly since that
is used with buffer pools which might be used by multiple threads asking
for buffers.

Jira: ZEP-2553

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-08-25 09:00:46 -04:00
Ricardo Salveti 60a908c9c9 Bluetooth: Kconfig: fix default value and range for BT_RX_STACK_SIZE
Fix checks for BT_HCI_RAW and move default range after the other range
options, required by Kconfig to avoid overwriting other options.

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

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
2017-08-17 11:16:03 +03:00
Paul Sokolovsky cf43be1a2e Bluetooth: Increase CONFIG_BT_HCI_TX_STACK_SIZE for BT_SPI
Older value of 256 was introduced in 1.7 times. Testing on
BOARD=96b_carbon with 2 weeks old codebase however showed that TX
thread stack however can grow to 324 bytes. Finally, with the
latest master, following stacks are reported on BLE disconnect
(with CONFIG_INIT_STACKS enabled):

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

Two outcomes:

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

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

Jira: ZEP-2510

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-08-16 14:54:20 +03:00
Marti Bolivar 4e53f4e830 Bluetooth: Kconfig: delete stray double quote
Trivial fix.

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

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

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-14 13:01:39 +03:00
Sebastian Bøe 2120beebf4 Kconfig: Move BT_WAIT_NOP into subsys/bluetooth/host
The CONFIG_BT_WAIT_NOP define is used only by
zephyr/subsys/bluetooth/host/hci_core.c.

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

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

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

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

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

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

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

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

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-08-08 23:01:05 +03:00
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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
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 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
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
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 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 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
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 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
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
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 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
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 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
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
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
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
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
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
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 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
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
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
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 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
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
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
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
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
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
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
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
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
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
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
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 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
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 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
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 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 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