Commit graph

922 commits

Author SHA1 Message Date
Johan Hedberg 5e3804b11d Bluetooth: Mesh: Add support for sending Heartbeat Publication Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 897f32f0d1 Bluetooth: Mesh: Add documentation for public provisioning APIs
Add proper documentation for public provisioning APIs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 255edcfde2 Bluetooth: Mesh: Provisioning: Add NetKeyIndex to complete callback
It may be useful for the app to know what the initial NetKeyIndex that
it was given during provisioning is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 06694787cd Bluetooth: Mesh: Provide documentation for provisioning APIs
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 70cbcef576 Bluetooth: Mesh: Rename health server code from health to health_srv
This is in anticipation of soon adding health client support, which
could then cause confusion due to the ambiguous API names.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 3b252ca2be Bluetooth: Mesh: Rename configuration server code from cfg to cfg_srv
Now that there's support for configuration client as well, rename cfg
to cfg_srv to avoid any confusion.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg 0ef7c6e09a Bluetooth: Mesh: Add more flexible APIs for provisioning bearers
Add the ability to track the provisioning bearer through an extra
parameter to link_open/close. Also introduce new public functions to
enable/disable specific provisioning bearers. This also means that one
now needs to explicitly enable provisioning bearers after calling
bt_mesh_init().

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
Johan Hedberg a81fa43a59 Bluetooth: Mesh: Use proper _t suffix for typedefs
To be consistent with the coding style, use a _t suffix for typedefs.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-15 13:48:29 +02:00
David B. Kinder 5ab1365cf7 doc: fix doxygen defgroup title error
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-11-14 18:31:22 -05:00
Johan Hedberg f50b99572f Bluetooth: Mesh: Add support for sending Heartbeat Subscription Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg b4688bdc84 Bluetooth: Mesh: Add support for sending Model Subscription Add
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg e4db09e919 Bluetooth: Mesh: Add support for sending Model App Bind message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg e1bc6a6141 Bluetooth: Mesh: Add support for sending AppKeyAdd message
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg cbfea942f6 Bluetooth: Mesh: Add support for Relay and 1-byte state Get/Set
Add support to the Configuration Client Model for getting and setting
1-byte states (which can be nicely generalized in code) as well as the
2-byte Relay state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 07305fd71d Bluetooth: Mesh: Add support for sending Beacon Get & Set
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 3d1ce43eb0 Bluetooth: Mesh: Add support for sending Get Composition Data
Add Get Composition Data support to the Configuration Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 588887c9b7 Bluetooth: Mesh: Add primary address to provisioning complete callback
It may be useful for the app to know that the local node's primary
address is.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 2a1e16c2a3 Bluetooth: Mesh: Add skeleton for Configuration Client Model
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 17c9b3a105 Bluetooth: Mesh: Make TRANSMIT_COUNT & TRANSMIT_INT macros public
These are useful for apps who want to implement/use the Configuration
Client Model.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg 52cc3b7d00 Bluetooth: Mesh: Refactor public headers into dedicated subdirectory
As the number of mesh APIs grows it becomes a bit cumbersome to have
everything in a single header file. Split the mesh.h header file into
multiple files in a new mesh subdirectory, and include the new headers
from the old one to retain backwards compatibility and simplicity for
apps (they only need to include <bluetooth/mesh.h>).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 16:48:49 +02:00
Johan Hedberg b4700c3f2b Bluetooth: Mesh: Clarify API for empty model arrays
Avoid applications defining empty model arrays by themselves by
documenting the BT_MESH_MODEL_NONE helper macro (renamed to be more
intuitive) and using it in the mesh sample app.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 14:38:04 +02:00
Johan Hedberg 092a28541a Bluetooth: Mesh: Provisioning: Introduce link open/close callbacks
It may be useful for the app to know when the provisioning link is
active and when it has been closed. This can be used e.g. to signal
the user the state of the device. Some PTS tests also require
verifying the link state.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg 1311676645 Bluetooth: Mesh: Provisioning: Make static OOB value const
This makes it possible for the actual value to reside in ROM.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-13 13:15:07 +02:00
Johan Hedberg eb23d688f2 Bluetooth: Mesh: Fix network credential selection
The only messages that should be encrypted using the friendship
credentials are those coming through the Friend Queue on the Friend
node, most request-response pairs between LPN & Friend (exceptions are
Friend Request - Friend Offer, and Friend Clear - Friend Clear
Confirm), as well as Model Publication messages when the Friendship
Credentials Flag has been enabled in the model publication.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-10 22:17:43 +03:00
Johan Hedberg 56f79f817e Bluetooth: Add support for Link Layer Privacy
Add support for loading IRKs into the controller as well as the LE
Enhanced Connection Complete HCI event. To simplify things, the old LE
Connection Complete handler translates its event into the new enhanced
one which is then the single place of processing new connection
events.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg a74feaaf55 Bluetooth: Add missing HCI defines for LL privacy
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-06 12:50:40 +02:00
Johan Hedberg b452d6f348 Bluetooth: Add support for decoding new address types
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-10-05 13:14:08 +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
Carles Cufi b77b8e615b Bluetooth: controller: Issue Data Buffer Overflow event
Whenever the HCI ACL flow control is violated by the Host, a Data Buffer
Overflow event is now issued by the Controller (if enabled) to notify
the Host of the buffer overrun.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-09-13 14:17:32 +02:00
Carles Cufi f597c8120e Bluetooth: controller: Add LE Read Chan Map command
Implement the LE Read Channel Map HCI command, along with making the
reading of the multi-byte channel map value from the connection pointer
thread-safe in case the ISR triggers while we are reading the value.

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-25 11:27:22 +02:00
Carles Cufi 9d63dda43a Bluetooth: VS: Replace IRK with IR
The values returned by the controller are Identity Roots and not
Identity Resolving Key. To avoid confusion, and since IRK is commonly
associated with the latter, use "ir" instead.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-17 12:36:51 +02:00
Carles Cufi 16a28bf106 Bluetooth: VS: Add RSSI to Scan Req Received Event
In order to allow for the controller to report the RSSI of a received
Scan Request, include the field inside the Scan Request Received
Vendor-Specific Event.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-17 12:36:51 +02:00
Carles Cufi 01338fd3ed Bluetooth: VS: Fill the Vendor-Specific header with the spec
The Vendor-Specific header file defines the commands and events used to
communicate with a Zephyr Vendor-Specific capable controller from a
Host. Translate the existing specification fully into the header file.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-17 08:30:32 +03:00
David B. Kinder 2c850d7547 doc: fix misspellings in include (API docs)
Fix misspellings in .h files missed during code reviews
and affecting generated API documentation

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-08-10 12:22:19 -04:00
Carles Cufi 868aeeb126 Bluetooth: controller: LE Directed Advertising Report
Implement the 4.2 event LE Directed Advertising Report, used for
scanners in a privacy-enabled controller to report directed advertising
events whose TargetA cannot be resolved by the local controller.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-08-10 12:33:36 +03:00
Johan Hedberg 505c45a7ad Bluetooth: Clean up address related definitions
Fix white-space usage and use a shorter parameter name to avoid line
splits.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 12:51:39 -04:00
Johan Hedberg f4673fa8b6 Bluetooth: Mesh: Fix alignment issue resulting from Kconfig change
The alignment of these defines went a bit off with the shortened
Kconfig variable names.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-08-09 12:49:10 +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
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
Vinayak Kariappa Chettimada 255e5cc344 Bluetooth: controller: Implement Read/Write Auth Payload timeout
Added implementation to support HCI Read Authenticated
Payload Timeout Command and HCI Write Authenticated Payload
Timeout Command.

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

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

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

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

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

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

Jira: ZEP-2360

Change-Id: Ic773113dbfd84878ff8cee7fe2bb948f0ace19ed
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-20 09:30:44 +03:00
Marcel Holtmann aefcf547ad Bluetooth: controller: Add skeleton for vendor HCI commands
Signed-off-by: Marcel Holtmann <marcel.holtmann@intel.com>
2017-07-14 14:54:52 +03:00
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 dd542e14f6 Bluetooth: GATT: Reorder bt_gatt_ccc_cfg to eliminate padding
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-07-04 17:30:40 +03:00
Carles Cufi d990079f15 Bluetooth: controller: Fix HCI remote version structure
The HCI Read Remote Version Information Complete event structure was
incorrect, leading to qualification test failures. This patch fixes the
structure and also the storing of the data in an endianness-agnostic
manner.

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

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

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-07-03 15:43:00 +02:00
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
Luiz Augusto von Dentz 0bdd4db98f Bluetooth: GATT: Fix aligment of bt_gatt_ccc_cfg and _bt_gatt_ccc
During the conversion of uint16_t to u16_t the value field of these
structs was not aligned properly.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-06-21 08:56:00 +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
David B. Kinder 4fe91f7819 doc: fix doxygen errors in bt include files
Misspelled @brief and a couple names were different than
what was in the doxygen comments (generated warnings)

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-06-15 20:20:16 -04: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 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 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
Jaganath Kanakkassery 05af2424b2 Bluetooth: L2CAP: Fix bt_l2cap_chan_send() API doc
This API no longer blocks and if the credits are not available
buf will be queued and will be sent once credits are recieved
from peer.

Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2017-06-14 10:14:22 +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
Luiz Augusto von Dentz 64bf41254f Bluetooth: GATT: Add proper documentation for bt_gatt_notify attribute
Document the expected attribute shall be the Characteristic Value
Descriptor.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-05-30 14:34:11 +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 Chettimada d8307b87b3 Bluetooth: Fix HCI LE Set PHY cmd parameters
Fixed PHY_options parameter in HCI LE Set PHY command to be
2 octets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2017-05-10 07:30:16 +03:00
Vinayak Kariappa Chettimada a7d3b32c17 Bluetooth: Fix PHY related HCI param values
LE Set PHY command parameters take bit numbers, fix
definition values to comply to bit number values.

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
David B. Kinder 1bec7e747c doc: loses misspelling in conn.h
affects doxygen-generated API documentation

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-05-04 19:42:50 -04: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 7ebe7da736 Bluetooth: controller: Controller to Host flow control
The Bluetooth Specification allows for optional Controller to Host flow
control based on the same credit-based mechanism as the Host to
Controller one. This is particularly useful in 2-chip solutions where
the Host and the Controller are connected via a physical link (UART, SPI
or similar) where the Host is sometimes required to ask the Controller
to throttle its data traffic while still making sure that relevant
events get through the line.

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

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

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

Jira: ZEP-1735

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-05-03 22:23:42 +03:00
David B. Kinder fc5f2b3832 doc: spelling check doxygen comments include/
fix misspellings found in doxygen comments used for API docs

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-05-02 22:21:37 -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
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
Johan Hedberg acb872fd8c Bluetooth: HCI: Fix alignment of struct members
This is mostly resulting from the recent change to new integer types.

Change-Id: I16aa4ca645c24d682667985de14687a7dc360b2f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-04-29 11:39:13 -04:00
Andrew Boie cdb94d6425 kernel: add k_panic() and k_oops() APIs
Unlike assertions, these APIs are active at all times. The kernel will
treat these errors in the same way as fatal CPU exceptions. Ultimately,
the policy of what to do with these errors is implemented in
_SysFatalErrorHandler.

If the archtecture supports it, a real CPU exception can be triggered
which will provide a complete register dump and PC value when the
problem occurs. This will provide more helpful information than a fake
exception stack frame (_default_esf) passed to the arch-specific exception
handling code.

Issue: ZEP-843
Change-Id: I8f136905c05bb84772e1c5ed53b8e920d24eb6fd
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-04-22 10:31:49 -04: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
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
Carles Cufi 045f076e5e Bluetooth: Use event masks instead of bits in controller and host
To avoid having to define a BIT64() macro in a public namespace, use
instead masks directly instead of bits, and also refactor the host code
so that it uses those instead of the earlier byte array with hardcoded
indices and masks.

Change-id: Ief03db616a96df65349d24289b62566a268ffdd0
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-20 08:58:09 +03:00
Vinayak Chettimada f860b786a7 Bluetooth: HCI: Add Bluetooth 5.0 FeatureSet field's bit mapping
Add definitions for Bluetooth 5.0 FeatureSet field's bit
mapping. Refer to Bluetooth Specification Version 5.0,
Vol.6, Part B, Section 4.6, Table 4.4.

Change-id: I5069421bf07a31ed9524fbdd02eb44079b1255cb
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
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
Carles Cufi f82e101e20 Bluetooth: HCI: Add Bluetooth 5.0 LE commands and events
Add definitions for all LE commands and events added in the Bluetooth
5.0 specification.

Change-Id: Ia6d134a1ada67e98c803bb6a1708c3f4361c3bfb
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-20 08:58:09 +03: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
Carles Cufi 9a9699ebdb Bluetooth: controller: Implement event masks
HCI event masking allows the host to choose which events are reported to
it to avoid interruption and excessive traffic. This patch implements
masking to drop any non-enabled events as specified by the host.

Jira: ZEP-1769

Change-Id: If09d4aa22b0da8f743fc42a3b0db3f369daaff96
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-04-08 20:11:54 +03:00
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
Johan Hedberg 60e44f6956 Bluetooth: HCI: Add define for success status
Change-Id: I048318094f3eac3e5e705ccc2d3c53512430e960
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
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
Johan Hedberg 94831a7589 Bluetooth: Introduce public big-endian AES API
There may be use cases where input and output is in big-endian rather
than little-endian. Introduce a native big-endian API to avoid
excessive byte order reversals in these cases.

Change-Id: Ia7b3e01bb0a07c4560b23f60c2f615ec614eb431
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-03-21 17:05:42 -07:00
Johan Hedberg 042624fb62 Bluetooth: Move crypto APIs to dedicated header file
This avoids overpopulating the high-level bluetooth.h

Change-Id: Icab8500be92003aa45d837ff111a8d93689865cc
Signed-off-by: Johan Hedberg <johan.hedberg@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
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
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
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
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
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
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 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
Piyush Itankar 160dfdf706 Bluetooth: A2DP: Added Preset Structure
Added structure to account for the preset. The user can use the
SBC codec.

Change-Id: Ia2466b6fc166cae919f82a8042f4dd047ed28772
Signed-off-by: Piyush Itankar <piyush.t.itankar@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
Jonathan Gelie b3ac77becd Bluetooth: GATT: introduce volatile subscription flag
Some application protocol required non-persistente subscription
across connection even in bonded case.
Flag BT_GATT_SUBSCRIBE_FLAG_VOLATILE specify if subscription
must be remove during disonnection.

Change-Id: I1bc2bbbb4bc86f58905e44a7eb267ca0871f2fdb
Signed-off-by: Jonathan Gelie <jonathanx.gelie@intel.com>
2017-02-06 17:43:18 +00:00
Luiz Augusto von Dentz 31016448b4 Bluetooth: GATT: Fix not removing subscriptions safely
The subscriptions callback may free or reuse the subscription so all
instances that where this could happen need to safely fetch the next
element which is why this changes switch to use sys_list_t as it has
SYS_SLIST_FOR_EACH_NODE_SAFE.

Change-Id: I37d51f27116ea0c057b560924a9416676477597b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2017-02-06 11:18:57 +00:00
Johan Hedberg 50678b03cb Bluetooth: Reuse HCI command buffers for the command response
Reduce the pressure on the common RX buffer pool by reusing HCI
command buffers also for the Command Status or Command Complete
response to them. This also implies removing the existing Kconfig
variable for the command buffer sizes since the size is also dependent
on maximum Command Complete event sizes. Instead, reuse the RX buffer
size also for HCI Command buffers.

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

Change-Id: I31d846331939f1a2270df7ed0c75112825e16493
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-02-05 22:39:25 +02:00
Johan Hedberg 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
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 75421e0f53 Bluetooth: uuid: Fix assigned UDP uuid value
Change-Id: Ia004e77af064d24f5d5de7ab02d4bedaeb0bb079
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 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
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
Roger Lendenmann 785415c8ad Bluetooth: add storage flag for secure connection pairing LTK
Change-Id: I521036a7887541f4cc078283fcb400bcdd5c41ef
Signed-off-by: Roger Lendenmann <roger.lendenmann@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
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
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
Johan Hedberg b4e65654a0 Bluetooth: Add __printf_like annotation for bt_log
This helps catch any format string issues when using this API.

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

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

Change-Id: Ie6bc8e10727b5b306f3ed0f94089a07a22583d9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-18 08:28:06 +02:00
Johan Hedberg 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 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
Johan Hedberg 2a3babc67d Bluetooth: Add documentation for connection callbacks
Add proper documentations for all of the callbacks that are part of
the bt_conn_cb struct.

Change-Id: Iabce1d08a84c3849307c436a2cc528edffc62242
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-17 08:44:21 +02:00
Johan Hedberg 91a2f17c23 Bluetooth: ATT: Add new error code from CSSv7
The Core Specification Supplement v7 defines one new ATT error code.

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

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

Change-Id: I53e0ce5155eebc352b84ba41b30ecb9d9958699f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-01-05 08:49:16 +02:00
Jaganath Kanakkassery 51e71ea0fd Bluetooth: RFCOMM: Increase dlc stack size to 256
This analyzes the dlc stack using stack_analyze() which is coming
as 188 with BLUETOOTH_DEBUG_LOG off.

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

So increase the stack size to 256.

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

Also added doxygen comment for connected and disconnected callback.

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

Change-Id: I7b2a89487e2d481391c51201e32b3287808f82dc
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2017-01-05 08:49:16 +02:00
Arkadiusz Lichwa 6d89dd897e Bluetooth: SDP: Queue user UUID to be resolved
Makes possible to append user UUID to context to be able later iterate
it on subsequent resolving process.

Jira: ZEP-1112

Change-Id: I193ff1cee199045c9686dc4ca200adf19db377e4
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-12-24 08:42:15 +02:00
Johan Hedberg 2ee61f1f97 Bluetooth: Move buffer allocation helpers to buf.h
The buf.h header file is a more natural place for these than the
hci_driver.h file.

Change-Id: I1eedcf03ae6ffa374403b382ec665ae554d6847b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Arkadiusz Lichwa a3a59569fb Bluetooth: SDP: Initial SDP client interface API
Adds basic object datatypes and functions as an entry to SDP client
infrastructure.

Jira: ZEP-1112

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

Change-Id: I1e9ca901b693f608d58575916809e8bd8bfe710f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-24 08:42:15 +02:00
Johan Hedberg aefc154811 Bluetooth: GATT: Add BT_GATT_PERM_NONE convenience value
If an attribute has no special access permissions (e.g. it's
notify-only) it would set the permissions to 0. Having a dedicated
enum value for this makes the code a bit more readable.

Change-Id: I0d3d8716a2544379353148735ba29b1a137f7173
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-24 08:42:15 +02:00
Anas Nashif a9e879e273 logging: move sys_log to subsys/logging
Move logging out of misc/ to its own subsystem. Anything related to
logging and any new logging features or backends could be added here
instead of the generic location in misc/ which is overcrowded with
options that are not related to eachother.

Jira: ZEP-1467
Change-Id: If6a3ea625c3a3562a7a61a0ba5fd7e6ca75518ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:39 +00:00
Jaganath Kanakkassery fdf212fa29 Bluetooth: RFCOMM: Fix channel range documentation
RFCOMM channel range is 1 - 30, 0 and 31 shall not be used since
the corresponding DLCIs are reserved in GSM.

Change-Id: I63ff188e06007208b629a3e3bc22681c0bad239b
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-16 10:27:48 +02:00
Arun Jagadish 7f6a059a36 Bluetooth: AVDTP: Add AV-Stream data structure
AV-Stream Data structure added to AVDTP structure.

Change-Id: Icb6ae80e84b49e8a800c99e7f004b43a0fa6c043
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-16 10:27:48 +02:00
Johan Hedberg c3e08c8fea net: buf: Redesigned pool & buffer allocation API
Until now it has been necessary to separately define a k_fifo and
an array of buffers when creating net_buf pools. This has been a bit
of an inconvenience as well as blurred the line of what exactly
constitutes the "pool".

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

	NET_BUF_POOL_DEFINE(pool_name, ...);

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

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

Change-Id: Id91b1e5c2be2deb1274dde47f5edebfe29af383a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-13 21:41:53 +00:00
Johan Hedberg fb37a5c330 Bluetooth: Fix stack overhead amount when debug is enabled
After some more careful measurements, the worst measured overhead is
288 bytes. Adjust BT_STACK_DEBUG_EXTRA correspondingly to 300 (to give
a bit of playroom still on top of this).

Change-Id: Icdf477b05b40917027314b180c2b69c8c6c759b3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 12:57:37 +00:00
Johan Hedberg f85878146a Bluetooth: Fix BT_STACK_DEBUG_EXTRA for BLUETOOTH_DEBUG_LOG
BT_STACK_DEBUG_EXTRA was adjusted by commit 047c6eacf7,
however it failed to cover this #ifdef section in log.h.

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

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

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

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

Change-Id: Ie4fa3bd8f6b279fee6fb56ddce198d82c5047849
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-12-09 06:52:56 +00:00
Johan Hedberg 047c6eacf7 Bluetooth: Fine-tune debug-based stack size increase
Now that printk is the default backend for logging the overhead is not
as bad as with printf. 160 seems to be roughly the worst case amount
of overhead that debug logs now cause.

Change-Id: Ia5937b7318e00cc31c72fa1702c73a57bca0603a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Johan Hedberg b94a69e346 Bluetooth: Fix format specifier in address helpers
Instead of %2.2x we should use %02x since printk doesn't (currently)
support the former.

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

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

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

Change-Id: I7c6437051f0b2d1f5f79e19b2616bb643ae6300b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-09 08:18:24 +02:00
Szymon Janc a7e746047f Bluetooth: Account K_THREAD_SIZEOF in BT_STACK macros
This makes BT_STACK_* macros to account K_THREAD_SIZEOF overhead of
thread. This make it easier for developer as he only needs to care
about size needed by his own code. Also size reported by stack_analyze
now match what was passed to BT_STACK macro.

Without this patch we were pretty close to stack overflow on x86:
ecc stack (real size 1280):     unused 52       usage 1164 / 1216 (95 %)
rx stack (real size 1024):      unused 44       usage 916 / 960 (95 %)
cmd tx stack (real size 256):   unused 16       usage 176 / 192 (91 %)
conn tx stack (real size 256):  unused 4        usage 188 / 192 (97 %)

With this patch stacks have reasonable utilizations:
ecc stack (real size 1344):     unused 112      usage 1168 / 1280 (91 %)
rx stack (real size 1088):      unused 108      usage 916 / 1024 (89 %)
cmd tx stack (real size 320):   unused 80       usage 176 / 256 (68 %)
conn tx stack (real size 320):  unused 68       usage 188 / 256 (73 %)

Change-Id: I9d9c49fab5a455ffc6b96bc75d5afadcabc6dc79
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-12-03 17:09:38 +00:00
Arun Jagadish 6f3c4bf425 Bluetooth: AVDTP: SEP Definition
Added
SEP structure
SEP Registration function

Change-Id: Ib8c4a1753c85390009c154a50a1a1a2f2794e8a2
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-12-03 17:09:38 +00:00
Luiz Augusto von Dentz 58a2b3df7c Bluetooth: GATT: Fix using out of scope variable
This fixes defect found by coverity: 152027 Pointer to local outside
scope.

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

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

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

Jira: ZEP-1246

Change-Id: Id76d8fedb5ecaf0001c8429cf22f9a3e2c910a44
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-11-18 07:47:50 +02:00
Johan Hedberg d9be4ab740 Bluetooth: log: Fix usage of legacy APIs
Use k_current_get() instead of the deprecated sys_thread_self_get()
API.

Change-Id: I4ddb45f299373237690b2f4ca614e7fd3b6c0c36
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-12 12:50:04 +02:00
Luiz Augusto von Dentz b3cece0af1 Bluetooth: L2CAP: Fix using nano_delayed_work API
This fixes warnings related to the use of nano_work and
nano_delayed_work in L2CAP layer.

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

Change-Id: I1e3bd7857248865e34a313dd42862af5f4e3805b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-11 07:59:15 +02:00
Szymon Janc 47eaaf9f96 Bluetooth: Use unified k_fifo API for FIFOs
Change-Id: I6ddc24575e4bf3c3040945a2bdb62f153b15cdb3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-11 07:59:15 +02:00
Jaganath Kanakkassery 00457636f8 Bluetooth: RFCOMM: Initiate session connection
This patch introduces the Connect API which initiates session
connection first. If session is already there with the peer
then it has to reuse it and initiate DLC (which will be done
in the subsequent patch) since there can be only one session
per device.

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

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

Change-Id: I9828e0f3b3ea43bb17df95f0536e15df86f1b4be
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-11 07:59:15 +02:00
Johan Hedberg 195e1b89b1 Bluetooth: Fix usage of C++ reserved word
'private' is a C++ reserved word and will lead to compilation errors:

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

Change-Id: I36aef5a84af4fc66e1c810bd0c56e5ab5f803294
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8f800a8bfe Bluetooth: Use unified k_sem API for semaphores
Change-Id: I0099c837cc8ad67b8f927b2debd771acfe626eea
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 807bd5fec8 Bluetooth: L2CAP: Handle LE connection response security errors
If there are security errors bump the security of the connection and
retry:

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

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

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

These changes are basically done to make it more readable

Change-Id: Ic15e93465b0afbd19d8805f27d7a43f34ef38689
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 3eb04280ed Bluetooth: Rename BT_SECURITY_ZERO to BT_SECURITY_NONE
Even though this is level 0, NONE as a symbolic description is more in
line with the other level names.

Change-Id: Ic9d7c38b928d8744d47e759fae804bbbc08c89bf
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-01 21:40:39 +02:00
Johan Hedberg 9dc033cb84 Bluetooth: Add handling for security level 0
So far bt_security_t has completely missed out on security level 0,
i.e. its actual values have been one lower than in the core
specification.

To properly introduce for the new level (which is only applicable for
BR/EDR) add proper tracking for each channel and server, and make the
channels inherit their required level from the respective server.

Change-Id: I9a2384d883017125c2c117880aa6e0ade30520e4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-01 21:40:39 +02:00
Luiz Augusto von Dentz 07c8be1791 Bluetooth: ATT: Rework buffer pools to minimize extra data
This uses net_buf_simple_{save/restore} so the same buffer can be reused
if the buffer needs to be resent, also since the responses don't need to
be saved a pool with 1 element is enough while it keeps the code safe
from deadlocking when both request and responses use the same pool.

Change-Id: Ibaa8e7ef39f4b466d5cd4d55874bd609f0a1d67c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-01 21:40:39 +02:00
Johan Hedberg 079030718f Bluetooth: Move hci_driver.h to include/drivers/bluetooth
This header file is not intended for applications, rather than for
drivers, so move it to the appropriate place.

Change-Id: I7ff8158418e7e839b538c6cccbb32f3af43c12c6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-01 21:40:39 +02:00
Johan Hedberg 4a3db55a54 Bluetooth: Fix license header in l2cap.h and rfcomm.h
The header was always supposed to be Apache 2 and not 3-Clause BSD.

Change-Id: I82f319edfc7a76323b2b409fadc90e270d7f1cad
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-28 13:16:39 +03:00
Johan Hedberg 6989bf88e1 Bluetooth: Rename bt_driver to bt_hci_driver
The bt_driver API was created when Zephyr only had a Bluetooth host
stack, but no controller-side functionality. The only "driver" that
was needed for the host was the HCI driver, and hence "HCI" was
omitted from the name.

With support both for host and controller Zephyr will be getting more
Bluetooth driver types, in particular radio drivers. To prepare for
this, move all HCI drivers to drivers/bluetooth/hci/ and rename the
bt_driver API bt_hci_driver.

Change-Id: I82829da80aa61f26c2bb2005380f1e88d069ac7d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-28 08:09:08 +03:00
Carles Cufi 86912a5e83 Bluetooth: HCI: Remove "EDR" and "HS" marketing terms from macros
Remove "EDR" and "HS" postfixes from the version names, since
those are only relevant from a marketing point of view, and
not at all for HCI compatibility purposes.

Change-Id: Id8b4b010ed8b80dd63898c4baf85062e51b2635a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-28 08:09:08 +03:00
Carles Cufi 40b8ea136a Bluetooth: Controller: Set HCI version to 4.2
Report the HCI version supported by the Controller as 4.2,
since it was set as 0 (1.0b) and this confused certain Host
implementations, such as BlueZ.

Change-Id: I809721ee9c2b55e77e6a3ca63688c802a9ffa0ba
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-10-28 08:09:08 +03:00
Kaustav Dey Biswas 0ecbbc8a7b Bluetooth: SDP: Shorten Service Class macro name
This change shortens the Service Class macro name from
BT_SDP_*_SVCLASS_ID to BT_SDP_*_SVCLASS

Change-Id: I1150baae24428c6b76f005d11003291016e0a03e
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-21 07:47:31 +03:00
Kaustav Dey Biswas 148b0a2d35 Bluetooth: shell: Add sample SDP service registration
This change adds SPP as a sample SDP service during RFCOMM
server registration. The SPP channel is now used as the
fixed channel for RFCOMM register command.

Change-Id: I3b5ad3995725adca55db1497d4a35099f6311f3b
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-21 07:47:31 +03:00
Jaganath Kanakkassery 96c1169e4d Bluetooth: RFCOMM: Handle security for incoming connections
Added required_sec_level in dlc struct so that user can set it.
If current security level is greater than or equal to the
required security level then connection will be accepted right
away, otherwise security elevation will be reqiested and connection
will be accepted once it is done.

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Set Async Balance Mode (SABM) (0x2f)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x3f poll/final 1
         Length: 0
         FCS: 0x59
< HCI Command: Authentication Requested (0x01|0x0011) plen 2
        Handle: 256
> HCI Event: Command Status (0x0f) plen 4
      Authentication Requested (0x01|0x0011) ncmd 1
        Status: Success (0x00)
> HCI Event: Link Key Request (0x17) plen 6
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
< HCI Command: Link Key Request Negative Reply (0x01|0x000c) plen 6
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
> HCI Event: Command Complete (0x0e) plen 10
      Link Key Request Negative Reply (0x01|0x000c) ncmd 1
        Status: Success (0x00)
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
> HCI Event: IO Capability Request (0x31) plen 6
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
< HCI Command: IO Capability Request Reply (0x01|0x002b) plen 9
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
        IO capability: DisplayYesNo (0x01)
        OOB data: Authentication data not present (0x00)
        Authentication: Dedicated Bonding - MITM required (0x03)
> HCI Event: Command Complete (0x0e) plen 10
      IO Capability Request Reply (0x01|0x002b) ncmd 1
        Status: Success (0x00)
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
> HCI Event: IO Capability Response (0x32) plen 9
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
        IO capability: DisplayYesNo (0x01)
        OOB data: Authentication data not present (0x00)
        Authentication: Dedicated Bonding - MITM required (0x03)
> HCI Event: User Confirmation Request (0x33) plen 10
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
        Passkey: 104251
< HCI Command: User Confirmation Request Reply (0x01|0x002c) plen 6
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
> HCI Event: Command Complete (0x0e) plen 10
      User Confirmation Request Reply (0x01|0x002c) ncmd 1
        Status: Success (0x00)
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
> HCI Event: Simple Pairing Complete (0x36) plen 7
        Status: Success (0x00)
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
> HCI Event: Link Key Notification (0x18) plen 23
        Address: A0:A8:CD:40:99:98 (OUI A0-A8-CD)
        Link key: 7c5e5bbc67268293202913902fd0d5fe
        Key type: Authenticated Combination key from P-192 (0x05)
> HCI Event: Auth Complete (0x06) plen 3
        Status: Success (0x00)
        Handle: 256
> HCI Event: Encryption Key Refresh Complete (0x30) plen 3
        Status: Success (0x00)
        Handle: 256
< HCI Command: Set Connection Encryption (0x01|0x0013) plen 3
        Handle: 256
        Encryption: Enabled (0x01)
> HCI Event: Command Status (0x0f) plen 4
      Set Connection Encryption (0x01|0x0013) ncmd 1
        Status: Success (0x00)
> HCI Event: Encryption Change (0x08) plen 4
        Status: Success (0x00)
        Handle: 256
        Encryption: Enabled with E0 (0x01)
< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x92

Change-Id: Ia01f2984dda77d58b724f869eb526734f1846ad6
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-21 07:47:31 +03:00
Kaustav Dey Biswas de58e096dd Bluetooth: SDP: Server: Support service record registration
This change adds support for registering new service records.

Change-Id: I0ff2264d08787fe5f8edf6300259961c3ca52fbb
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-21 07:47:31 +03:00
Kaustav Dey Biswas 1a1843d738 Bluetooth: UUID: Add protocol UUIDs
Add Bluetooth protocol UUIDs to be used in SDP service records

Change-Id: I184cc114ff3fa172d9caa23d0b243a3191bb9773
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-21 07:47:31 +03:00
Kaustav Dey Biswas 773c097829 Bluetooth: UUID: Fix alignment of UUID declarations
Change-Id: I77d6466cb47cbe41b67b728d4eb7b0346ef80a9a
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-21 07:47:31 +03:00
Luiz Augusto von Dentz ee9f5c1784 Bluetooth: GATT: Pass CCC attribute to changed callback
This way the application can reuse the same callback for multiple CCC
since it can track what CCC is affect by checking the attribute pointer.

Change-Id: I608da643aea07de26b65d67e6db3268d717d0f53
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-21 07:47:31 +03:00
Roger Lendenmann c839f76e3f Bluetooth: Add well known keys to storage API for legacy pairing
The keys BT_STORAGE_SLAVE_LTK, BT_STORAGE_LTK, BT_STORAGE_IRK allow to store
the distributed bonding keys for ble legacy pairing.

Change-Id: Iaee8b78456e9865a53a2f1228b6afa7ff44bc4db
Signed-off-by: Roger Lendenmann <roger.lendenmann@intel.com>
2016-10-16 09:01:28 +03:00
Szymon Janc 2caa5f1442 Bluetooth: Track role change for BR/EDR connections
This make sure conn object is using correct role.

< HCI Command: Create Connection (0x01|0x0005) plen 13
        Address: 20:68:9D:60:A1:E4 (Liteon Technology Corporation)
        Packet type: 0xcc18
          DM1 may be used
          DH1 may be used
          DM3 may be used
          DH3 may be used
          DM5 may be used
          DH5 may be used
        Page scan repetition mode: R2 (0x02)
        Page scan mode: Mandatory (0x00)
        Clock offset: 0x0000
        Role switch: Allow slave (0x01)
> HCI Event: Command Status (0x0f) plen 4
      Create Connection (0x01|0x0005) ncmd 1
        Status: Success (0x00)
> HCI Event: Role Change (0x12) plen 8
        Status: Success (0x00)
        Address: 20:68:9D:60:A1:E4 (Liteon Technology Corporation)
        Role: Slave (0x01)
> HCI Event: Connect Complete (0x03) plen 11
        Status: Success (0x00)
        Handle: 11
        Address: 20:68:9D:60:A1:E4 (Liteon Technology Corporation)
        Link type: ACL (0x01)

Change-Id: I65cd8ba36f0e5317d79d7e4d884ee530e1f8b2a3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-16 09:00:57 +03:00
Itankar, Piyush T 5bdaa5ae31 Bluetooth: HCI: Add OpCode definition for setting page timeout
Added a OpCode definition that can be used to change the Page
timeout value.

Change-Id: I6ec06f6114f75665b161206ef3ebabbab193b04f
Signed-off-by: Itankar, Piyush T <piyush.t.itankar@intel.com>
2016-10-16 09:00:57 +03:00
Johan Hedberg 5c64037461 Bluetooth: Add BT_STORAGE_ADDRESSES key to storage API
The list of remote devices for which we have information stored can be
retrieved using this key.

Change-Id: I1476c40177b631d6b2b4049623052245b25ed1b3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-16 09:00:57 +03:00
Johan Hedberg e4f2df013a Bluetooth: Improve storage API documentation
Add missing documentation to storage API.

Change-Id: I17903d75c6b4332e4f9596175587f0068e352b9a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-16 09:00:57 +03:00
Johan Hedberg 7d0eef5f96 Bluetooth: Use proper const type for bt_storage_clear()
The bt_storage_clear() function doesn't modify the data behind the
addr parameter, so the pointer should be decared const.

Change-Id: Icce676f9df80bac26ba4877bb63752559a43339f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-16 09:00:57 +03:00
Arkadiusz Lichwa f30b3debc6 Bluetooth: Refactor distribution of security procedure status
Layers (modules) above HCI like L2CAP need to know status of applied
security procedure when it's triggered on existing connection. It gives
them possibility to make action in layer specific context on
post-security-procedure conditions.

Change-Id: Ia10078469847b29bb7eb3b1fb376ac305dd0b0fc
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 15:15:40 +00:00
Johan Hedberg a8de2de1f2 Bluetooth: Fix compiler warnings/errors related to string casts
Fix the following compiler warnings/errors that show up with llvm:

    tests/bluetooth/shell/src/main.c:594:2: error:
          initializing 'const uint8_t *' (aka 'const unsigned char *') with an
          expression of type 'char [11]' converts between pointers to integer types
          with different sign [-Werror,-Wpointer-sign]
            BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/bluetooth/bluetooth.h:93:11: note: expanded
          from macro 'BT_DATA'
                    .data = (_data), \
                            ^~~~~~~
    1 error generated.
    net/bluetooth/hci_core.c:1759:22: error: passing
          'uint8_t [248]' to parameter of type 'const char *' converts between
          pointers to integer types with different sign [-Werror,-Wpointer-sign]
                            name_len = strlen(evt->name);
                                              ^~~~~~~~~
    lib/libc/minimal/include/string.h:32:34: note: passing
          argument to parameter 's' here
    extern size_t strlen(const char *s);
                                     ^
      CC      net/bluetooth/log.o
    net/bluetooth/hci_core.c:3136:10: error: passing
          'uint8_t [248]' to parameter of type 'char *' converts between pointers to
          integer types with different sign [-Werror,-Wpointer-sign]
            strncpy(name_cp->local_name, CONFIG_BLUETOOTH_BREDR_NAME,
                    ^~~~~~~~~~~~~~~~~~~
    lib/libc/minimal/include/string.h:30:39: note: passing
          argument to parameter 'd' here
    extern char  *strncpy(char *_Restrict d, const char *_Restrict s, size_t n);
    net/bluetooth/conn.c:301:10: error: passing
          'uint8_t [16]' to parameter of type 'char *' converts between pointers to
          integer types with different sign [-Werror,-Wpointer-sign]
            strncpy(cp->pin_code, pin, sizeof(cp->pin_code));
                    ^~~~~~~~~~~~
    lib/libc/minimal/include/string.h:30:39: note: passing
          argument to parameter 'd' here
    extern char  *strncpy(char *_Restrict d, const char *_Restrict s, size_t n);

Change-Id: I342131c6c2b25445382b2317d673561c4087096b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 12:44:24 +00:00
Itankar, Piyush T 76947d7fe6 Bluetooth: A2DP: Added Connect API
API Implemented Connect API. This can be used to establish A2DP connection.

Change-Id: I8cf714283a452c40b33fd46de442514a1341264c
Signed-off-by: Itankar, Piyush T <piyush.t.itankar@intel.com>
2016-10-04 10:55:04 +00:00
Johan Hedberg 9adfb4af17 Bluetooth: RFCOMM: Fix some remaining white-space issues
Change-Id: I56f3ffc9dc9dd18ff204224d1a3166f9dbdc4c3f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 08:12:14 +03:00
Johan Hedberg ea5576145a Bluetooth: RFCOMM: Remove reference counting
The reference counting has been an internal trick to handle the TX
fiber, but it's not really needed since we can do the same thing with
the help of the state value.

Change-Id: I9cdaed9afb0b0c07e23d599637328cb863c123b3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 08:12:14 +03:00
Jaganath Kanakkassery 7fb0894565 Bluetooth: RFCOMM: Introduce dlc destroy
dlc will be destroyed when ref count reaches 0.
This also moves calling user disconnected callback to destroy
since disocnneted callback will be called whenever dlc is
destroyed regardless of dlc previously been in connected state
or not.

Change-Id: I4a13f8118704c59a88923b74e538063c0db11d77
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-04 08:12:14 +03:00
Kaustav Dey Biswas ab30160708 Bluetooth: SDP: Server: Initialize and accept incoming connections
Initialize SDP, register to L2CAP and accept incoming connections

Change-Id: I568db63910d9e6ff418581b9943d528d4260b859
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-04 08:12:14 +03:00
Szymon Janc 7ea426a8f1 Bluetooth: L2CAP: Cleanup flags names for BR/EDR channels
This makes all flags used for BR/EDR L2CAP be stored in single place.
Connection oriented flags and signaling flags are now sharing same
atomic.

Change-Id: If01b29009f9c60ed529338122992b9b5e31f883a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-04 08:12:14 +03:00
Szymon Janc 85195d2d2e Bluetooth: Add support for reading encryption key size for BR/EDR
Make use of "Read Encryption Key Size" HCI command to read real
encryption key size for BR/EDR connection instead of assuming 16
bytes key size.

< HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2
        Handle: 11
> HCI Event: Command Complete (0x0e) plen 7
      Read Encryption Key Size (0x05|0x0008) ncmd 1
        Status: Success (0x00)
        Handle: 11
        Key size: 16

Change-Id: I372028ce73115d34aedbb6b5ce420144844cfce0
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:01:55 +00:00
Carles Cufi 77c389aa1c Bluetooth: HCI: Add read remote version info event
This adds the Read Remote Version Info Complete event,
used in both BR/EDR and LE and required by the LE Controller.

Change-Id: I650411ef2c582c20a90eb73bc4475b5e2d4aa2d9
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 10cd9e31f3 Bluetooth: HCI: Add auth payload expiry event
This adds the Authenticated Payload Timeout expired event,
used in both BR/EDR and LE and required by the LE Controller.

Change-Id: Ifbbccea6d44a7d432734090e56cbf4e7189362b0
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 4392d6d737 Bluetooth: HCI: Fix and extend advertising report events
The advertising report (standard or direct) events require
a number of reports field that is used by the controller
to fill in the structure.
At the same time this fixes the subevent code of the direct
advertising report structure.

Change-Id: I0fdb9b1dcad03615ac9b3f1f38fdfbe9ab3f9c3a
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Sathish Narasimman 9738e83285 Bluetooth: HFP HF: Initialize Handsfree profile
Initialize Handsfree profile for HF Role and register RFCOMM server
channel number to the RFCOMM. And also exposes some basic callbacks
which is required for the application.

Change-Id: Ic79cbd66ef9529c4eb134cc21efcdbc388bb707d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-09-14 08:45:45 +03:00
Sukumar Ghorai 17117f306a Bluetooth: Pre-allocated RFCOMM Channels
Limited number of RFCOMM channels(1-31). Pre-allocated
for profile use and to avoid conflicts.

Change-Id: Ibd081435cf927aa7386161710e48b7371d20af24
Signed-off-by: Sukumar Ghorai <sukumar.ghorai@intel.com>
2016-09-14 08:45:45 +03:00
Vinayak Chettimada feb342140a Bluetooth: log: Include nanokernel.h to use BT_ASSERT()
_SysFatalErrorHandler referenced in BT_ASSERT() is arch
defined. Include nanokernel.h in bluetooth/log.h to include
the necessary arch definitions, as required.

Change-id: Ia39690d2a49db0c9db669a68147fe410abb4213b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Vinayak Chettimada 4a4b76afbc Bluetooth: log: Call _SysFatalErrorHandler in BT_ASSERT()
Change-id: I0cd55426b4dbae0cc95b6b6b57fcf1a02c9103b4
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi ca4b5b93d8 Bluetooth: HCI: Add handle to conn param update command complete
The BT_HCI_OP_LE_CONN_PARAM_REQ_REPLY and
BT_HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY command complete events contain
a connection handle that serves to match the command with their
corresponding command complete event when there's more than one
pending. For now this just adds the structure definitions required,
and later on code will need to be added to handle possible mismatches.

Change-Id: I4585888b32ec995b18847c2a6ed488a2da9c8520
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 102aee8f55 Bluetooth: HCI: Add handle to LTK command complete events
The BT_HCI_OP_LE_LTK_REQ_REPLY and BT_HCI_OP_LE_LTK_REQ_NEG_REPLY
command complete events contain a connection handle that serves to
match the command with their corresponding command complete event
when there's more than one pending. For now this just adds the
structure definitions required, and later on code will need to
be added to handle possible mismatches.

Change-Id: I37e88070bc0d4d1b80f085f7e162c30715a82103
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Carles Cufi 80d1fba9e9 Bluetooth: HCI: Fix the length of supported commands
The length of the commands array in the return parameters of
the HCI Read Local Supported Commands event is 64 bytes
according to the spec. This was mistakenly set as 36 bytes due
to the fact that only 36 out of the 64 bytes currently contain
meaningful data. The actual array as received from the driver
will always be 64 bytes however, and is therefore sized
accordingly.

Change-Id: Iee7f1fc18045dff96efcc808fd81661eced37b03
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-14 08:45:45 +03:00
Jaganath Kanakkassery 2df4bf6237 Bluetooth: RFCOMM: Implement TX flow control
Data sent by user will be queued in a FIFO. A TX fiber will be
started for each DLC which process this FIFO and write to L2CAP.
Fiber will sleep in two scenarios - no buffer in FIFO, no TX
credit. Credit is handled using semaphore. So if credit is 0
then fiber will wait on semaphore and will be scheduled when
it receives credit.

Change-Id: Id6e796eed594b28d6fb6e4259d3ed52634db9335
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 07:22:32 +00:00
Carles Cufi 0762a5c744 Bluetooth: HCI: Add definitions and macros
Add multiple definitions and macros required by the
controller's HCI layer.

Jira: ZEP-726

Change-Id: I2d4ce0a740495613128092c56ee1b16a232bb076
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Carles Cufi 49583b10d0 Bluetooth: HCI: Rename cmd complete struct
For consistency, add the bt_ prefix to
hci_evt_cmd_complete.

Jira: ZEP-726

Change-Id: I0deb9f12913991bf52ccffc8c85b86c83da1c045
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Kaustav Dey Biswas 68e58af67e Bluetooth: UUID: Add 32bit UUID support
This adds helper support for handling 32bit UUIDs

Change-Id: I4874b5f092bdbe30039b8031485bf856e4268f2a
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-09-07 08:17:26 +03:00
Vinayak Chettimada 1553ccc492 Bluetooth: Add LE read supported states
To fully support BT Spec. v4.2 LE Topology use LE read supported
states HCI command to find the supported states in the
controller.

Change-id: I6b4cf4cbefdff44e51bb0a4242e0aef3755f43db
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Luiz Augusto von Dentz 76773c2ff4 Bluetooth: UUID: Add HID Service
This adds UUIDs related to HID Service as defined in the assigned
numbers.

Change-Id: I73e8659546587aa9330bcd7d483bc097448e5ced
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-09-07 08:17:26 +03:00
Jaganath Kanakkassery 623ce45fc9 Bluetooth: RFCOMM: Remove BT_RFCOMM_SEND_RESERVE
Profiles should use bt_rfcomm_create_pdu() hereafter.

Change-Id: I2fcbbd910005ec5b7b8d75ca452a63c21e6964ea
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 08:17:26 +03:00
Jaganath Kanakkassery 6198f07637 Bluetooth: RFCOMM: Introduce helper to create rfcomm pdu
Profiles can use this helper to create buffer which reserves the
headroom for rfcomm, l2cap and acl headers

Change-Id: I22f97b54423d66fe0c133a8e9903b652fb6a6854
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 08:17:26 +03:00
Carles Cufi 341f5c9c5e Bluetooth: Cleanup and extend HCI header
In preparation for the unification of the code in:
drivers/bluetooth/controller/hci
with the existing HCI definitions in Zephyr,
this change addresses both the required usage of spaces
in the alignment of line components that require matching
the alignment of other adjacent lines and also adds all
missing Bluetooth 4.2 LE commands and events so that the
controller code can make use of them.

Jira: ZEP-726

Change-Id: Iabcee6898a09ddaf4479cfe4ecb0eedc194da8a3
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-09-07 08:17:26 +03:00
Johan Hedberg 50318d2e4f Bluetooth: Clean up feature test macros
The lmp_*_capable() macros were neither following the appropriate name
space (BT_*) nor the appropriate style (macros should be upper-case).
Introduce a new BT_FEAT_TEST() macro which gives a clearer mapping to
the feature tables found in the core specification. Each specific
feature test macro is now also named with the appropriate BT_FEAT_*
prefix.

Change-Id: Ia6b18b066927908f9bda646e737e63d46a1d17df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-07 08:17:26 +03:00
Johan Hedberg 00eda80c59 Bluetooth: Make lmp_ext_feat_capable() more generic
Make is possible to use lmp_ext_feat_capable() both for local as well
as remote features.

Change-Id: I05bb6a25303c0dd2f5e0bbc4f7f412210f668aa3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-07 08:17:26 +03:00
Szymon Janc 29cbaa864d Bluetooth: Enable Secure Connections if supported
Enable BR/EDR Secure Connections if Write Secure Connections Host
Support Command is supported in controller.

Change-Id: Ic0c989217be3cd95e5c0ce1ae2b18d3557c774b8
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-07 08:17:26 +03:00
Szymon Janc a5ab11708e Bluetooth: Read local extended features on init
Use Read Local Extended Features command to read local features and
extended local features on init.

Change-Id: I4c8594783895f439af36214881aeff24e116e783
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-07 08:17:26 +03:00
Arkadiusz Lichwa b082216e2f Bluetooth: L2CAP: Implement connect command on BR/EDR
Adds functionality to do connect to remote PSM. Connecting to remote
PSM other than SDP when both support SSP involves raising security
to at least BT_SECURITY_MEDIUM before any CoC traffic on L2CAP layer.
If connection response is send back with status 'pending' it means
remote doing additional job, so restarts RTX timer. If the command
timer is fired detach the apps channel from connection and make it
ready for reuse.

Change-Id: I81f57bc2f5738754f872ce52cb25027db6db5ccf
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-09-07 08:17:26 +03:00
Jaganath Kanakkassery f598f3f3f6 Bluetooth: RFCOMM: Implement send data API
Sends the data to l2cap after adding rfcomm header. Profile should
reserve the head room for rfcomm, l2cap and hci headers. Data length
should not be more than dlc mtu.

Flow control is not included in this patch

< ACL Data TX: Handle 256 flags 0x00 dlen 38
      Channel: 64 len 34 [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: 30
         FCS: 0x40
        ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
        ff ff ff ff ff ff ff ff ff ff ff ff ff ff 40

Change-Id: Ib97dbf85e236a5f75fda6037bb75bc6be00b9dc7
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 08:17:26 +03:00
Luiz Augusto von Dentz 50997f2ccd Bluetooth: GATT: Add queuing support
This adds queueing support for requests that requires a response making
it simpler to use the API. The storage is keep in the parameters of the
request so it is up to the application to define how many can be queued
but in case the application don't want a request to block waiting for
a buffer it can use BLUETOOTH_ATT_REQ_COUNT to control the available
buffers which is recommended in case the requests will be sent from the
RX fiber.

Change-Id: I407c3982a7ecdc4a9eff7172d9d0addd46949783
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-09-07 08:17:26 +03:00
Jaganath Kanakkassery ab96eae52d Bluetooth: RFCOMM: Handle PN request
PN (Parameter negotiation) is used to negotiate parameters like mtu.
Initial credit for flow control is also sent in PN. If the dlci to which
PN requested is not found in the dlc list then it will be treated as
incoming dlc request and accept callback will be called to profile.
Dlc mtu has to be set by profile (before it returns dlc) which will be
negotiated with remote. But the final mtu will be min of mtu provided
by profile, mtu sent by remote, and session mtu

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

Change-Id: Ifd466db6b3b868d04e38db02ebad6e47ab2da030
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 08:17:26 +03:00
Johan Hedberg d0504ffc34 Bluetooth: Add missing guards to hci_raw.h header file
Each public header file needs the #ifdef guards as well as a
declaration for C++ compatibility.

Change-Id: If270de1ee74e2e74eab02d218417d80fcbf422ac
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-07 08:17:26 +03:00
Andrei Emeltchenko 2b12ca875f Bluetooth: Add documentation to HCI RAW interface
Describe bt_enable_raw() and bt_send() functions.

Change-Id: I0eb18dd2364eec0eb2a8c3e7b537d87e984dd90e
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-09-07 08:17:26 +03:00
Andrei Emeltchenko 6ab1b9cdc4 Bluetooth: Add RAW API interface to Bluetooth
HCI RAW channel API is intended to expose HCI interface to the remote
entity. The local Bluetooth controller gets owned by the remote entity
and host Bluetooth stack is not used. RAW API provides direct access
to packets which are sent and received by Bluetooth HCI drivers.

Change-Id: I4ba2b7ca2c2b0d6c5de6ef1f231d1c5b82125e09
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-09-07 08:17:26 +03:00
Szymon Janc 017586707e Bluetooth: Set BR/EDR device name on init
This adds support for setting default BR/EDR name on init. For now
this is just static configuration but can be extended later on
to allow runtime configuration if requested.

< HCI Command: Write Local Name (0x03|0x0013) plen 248
        Name: Zephyr
> HCI Event: Command Complete (0x0e) plen 4
      Write Local Name (0x03|0x0013) ncmd 1
        Status: Success (0x00)

Change-Id: I59ecfc2be8e55c6f90cdb0f12c6fed7f7ce976f8
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-07 08:17:26 +03:00
Jaganath Kanakkassery 7859ffeab0 Bluetooth: RFCOMM: Implement Register Server channel API
Profiles can use this API to register the RFCOMM server channel.
DLC structure which represents individual connnection on a particular
server channel has to be defined in the profile and provide it in
accept callback.

Change-Id: I14e607ca65a29f29389deb2ac5d0658f5cd92883
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 08:17:26 +03:00
Arkadiusz Lichwa cfcb1d20c4 Bluetooth: L2CAP: Make common RTX commands timer
There's a need to add timeout support for control commands on BR/EDR
transport. So far RTX timer feature has application to control protocols
only on LE. Here 'rtx_work' member is moved to common L2CAP context to
safe memory footprint and prepare L2CAP layer to handle RTX timeout
in BR/EDR context.

Change-Id: I9938268a5c4e5dd1f980bb3ec8697d0209c24065
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-09-07 08:17:26 +03:00
Arkadiusz Lichwa ea5449dbcc Bluetooth: L2CAP: Add BR/EDR CoC channel disconnect
Implements CoC channel disconnect API initiated from local and handles
response to the disconnect request from remote.

Change-Id: I25f2495404cd405dc83ad56269e4897e53d602e6
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-25 14:24:04 +00:00
Arkadiusz Lichwa 96e68fe654 Bluetooth: L2CAP: Introduce security requirements on CoC
Applies on L2CAP channel object security requirement member and
implements on BR/EDR transport basic security cases during incoming
CoC connection request. Since channel security requirements can involve
sending 2 separate connection responses with proper results depending on
context path, there's a need to store L2CAP signaling identifier set in
original connection request to be restored later to help match proper
response context.

Change-Id: Ibac9a5d2443f2975637e1bd15f61afcad53f843b
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-25 13:56:08 +00:00
Luiz Augusto von Dentz c6071e46da Bluetooth: GATT: Fix bt_gatt_exchange_mtu documentation
bt_gatt_exchange_mtu does actually return an int, also change the align
the description properly so it is consistent with other functions.

Change-Id: I6a0780830e13ded15e6262a46094441a2ef662c8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-25 16:08:52 +03:00
Szymon Janc d2549115ca Bluetooth: Rename connectable_addr member in struct bt_le_oob
Depending on advertising options this can be non-connectable address.
NFC pairing application document also allows broadcaster/observer
roles.

Change-Id: I9b104ac8fb9752a083a7a31fc20598c66f23f608
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-07-22 13:09:30 +02:00
Arkadiusz Lichwa d5a07edde0 Bluetooth: L2CAP: Refactor channel context by ident
Moves 'ident' member so far included in bt_l2cap_le_chan context only
to common bt_l2cap_chan context. The change is driven by sharing ability
to store/restore 'ident' on both transports and makes use of it only if
CoC is configured. For default configuration there's channel addition
helper to be used internally by dedicated macros managing channel
objects enlisted in connection tracker list.
The common member is used in matching outstanding connection responses
on LE and to prepare a ground for BR/EDR transport context when
there'll be a need to match response to original incoming connection
request after in-between security changes that can happen.

Change-Id: I1a4cad7cd53c74774604a0e9794607081a8b6e80
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-22 09:20:20 +00:00
Szymon Janc c6bcb591f6 Bluetooth: Add initial support for OOB data
This allows to query information needed for Out Of Band pairing
or connection creation. Currently supports only BT addresses.

Change-Id: I60bf9344baee552e7743fa8fc1b3cfb3a4765334
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-07-20 20:20:44 +02:00
Johan Hedberg 211ae314e8 Bluetooth: Pass net_buf_simple to scan callback
This lets the callback take advantage of the powerful net_buf API for
parsing the advertising data content.

Change-Id: Id65e6e83efd60c0f36c47bc5446a2e8ec2833d7c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-20 16:19:01 +00:00
Luiz Augusto von Dentz c51bcbb9d9 Bluetooth: GATT: Add write struct parameter to its callback
This makes bt_gatt_write consistent with the rest of the API where the
parameters are passed back to its callback.

Change-Id: Ie94208aa661d3620d0cbc5be4a4fb5b3c3ef061c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-20 13:40:55 +00:00
Arkadiusz Lichwa cc1d2f6ff7 Bluetooth: doc: Fix displacement of storage keys description
Improves placement of well known storage keys type values description
in Bluetooth API documentation by moving the comment to separate line
above the item it describes.

Change-Id: I6a9182d135983c5037cf44a4fda4305abfa4387f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-19 07:28:05 +00:00
Arkadiusz Lichwa 3fa7be207c Bluetooth: doc: Fix displacement of HCI buffer description
Improves placement of HCI buffer types description in Bluetooth API
documentation by moving the proper comment describing the value to
separate line above the item.

Change-Id: I15fb72842853b774a066f2c4f075547eb22a406e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-19 07:27:48 +00:00
Arkadiusz Lichwa a00625f37c Bluetooth: doc: Fix displacement of conn type description
Improves placement of available connection type values in Bluetooth API
documentation by moving comment describing the value to separate line
above item.

Change-Id: I50eab1eb9659e20da35cd35a6fa0d6fabde3f63d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-19 07:27:29 +00:00
Arkadiusz Lichwa 14de650b13 Bluetooth: doc: Fix displacement of security levels description
Improves placement of security levels value description in Bluetooth API
documentation by moving to separate line proper comment describing
the value meaning.

Change-Id: Ia2f58282bb664bf96cda888412900024c6ddf4b0
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-18 10:29:43 +02:00
Arkadiusz Lichwa 37bd570b9b Bluetooth: doc: Fix displacement of L2CAP channel states description
Improves placement of channel states value description in Bluetooth API
documentation by moving to separate line proper comment describing
the value meaning.

Change-Id: Ib111884bd4a52bdb023b872598a852fc441fefe5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-18 08:15:25 +02:00
Arkadiusz Lichwa 796d467653 Bluetooth: L2CAP: Set BR/EDR CoC channel as connected
Finalizes CoC channel configuration setup. The channel's CONNECTED state
can be set depending on context path by two responsible for that handlers.
Then one of them announces to all registered clients the connection is
set successfully.

> ACL Data RX: Handle 12 flags 0x02 dlen 12                   [hci1] 108.666944
      L2CAP: Connection Request (0x02) ident 3 len 4
        PSM: 3 (0x0003)
        Source CID: 64
> HCI Event: Number of Completed Packets (0x13) plen 5        [hci1] 108.668572
        Num handles: 1
        Handle: 12
        Count: 2
< ACL Data TX: Handle 12 flags 0x00 dlen 16                   [hci1] 108.673002
      L2CAP: Connection Response (0x03) ident 3 len 8
        Destination CID: 64
        Source CID: 64
        Result: Connection successful (0x0000)
        Status: No further information available (0x0000)
< HCI Command: Host Number of Complet.. (0x03|0x0035) plen 5  [hci1] 108.673548
        Num handles: 1
        Handle: 12
        Count: 1
< ACL Data TX: Handle 12 flags 0x00 dlen 16                   [hci1] 108.674725
      L2CAP: Configure Request (0x04) ident 5 len 8
        Destination CID: 64
        Flags: 0x0000
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 48
> HCI Event: Number of Completed Packets (0x13) plen 5        [hci1] 108.707579
        Num handles: 1
        Handle: 12
        Count: 2
> ACL Data RX: Handle 12 flags 0x02 dlen 16                   [hci1] 108.714206
      L2CAP: Configure Request (0x04) ident 4 len 8
        Destination CID: 64
        Flags: 0x0000
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 560
> ACL Data RX: Handle 12 flags 0x02 dlen 18                   [hci1] 108.715442
      L2CAP: Configure Response (0x05) ident 5 len 10
        Source CID: 64
        Flags: 0x0000
        Result: Success (0x0000)
        Option: Maximum Transmission Unit (0x01) [mandatory]
          MTU: 48
< HCI Command: Host Number of Complet.. (0x03|0x0035) plen 5  [hci1] 108.720451
        Num handles: 1
        Handle: 12
        Count: 1
< ACL Data TX: Handle 12 flags 0x00 dlen 14                   [hci1] 108.720472
      L2CAP: Configure Response (0x05) ident 4 len 6
        Source CID: 64
        Flags: 0x0000
        Result: Success (0x0000)

Change-Id: If831777f7bd87489eefbd200a1ca8883b83aae3e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-15 11:31:06 +02:00
Arkadiusz Lichwa 22bdf50615 Bluetooth: L2CAP: Mark finishing CoC configuration on BR/EDR
When each side involved in getting configured L2CAP CoC channel on
BR/EDR transport aggrees on configuration contract regarding in/out MTU,
set proper context flags to start prepare finalize config process.

Change-Id: Ic821ea3b961442be758ad4e2d91b2d812e2a54b5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-15 11:01:17 +02:00
Arkadiusz Lichwa c28720f167 Bluetooth: L2CAP: Introduce CoC channel states
Adds CoC channel's context to hold channel setup state and SM routine
that evaluates validness of transitions.
At the beginning DISCONNECTED, CONNECT and CONFIG states are added and
used by CoC setup on BR/EDR transport.

Change-Id: I1bbd16ec2f59ea961791786b78f22834d6f4b4d8
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-07-15 04:54:03 +00:00
Mariusz Skamra d98b9bd139 Bluetooth: Get the included service 128bit UUID
This adds reading of included service attribute 128bit UUID.
The limitation of this solution is that if several attr handle-range
pairs will be received, this will read first attribute UUID and then
start discovery from the the succeeding handle.

ZEP-373

Discovery related test results:

 2/76   GATT   TC_GAD_CL_BV_02_C   PASS
 3/76   GATT   TC_GAD_CL_BV_03_C   PASS
 4/76   GATT   TC_GAD_CL_BV_04_C   PASS
 5/76   GATT   TC_GAD_CL_BV_05_C   PASS
 6/76   GATT   TC_GAD_CL_BV_06_C   PASS

Change-Id: I27185b3a3ae96c9c03b0f356492df18ba83b183a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-07-13 14:18:03 +00:00
Luiz Augusto von Dentz a6a78bfbca Bluetooth: L2CAP: Unify code for adding and deleting channels
The code for adding and removing channels is very similar for LE and
BR/EDR so it can be unified and just leave the CID allocation up for the
bearer implementation.

Change-Id: Icf4c66262c4e973039381ebd1861fad4d46e1535
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-11 15:39:59 +00:00
Johan Hedberg 6e701275af Bluetooth: Add hexadecimal conversion logging helper
This has so far been used in SMP code as the h() function. Now it has
a more generic name and is accessible by all parts of the Bluetooth
subsystem.

Change-Id: Iae4607da9c8b3e6779d9c97f84a4e486d5258ef0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-07-11 09:38:53 +00:00
Luiz Augusto von Dentz 1183e6b82a Bluetooth: L2CAP: Add timeout handling
This adds initial timeout handling as described in the spec:

BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part A] page 126:

  'The value of this timer is implementation-dependent but the minimum
   initial value is 1 second and the maximum initial value is 60
   seconds. One RTX timer shall exist for each outstanding signaling
   request, including each Echo Request. The timer disappears on the
   final expiration, when the response is received, or the physical
   link is lost.'

Note: As for the actual interval used they are based on the values used
in Linux but in case of disconnect the minimum of 1 seconds was used
to follow the text above.

Change-Id: Ib98899c3ff07334955aee9c8fb53b1b89ba7bf31
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-08 12:05:33 +00:00
Inaky Perez-Gonzalez da5446281d doc: revert unnamed union/struct workaround in favour of known-issues
A workaround used to silence a warning in the doc generation process
which involved tagging a structure with a #define can now be solved
with a cleaner approach which is non-code-invasive.

Backup said change and update documentation on what to do when the
issue is found.

Change-Id: I1ef5224cd1b2df2e57c2ace438dba90ba3fc8528
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-07-01 21:53:45 +00:00
Luiz Augusto von Dentz b008f74b0b Bluetooth: L2CAP: Fix not cleanup properly if ACL is disconnected
If ACL is disconnected with channels still active the code should call
l2cap_chan_del to clean it up properly.

Change-Id: Iffa9345a9697ac80c1f2295578c7161ffeb44420
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-07-01 14:17:06 +00:00
Arkadiusz Lichwa caf83c96ed Bluetooth: L2CAP: Make public helper for LE channel conversion
Replaces all occurences of LE_CHAN() macro with new name
BT_L2CAP_LE_CHAN() and makes it public.

Change-Id: I426b17b0214f7ab4b69e5febbdca1917f22e7487
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-06-30 09:06:35 +00:00
Johan Hedberg e0ddc33ce2 Bluetooth: log: Add space after scheduling context
This improves readability of the debug logs.

Change-Id: Ib661535bcbb990cc8a807d40ff570aa11a293c54
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-30 08:38:58 +03:00
Johan Hedberg e4c8293e7f Bluetooth: log: Add missing sections.h include
The __stack and __noinit defines require sections.h.

Change-Id: I15f69b2ac9bc737016c986b21c76e576465bfdf7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-30 08:38:58 +03:00
Szymon Janc 9c68fd4e5b Bluetooth: Add priority buffer for handling critical HCI events
Command Status, Command Complete and Number of Complete Packets are
used for driving TX fibers (HCI and connection). Missing any of
those event will lead to HCI traffic stall.

Priority pool will be used when critical HCI event is received
or normal pool runs out of buffers. The difference with priority
pool is that buffer from it must not be passed to RX fiber and
must be freed from bt_recv.

If driver knows HCI event opcode before requesting buffer for event
it may hint HCI core about preferred pool selection.

Change-Id: Iad14724945bb59721c5ffb6b62d5a8a3e3f70be7
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-06-29 14:51:51 +00:00
Luiz Augusto von Dentz e9083dfcd7 Bluetooth: GATT: Add flags to attribute write callback
This adds flags parameter to write callback which can be used to indicate
that data only need to be prepared with use of BT_GATT_WRITE_FLAG_PREPARE
fixing qualification tests that needs to check authorization or other
errors that cannot be verified with just the permissions.

Change-Id: I3d662b2027718ffb52a280e3bbc9750be14f89ae
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-28 17:36:08 +03:00
Luiz Augusto von Dentz ad8066404f Bluetooth: GATT: Use enum to declare permissions
This makes it easier to document and more aligned to other parts of the
API that do make use of bitfields.

Change-Id: If1ff89d653537d854a4f788bf845d2ab6fe5bc23
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-28 17:11:29 +03:00
Luiz Augusto von Dentz 70afc2c7ae Bluetooth: GATT: Use BIT macro to declare permissions
This way it is easier to understand what bits are being set.

Change-Id: I17cbcc8adcbacb32d20142b557060759e5b7cd81
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-27 11:29:54 +00:00
Johan Hedberg 502f4a1581 Bluetooth: Add convenience enum value for no advertising options
This makes the code be a bit clearer by letting it specify a more
descriptive value than '0'.

Change-Id: I2e6b46f0924581d0d13f13479aa15170cc9e0e70
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-27 11:09:51 +03:00
Johan Hedberg fbb2fe8acf Bluetooth: Make random number generation API public
Applications or higher level profiles that are not part of the core
Bluetooth stack may need an easy way to generate random numbers. Since
we already have an internal helper for this export it for others to
use as well.

Change-Id: I29af7cab30ad8f60d481bc847984e781eaecd6bf
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-27 11:09:51 +03:00
Luiz Augusto von Dentz 105d342a63 Bluetooth: GATT: Fix attribute .write documentation
Change-Id: I765de61cc98927affd2547de765d61bb3f8e7efb
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-22 12:03:23 +00:00
Inaky Perez-Gonzalez ecc4c765cc doc: fix WARNING: Invalid definition" due to unamed structs/unions
Fix with a workaround in unnamed unions / structs in bluetooth, i2c,
sensor and uart.

Current documentation parsers (sphinx under Doxygen) don't seem to
understand well unnamed structs / unions. They will not generate any
documentation for any documented members (see left side of
http://imgur.com/mcpBXWc).

A workaround is to make the parser think there is something like a
struct/union/enum name that is actually something with no effect to
the compiler.

Naming it with __unnamed_workaround__ ensures it is clear it is a
workaround while we wait for a final fix. It is #defined to be a NO-OP
to the compiler and rearrange the member documentation as *@param* so
we have some documentation that the non-worked around code fails to
document.

Anonymous structs/union that declare a variable are just given an
internal name.

Workarounds documented in the contribution guidelines.

Change-Id: I4d32cf444f3c5e7d2fb11581e4b41f80e93c9786
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-06-21 22:06:56 +00:00
Arkadiusz Lichwa 8b1c837e28 Bluetooth: L2CAP: Handle incoming BR/EDR connection request
Enables L2CAP protocol definitions for connection request/response and
use it then to start handle incoming PSM connection request to valid
registered local PSM server. SDP PSM got no security restrictions.
The other PSM connections are validated against link encryption and
availability of SSP feature and if not matched are refused with
security error.

Change-Id: I429cf5dbce92300bd52639d5065e0144f8db4d13
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-06-21 07:41:27 +00:00
Arkadiusz Lichwa 16fda5f3d9 Bluetooth: Add support to read LMP remote features
Introduces HCI protocol defines to be able request and read remote LMP
features and if available extended data from peer when connected.

Change-Id: Ic274737d8b6c896eb9e83e2179829bcbadf6f635
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-06-20 10:13:03 +02:00
Inaky Perez-Gonzalez ee4c153f0a doc: fix warnings introduced in bluetooth headers
- Missed/mispelled argument types
- Needed @typedefs to workaround tool limitations

Change-Id: I1655eca96d30d04959154c5d468e1b3b330fafc5
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-06-16 13:11:06 -07:00
Johan Hedberg 8ea57bd5d3 Bluetooth: Shorten limited discovery parameter name
The parameter is already inside a struct that's specific to BR/EDR
discovery, so there's no need to repeat "discovery" in its name.

Change-Id: Idb95788bfc9d62ecd52adecc35104e212724cb78
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-16 11:28:59 +03:00
Johan Hedberg 1a756d6f8d Bluetooth: Fix validity check for Inquiry parameters
Since we only have a single user we can enforce length > 0x01. We
should also ensure that the results count is 1-255.

Change-Id: Id5d91acae06c6c6fc66dd59c0e367682a98dc08c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-16 10:58:50 +03:00
Johan Hedberg c2a5ab1917 Bluetooth: Add BR/EDR Inquiry length to bt_br_discovery_param
This way the application can control the maximum duration of the
Inquiry. The value 0x00 (which is invalid for HCI) is still accepted
for backwards compatibility and gets mapped to the old hard-coded 0x30
value.

Change-Id: Ibc9eb86bbb6c9e45b7b351278517b4a688015195
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-16 10:21:15 +03:00
Johan Hedberg 0aa4398f35 Bluetooth: Clarify language in discovery API documentation
Current language is a bit confusing, reword it in a clearer way.

Change-Id: Iaf2d29ab838cf2c5f50d7f2bdb2cdfa83c9a44c7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-16 09:56:54 +03:00
Johan Hedberg 0dc25e3849 Bluetooth: Put bluetooth.h APIs behind a GAP subgroup
This way the APIs don't dangle on their own under the master Bluetooth
group but are nicely behind a subgroup like everything else.

Change-Id: I608b6019e970db86a1bcdb29f0a52ce4a3165fbe
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-15 09:55:55 +00:00
Johan Hedberg 58a1568943 Bluetooth: Remove #ifdefs from public header files
These prevent the documentation from being included in the generated
doxygen output.

Change-Id: Iffe38c15055b8283d4b9f16b1c830c9f269ba6e4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-15 09:55:41 +00:00
Arkadiusz Lichwa b2647d84b3 Bluetooth: L2CAP: Refactor l2cap core types
Refactors L2CAP core data structures and modifies functions that uses them.
Now we can have separate L2CAP feature channel objects for LE and BR/EDR
transport. This's also a ground for make L2CAP CoC API to be common
for both transports.

Change-Id: Ic1197b0e3c4f505764b23fb9c7eb27123a44a675
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-06-13 11:49:07 +00:00
Johan Hedberg ebd5011adf Bluetooth: Update Intel copyright for files modified in 2016
Change-Id: I10a7cab9a7f911b9f64e17bf24ddce82c2f08c40
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-06-10 12:10:53 +03:00
Szymon Janc 0bae6e8354 Bluetooth: L2CAP: Include <bluetooth/buf.h>
This header defines BT_BUF_USER_DATA_MIN which is needed for declaring
buffers passed to BT stack and already includes <net/buf.h>.

Change-Id: I6b556be9fb3939a55af0b73d49fc59152d6d6a53
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-06-06 19:03:14 +02:00
Luiz Augusto von Dentz f54c5b744d Bluetooth: GATT: Remove obsolete flush callback
It is no longer necessary to implement flush callback for long
descriptors since the stack can queue prepare writes this callback
will never be called which makes BT_GATT_LONG_DESCRIPTOR obsolete
as well.

Change-Id: Idca31ba8e4404d2acba760c420394d5adee0a508
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-06 12:29:02 +00:00
Luiz Augusto von Dentz f6dd1e4144 Bluetooth: Add support for using SYS_LOG
This add CONFIG_BLUETOOTH_DEBUG_LOG which depends on SYS_LOG since the
later can actually use either CONFIG_PRINTK or CONFIG_STDOUT_CONSOLE.

Change-Id: Ib2974d1331f6c91d119a218ec95e8bf01069377b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-01 05:04:10 +00:00
Szymon Janc 31912bcb23 Bluetooth: Constify bt_register_starage parameters
There is no need for struct bt_storage being modified by stack.

Change-Id: I732cf94983a29de40d692e802d6a71b8986708df
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-30 12:57:24 +00:00
Johan Hedberg 7753e335f7 Bluetooth: Fix advertising parameters documentation
Change-Id: I67af3d5928ffa76cfe8c8f7a25ad65eb6493821f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-27 14:44:15 +03:00
Johan Hedberg 37c0944d05 Bluetooth: doc: Use proper grouping for APIs
Change-Id: Ifb3483d300409d280ca12aef5f49a983eff92496
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-16 20:14:28 +00:00
Luiz Augusto von Dentz 1157a8f26f Bluetooth: GATT: Remove authorization permission
The application can return BT_ATT_ERR_AUTHORIZATION on the callback
already so there is no reason to have it as a permission as once set
it always fails.

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

Change-Id: I3c62af137b99985690cf88dcc37a977a0be891f5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-10 17:55:06 +00:00
Szymon Janc 6d5ed390b1 Bluetooth: Simplify advertising API
Instead of requiring application to provide both advertising type
and address type used just require app to provide info if advertising
is connectable or not. Advertising type is set based on provided
SCAN_RSP and local privacy support.

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

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

Change-Id: I90e9a683ef3794f155707343c874f75585439325
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-04 11:11:34 +00:00
Luiz Augusto von Dentz bd602f6e98 Bluetooth: GATT: Update documentation to include error domain
Refer to ATT as error domain expected by GATT API.

Change-Id: I70d45a618191ae859f3b2c33427dbb7262511393
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-02 15:28:18 +03:00
Luiz Augusto von Dentz 6a4d39d5cd Bluetooth: GATT: Fix error type
Callback errors should contain ATT error code not posix errors.

Change-Id: I698fac086ab8b2dca3487ab99ee974b4318d16f7
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-02 14:31:02 +03:00
Roger Lendenmann 3278f542eb Bluetooth: gatt: include service api definition proposal
* service include macro definition takes reference to
   first service attribute of the included service

Change-Id: Ib2b1defe2c99aea738da791af74a534d56025eae
Signed-off-by: Roger Lendenmann <roger.lendenmann@intel.com>
2016-04-28 10:35:38 +00:00
Arkadiusz Lichwa 8e34b5869b Bluetooth: L2CAP: Add API to register PSM server
Enables API to register PSM server on BREDR transport.
Adds l2cap_br.c file responsible for BREDR specific functionality to
build path based on Kconfig selection.

Change-Id: I92823b0207ab0da96bfb813353de9f95fa5dd0f4
Origin: Original
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-04-26 10:58:14 +02:00
Johan Hedberg a28babc9b7 Bluetooth: L2CAP: Fix coding style of bt_l2cap_chan_ops
Indenting away the function pointer name from the return type is not
consistent with the rest of the code base.

Change-Id: I8bd69ccfd201fa3c9eedb13caeff920774d1defd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-25 07:30:25 +00:00
Johan Hedberg dd59f2704e Bluetooth: Add recently added SPI & I2C HCI bus defines
Change-Id: I23b9e32f21b279a4a830bfa5685fe7d8250a5afc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-22 18:49:11 +03:00
Johan Hedberg e3e91d3280 Bluetooth: Add name member to HCI driver struct
This is more of a convenience to let the driver identify itself in
debug logs and the monitor protocol.

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

Change-Id: Ic3a086fcc06352dbf051e52cef5bf6b8696349ae
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-22 18:49:11 +03:00
Johan Hedberg 264c207f4f Bluetooth: Add custom "monitor" protocol logging over UART
With most boards there's no simple way to get access to the HCI
traffic. Simultaneously these boards only have one external UART for
the console. This patch introduces a protocol which combines both
normal logs and HCI logs over a single binary protocol sent over the
console UART.

The protocol is modeled based on the btsnoop/monitor protocols used by
BlueZ, and the first tool that's able to decode this is btmon from
BlueZ ("btmon --tty <tty>").

For platforms with two or more external UARTs it is still possible to
use CONFIG_UART_CONSOLE as long as the UART devices used are
different, however on platforms with a single external UART
UART_CONSOLE should be disabled if BLUETOOTH_DEBUG_MONITOR is enabled
(in this case printk/printf get encoded to the monitor protocol).

Origin: Original
Change-Id: I9d3997c7a06fe48e7decb212b2ac9bd8b8f9b74c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-22 18:49:11 +03:00
Arkadiusz Lichwa bf62dfad70 Bluetooth: BR/EDR: Initiate encryption on link
Adds method to start encrypting the link by local controller. Encryption
implies successful authentication to be done before.

> HCI Event: Auth Complete (0x06) plen 3
	Status: Success (0x00)
	Handle: 11
< HCI Command: Set Connection Encryption (0x01|0x0013) plen 3
	Handle: 11
	Encryption: Enabled (0x01)
> HCI Event: Command Status (0x0f) plen 4
	Set Connection Encryption (0x01|0x0013) ncmd 1
	Status: Success (0x00)
> HCI Event: Encryption Change (0x08) plen 4
	Status: Success (0x00)
	Handle: 11
	Encryption: Enabled with E0 (0x01)

Change-Id: I3bbfc6ca77a6fd088582ab45f14d7c122aec7f05
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-04-19 12:50:31 +00:00
Arkadiusz Lichwa 9d9e349b31 Bluetooth: BR/EDR: Initiate authentication
Enables initiate authentication using possibility to change security
level on link by calling internal security API. In case of failure
resets pairing state flag to re-enable change security on subsequent
authentication attempts.

To verify the process of authentication run BT shell app from
tests/bluetooth/shell folder and use commands like below:
 >br-connect xx:xx:xx:xx:xx:xx
 [Connected: xx:xx:xx:xx:xx:xx]
 >security 1

HCI log:
> HCI Event: Connect Complete (0x03) plen 11
	Status: Success (0x00)
	Handle: 11
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
	Link type: ACL (0x01)
	Encryption: Disabled (0x00)
< HCI Command: Authentication Requested (0x01|0x0011) plen 2
	Handle: 11
> HCI Event: Command Status (0x0f) plen 4
	Authentication Requested (0x01|0x0011) ncmd 1
	Status: Success (0x00)
> HCI Event: Link Key Request (0x17) plen 6
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
< HCI Command: Link Key Request Negative Reply (0x01|0x000c) plen 6
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
> HCI Event: Command Complete (0x0e) plen 10
	Link Key Request Negative Reply (0x01|0x000c) ncmd 1
	Status: Success (0x00)
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
> HCI Event: PIN Code Request (0x16) plen 6
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
< HCI Command: PIN Code Request Reply (0x01|0x000d) plen 23
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
	PIN length: 4
	PIN code: 0000
> HCI Event: Command Complete (0x0e) plen 10
	PIN Code Request Reply (0x01|0x000d) ncmd 1
	Status: Success (0x00)
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
> HCI Event: Link Key Notification (0x18) plen 23
	Address: 00:13:17:72:8D:87 (GN Netcom A/S)
	Link key: d9ff76c09284c1ed369851f87d7ac623
	Key type: Combination key (0x00)
> HCI Event: Auth Complete (0x06) plen 3
	Status: Success (0x00)
	Handle: 11

Change-Id: I2d383d34e19c04ead3fa254e5514d5c7f352a21e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-04-19 12:48:45 +00:00
Johan Hedberg 7c038ef99e Bluetooth: Provide static inline stubs for UUID string helpers
This way when BLUETOOTH_DEBUG has been disabled we don't need to make
extra #ifdefs in application code to make it build without debug
support.

Change-Id: Iceabe0d700d571afae8b85c2c559ba372a883682
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-18 13:45:33 +00:00
Szymon Janc c2a1ac8ae7 Bluetooth: Add support for confirming incoming JustWorks pairing
If incoming pairing request would result in JustWorks pairing this
can be used to request consent from user for accepting it.

Change-Id: If0695d0e1bb010bade6a16abe1b57a2ce07856cc
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-04-14 15:20:03 +00:00
Johan Hedberg 54425117d0 Bluetooth: Export helpers for defining buffer pools
Now that the incoming ACL & HCI event pools can be defined externally
to hci_core.c there should be convenience macros to know what's the
minimum required buffer size for these pools.

Change-Id: I6f2a7322a3d77e1304e9d925767a1fd3471c76c7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-11 11:52:38 +00:00
Johan Hedberg 30601c09bb Bluetooth: Refactor buffer handling for non-host managed buffers
So far the assumption has been that the host stack manages all
incoming and outgoing buffers. For the incoming buffers (from the
controller) this has required hci_core.c to manage its own pools and
do the host flow control. This setup makes perfect sense for an
architecture where the controller resides remotely on a different CPU
& address space (i.e. the "traditional" HCI transport case).

When the stack runs on a system where the controller resides in the
same address space this setup doesn't work that well. In such a
scenario the incoming buffers are ideally created as low down in the
stack as possible (i.e. below HCI), which means that the current
hci_core.c cannot be responsible for managing their pools.

To allow for both types of architectures this patch introduces a new
BLUETOOTH_HOST_BUFFERS Kconfig option that can be selected to say that
host-side management is desired, or deselected to say that the
controller (residing in the same address space) takes care of managing
the incoming buffers.

So far the incoming buffer types were identified by hci_core.c by
looking at their "free pool" pointers, however as soon as the pools
are allowed to be somewhere else this doesn't work. To solve this we
now require a minimum user data size for all Bluetooth buffers and use
that to store the buffer type.

Change-Id: I14bc32007e3e3f17c654f71f79b520650028d7ce
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-11 11:52:29 +00:00
Johan Hedberg bc706e2a88 Bluetooth: Add stub for bt_storage_clear()
Change-Id: I7ab9ee4ca1d9702e7aef23aadfa627554907d145
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-05 12:29:14 +03:00
Johan Hedberg d0e4e0183e Bluetooth: Rename bt_register_storage to bt_storage_register
Keep a single bt_storage_* name space for current and future storage
APIs.

Change-Id: If158eb7408cce7c06cd8f98d78a061b9f9585265
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-05 12:29:14 +03:00
Johan Hedberg 5ccb20c591 Bluetooth: Use bt_addr_t inside bt_addr_le_t
In many cases when we want to access the 'val' member of bt_addr_le_t
it's in situations where the type needed is actually bt_addr_t. To
avoid unnecessary typecasts in these places simply embed bt_addr_t
inside bt_addr_le_t.

Change-Id: I7eecf129bee1dcf085abc83ec2f32e1a10b0b5aa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-05 12:29:14 +03:00
Johan Hedberg 13be3947ab Bluetooth: Add Privacy Feature support
Add initial support for the Privacy Feature, including the ability to
manage a local IRK and to use Resolvable Random Addresses.

Change-Id: I1c70aea67078dd2a5d07f3b797c37746ebe9ab61
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-05 12:29:14 +03:00
Johan Hedberg 7e7eee0fb4 Bluetooth: Add skeleton for persistent storage API
Add initial skeleton for the persistent storage API.

Change-Id: I7a6cc283aa88e7d861af18a6f0db2ed8c71e44a0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-04 14:01:59 +03:00
Johan Hedberg a85b1f7752 Bluetooth: Shorten set_adv_parameters to set_adv_param
The shorter form "param" is used elsewhere and this helps avoid overly
long lines.

Change-Id: Ie76497b5bf30e72099d13a26db9cacb8cd2c9c79
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-02 20:59:09 +03:00
Szymon Janc e23e4c76e2 Bluetooth: Add support for resolving BR/EDR names
If BR/EDR device didn't provide name in EIR (or no EIR at all) names
are resolved after discovery is completed. Resolved names are put into
EIR block.

> HCI Event: Extended Inquiry Result (0x2f) plen 255
        Num responses: 1
        Address: F0:79:59:03:6B:30 (ASUSTek COMPUTER INC.)
        Page scan repetition mode: R1 (0x01)
        Page period mode: P0 (0x00)
        Class: 0x280424
          Major class: Audio/Video (headset, speaker, stereo, video, vcr)
          Minor class: Set-top box
          Capturing (Scanner, Microphone)
          Audio (Speaker, Microphone, Headset)
        Clock offset: 0x47d5
        RSSI: -88 dBm (0xa8)
> HCI Event: Inquiry Complete (0x01) plen 1
        Status: Success (0x00)
< HCI Command: Remote Name Request (0x01|0x0019) plen 10
        Address: F0:79:59:03:6B:30 (ASUSTek COMPUTER INC.)
        Page scan repetition mode: R1 (0x01)
        Page scan mode: Mandatory (0x00)
        Clock offset: 0x47d5
> HCI Event: Command Status (0x0f) plen 4
      Remote Name Request (0x01|0x0019) ncmd 1
        Status: Success (0x00)
> HCI Event: Remote Name Req Complete (0x07) plen 255
        Status: Success (0x00)
        Address: F0:79:59:03:6B:30 (ASUSTek COMPUTER INC.)
        Name: Nexus Player

Change-Id: Ica5f6cc8a7d9dc7a925025bc62faab2caec47dbb
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-26 05:57:34 +00:00
Johan Hedberg fd1aa712d0 Bluetooth: Clarify code comment
Change-Id: Ie5c15777c7fa904c8d631dac6e1d4796d35f906c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-03-25 19:26:43 +00:00
Johan Hedberg ffc542e2fa Bluetooth: Move extern "C" declaration to right place
Change-Id: I60ad668366b0067af940b2ada14c83d5b7fc2107
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-03-25 19:26:32 +00:00
Szymon Janc ca662c14f1 Bluetooth: Add initial support for BR/EDR discovery
This allows to start (general or limited) BR/EDR discovery. Inquiry
is active until explicitly disabled by application. This is to keep
BR/EDR discovery API similar to LE scan API.

< HCI Command: Inquiry (0x01|0x0001) plen 5
        Access code: 0x9e8b33 (General Inquiry)
        Length: 61.44s (0x30)
        Num responses: 0
> HCI Event: Command Status (0x0f) plen 4
      Inquiry (0x01|0x0001) ncmd 1
        Status: Success (0x00)
> HCI Event: Inquiry Complete (0x01) plen 1
        Status: Success (0x00)

Change-Id: I946fbd881e6d0460be28a9975acd564ae32896e8
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-24 20:25:02 +00:00
Arkadiusz Lichwa 6f30525278 Bluetooth: BR/EDR: Handle User Passkey Entry event
Enables handle request from remote to enter passkey by the user to
continue SSP authentication process. It happens when local device
supports 'keyboard only' functionality. Otherwise the response is
negative.

> HCI Event: IO Capability Response (0x32) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: DisplayOnly (0x00)
	OOB data: Authentication data not present (0x00)
	Authentication: Dedicated Bonding - MITM required (0x03)
> HCI Event: IO Capability Request (0x31) plen 6
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
< HCI Command: IO Capability Request Reply (0x01|0x002b) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: KeyboardOnly (0x02)
	OOB data: Authentication data not present (0x00)
	Authentication: Dedicated Bonding - MITM required (0x03)
> HCI Event: Command Complete (0x0e) plen 10
	IO Capability Request Reply (0x01|0x002b) ncmd 1
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: User Passkey Request (0x34) plen 6
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
< HCI Command: User Passkey Request Reply (0x01|0x002e) plen 10
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	Passkey: 599207
> HCI Event: Command Complete (0x0e) plen 10
	User Passkey Request Reply (0x01|0x002e) ncmd 1
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: Simple Pairing Complete (0x36) plen 7
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: Link Key Notification (0x18) plen 23
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	Link key: 560e9c31d700ae5576af83d1e079e911
	Key type: Authenticated
	Combination key from P-192 (0x05)

Change-Id: Ia15517519b326eede29bc8e71edb7ec6ca77e010
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-03-21 11:12:01 +00:00
Arkadiusz Lichwa 143a826b1e Bluetooth: BR/EDR: Handle User Passkey Notify event
To allow remote, typically a keyboard, input on its side common
passkey during SSP authentication, enable generated passkey value by
local controller to be notified to user interface if available.

> HCI Event: IO Capability Response (0x32) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: KeyboardOnly (0x02)
	OOB data: Authentication data not present (0x00)
	Authentication: No Bonding - MITM required (0x01)
> HCI Event: IO Capability Request (0x31) plen 6
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
< HCI Command: IO Capability Request Reply (0x01|0x002b) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: DisplayYesNo (0x01)
	OOB data: Authentication data not present (0x00)
	Authentication: No Bonding - MITM required (0x01)
> HCI Event: Command Complete (0x0e) plen 10
	IO Capability Request Reply (0x01|0x002b) ncmd 1
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: User Passkey Notification (0x3b) plen 10
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	Passkey: 831705
> HCI Event: Simple Pairing Complete (0x36) plen 7
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: Link Key Notification (0x18) plen 23
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	Link key: 1a8d1c80409c4466b3423ca2bb761cf4
	Key type: Authenticated Combination key from P-192 (0x05)
> HCI Event: Encryption Change (0x08) plen 4
	Status: Success (0x00)
	Handle: 11
	Encryption: Enabled with E0 (0x01)

Change-Id: I1e8ad5d75181ceb9c93576b9e9b93975d9cdf35b
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-03-21 11:11:49 +00:00
Arkadiusz Lichwa 7b2799da1c Bluetooth: BR/EDR: Handle User Confirmation Request event
Enables processing, as pairing acceptor, user interactive passkey
confirmation request if local and remote IO Capabilities supports
'display yes/no'. Based on such validation, both parties can confirm
interactively passkey value or JustWorks (auto-accept) model is used.

> HCI Event: Command Complete (0x0e) plen 10
	IO Capability Request Reply (0x01|0x002b) ncmd 1
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: User Confirmation Request (0x33) plen 10
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	Passkey: 565990
< HCI Command: User Confirmation Request Reply (0x01|0x002c) plen 6
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: Command Complete (0x0e) plen 10
	User Confirmation Request Reply (0x01|0x002c) ncmd 1
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
> HCI Event: Simple Pairing Complete (0x36) plen 7
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)

Change-Id: Ice7a57a1c6150c10ea22402554954ed84aa94d0e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-03-21 11:10:47 +00:00
Arkadiusz Lichwa 02f541dfc5 Bluetooth: BR/EDR: Reply to IO Capability request
For now as local host works as pairing acceptor, the pairing context
flag is set when remote IO Capabilities is received.
Reply to the request uses remote's authentication requirement
cross-checked against predefined authentication methods that are based
on local and remote IO capabilities.

> HCI Event: IO Capability Response (0x32) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: NoInputNoOutput (0x03)
	OOB data: Authentication data not present (0x00)
	Authentication: No Bonding - MITM not required (0x00)
> HCI Event: IO Capability Request (0x31) plen 6
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
< HCI Command: IO Capability Request Reply (0x01|0x002b) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: DisplayYesNo (0x01)
	OOB data: Authentication data not present (0x00)
	Authentication: No Bonding - MITM not required (0x00)
> HCI Event: Command Complete (0x0e) plen 10
	IO Capability Request Reply (0x01|0x002b) ncmd 1
	Status: Success (0x00)
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)

Change-Id: I0f95a58178618f06de16cce0e9d9cf6c85209677
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-03-21 11:09:55 +00:00
Arkadiusz Lichwa befb051595 Bluetooth: BR/EDR: Validate remote requirements
According Core Spec 4.2 [Vol 2 Part E, 7.7.41], remote authentication
and IO capability requirements have defined valid ranges.

Change-Id: I0f7cfb79097abbf96b3fee79a757431b6beef665
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-03-21 11:03:00 +00:00
Szymon Janc d4edd35d26 Bluetooth: Add name resolving HCI commands definitions
Change-Id: Id5ba3ca3929b604031a1bcbb898036a5c8ed3a3b
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-21 10:34:12 +00:00
Szymon Janc 6f7234d62a Bluetooth: Fix HCI EIR event definition
Extended Inquiry Result Event shall always have one report so there is
no need to iterate over array.

Change-Id: Id6c550074395666b36d4dc6b956c9e4ae4154938
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-21 10:33:32 +00:00
Johan Hedberg 8563efc773 Bluetooth: Add definition for vendor event code
Change-Id: I764ba3f85a1aee1b57b882f77b1709004bf466e7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-03-16 10:08:35 +02:00
Szymon Janc 8d154104b6 Bluetooth: Add support for outgoing BR/EDR connections
This allows to create outgoing BR/EDR connection and cancel pending
connection before it succeed.

Change-Id: I5c08bb2e89f79c09fa7930f860d6080d902186a1
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-14 11:37:11 +00:00
Szymon Janc 72d82777c0 Bluetooth: Add HCI commands definitions for BR/EDR connections
Change-Id: I704658c657c5ee1e08cb6a9e7119494ff9ceced5
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-14 10:37:00 +00:00
Szymon Janc 5d238639e6 Bluetooth: Add HCI defines for BR/EDR discovery
Change-Id: I21073329373e11371a5ca81e86a1092345a212e6
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-10 12:12:13 +01:00
Arkadiusz Lichwa aaa2650f0f Bluetooth: Cleanup dependency build for LE/BREDR
Reorganizes mostly by using preprocessor (indirectly Kconfig options)
strictly LE-SMP related interfaces and security interfaces shared
between LE and BREDR connections.

Change-Id: I90daa36d72403cd5b73e6791714fcaf7f1fbe8e5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-03-09 10:55:31 +00:00
Szymon Janc 6116d58b02 Bluetooth: Use bt_auth_cancel for pairing cancel
bt_auth_cancel can be used to cancel any type of pairing.

Change-Id: Ia1a6ba834186ab6d5082d3eb473319c2d70cf4a7
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-03-08 15:38:59 +00:00
Luiz Augusto von Dentz 7ea6a2e64a Bluetooth: L2CAP: Add more descriptive documentation
This documents more in detail the behavior of the API, what callbacks are
involved and when they are called, etc.

Change-Id: I62994ed09a9e8b3f14dc3f8c792469a93aeefabc
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-03-08 11:44:43 +00:00
Luiz Augusto von Dentz 68ee16d85c Bluetooth: GATT: Add bt_gatt_indicate
This uses ATT Indicate Value command to indicate changes and wait for
confirmation response.

Change-Id: I123a00e374929d779f96a02440215c32c0e79423
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-03-07 16:44:15 +00:00
Arkadiusz Lichwa 7d03eec8d3 Bluetooth: BR/EDR: Add HCI SSP exchange IO Capa defines
Adds values to be validated during examining Secure Simple Pairing exchange IO
capabilities and bond types.

Change-Id: I3f25fa863b9a8a46c0a0e3c366e8b915c7db0bc7
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-26 13:41:31 +00:00
Arkadiusz Lichwa 847a1f6628 Bluetooth: BR/EDR: Add initial SSP Complete
Adds HCI protocol type for Secure Simple Pair Complete event and enables the
event in controller.
Then implements the initial SSP Complete event handler with catching
the status of SSP process.

Change-Id: Ic7cc5b4cab8a1b4120285815c24eeb6483d748df
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-26 08:43:31 +00:00
Arkadiusz Lichwa 2697d4fd5e Bluetooth: BR/EDR: Initial IO Capability reply to remote
Enables IO Capability Request event in controller.
Adds handler to react on controller's IO Capability Request event during
incoming pairing.
As a initial case respond to the request with negative reply setting
reason as 'pairing not allowed'.

Change-Id: I161c7ab7f1031a78cfa50444f41624232e5c5146
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-26 08:42:57 +00:00
Arkadiusz Lichwa dd8bf892f3 Bluetooth: BR/EDR: Handle IO Capability Response event
Enables IO Capability Response event in controller and adds remote IO Capability
and authentication fields to connection object.
Initializes them using IO exchange values delivered in SSP IO Capability
Response event data set representing remote as a part of incoming pairing
process.

Change-Id: Ia73a912f6fb633d1d1bb086ef3af9a280ac5a864
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-26 06:22:54 +00:00
Arkadiusz Lichwa 73e201cbce Bluetooth: BR/EDR: Enable SSP mode in controller
Turns on Secure Simple Pairing mode in controller. Since there's a prerequisite
the controller is 4.0+, turning the mode is unconditional.

Change-Id: Id4a10ccf8892a430b0daaa6750835516b17b7e8a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-26 06:05:31 +00:00
Johan Hedberg bab3b49fdb Bluetooth: Change GATT callback return values to ssize_t
Since the return value of these callbacks is a number of bytes ssize_t
is more appropriate than int.

Change-Id: I3406fb382975d62f51e7a195666d0ae88364fd2c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-20 15:39:33 +00:00
Luiz Augusto von Dentz 5676fb012d Bluetooth: L2CAP: Add proper documentation for callbacks
Document callbacks included in structs since they are also public API.

Change-Id: I8eda02b12172c54e8076208d8ea5ae246c650a3c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-18 14:14:30 +00:00
Johan Hedberg 8cf5a5080c Bluetooth: GATT: Provide documentation for the attribute callbacks
Document the parameters and expected return values of the read, write
and flush attribute callbacks.

Change-Id: I600da2ed64944986395520d7fae77fcb05b58e86
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-18 10:38:45 +02:00
Johan Hedberg a72d967d33 Bluetooth: GATT: Expose ATT error codes to application callbacks
Introduce BT_GATT_ERR macro to make it possible for application
callbacks to return exact ATT error codes.

Change-Id: I971536508e75036fbddc40b3f33e5201e11940bc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-17 15:05:34 +00:00
Johan Hedberg 15ac9992a9 Bluetooth: ATT: Add Common Profile Error Codes
These are specified in the Core Specification Supplement.

Change-Id: Ieaa9f061666119bb430d77b0fd40b4891e515b81
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-17 15:05:16 +00:00
Johan Hedberg 96f9831304 Bluetooth: Add public att.h header file
For now this only exposes the various ATT error codes.

Change-Id: If568782e90dca22871681d2d3b2d81ae4cb8e5e4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-17 15:05:08 +00:00
Szymon Janc 4dfb50e514 Bluetooth: Fix not calling connected callback on connect failed
If LE Create Connection fails notify application that connection
failed.

Change-Id: I3993bcb1bf3f8bd8fc08546e1fe683326b47db5b
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-17 13:07:46 +00:00
Mariusz Skamra 7acdf884cf Bluetooth: Add Cycling Speed and Cadence Service related UUID defs
This adds CSC Service related UUID definitions.

Change-Id: I3fc77cd6561ccfd7de0d906c7ddcd5d8dac5bff9
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-16 10:49:50 +00:00
Mariusz Skamra d768527930 Bluetooth: Add Environmental Sensing Service related UUID defs
This adds Environmental Sensing Service related UUID definitions.

Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
Change-Id: Idd87139971fb3c992b7fb7e346ce2ea90553ad38
2016-02-15 11:53:13 +00:00
Peter Mitsis 173877cff3 bluetooth doc: Fix parameter name in documentation
Change-Id: If537f3557dfc75ca2999f977ca8c2e7dbad36d5a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-11 20:11:03 +00:00
Johan Hedberg ecff186a82 Bluetooth: Add HCI defines for common 1-byte values
Change-Id: Ib3646497177098af4bc3e36c054fd16a3b120b84
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-11 14:48:03 +02:00
Johan Hedberg 500513b5f0 Bluetooth: Add connection role to bt_conn_info
This can be useful for both LE and BR/EDR connections so it sits
outside of those specific structs. The values are intentionally
matching the HCI values so for the HCI case we can just do a direct
assignment.

Change-Id: Id78d304bb61e5fd941f2c35351758c1eecc6ab6a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-11 14:48:03 +02:00
Peter Mitsis 43579b39d2 bluetooth doc: Fix typos in uuid documentation
Change-Id: Id5c91e2a257a79fc18ebbe459b0261daaa156672
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-11 07:55:06 +00:00
Peter Mitsis d663e873f5 bluetooth doc: Fix unsupported xml/html tag warnings
Uses the correct doxygen formatting tags to identify variables.

Change-Id: Ia46d4e008eb7790383682ac33bd3d6dbc2a66a9d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-11 06:31:52 +00:00
Johan Hedberg fd28fc1b00 Bluetooth: Move address helper functions to hci.h
These are needed both by nble as well as the HCI stack and will likely
also be of use for applications.

Change-Id: Ifd10ae6df25151162d9d5491466324b4a42f5506
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-10 19:13:01 -05:00
Szymon Janc 843268d78d Bluetooth: GATT: Refactor read API
Add read parameters to read callabck

Merge bt_gatt_read_multiple functionality into bt_gatt_read.
This makes it easier for application to handle all types of reads
as same sematics is kept for them.

Instead of destroy callback, call read_func with NULL data to
indicated that read has completed. This makes it clear when
read is completed and parameters used for it are no longer needed.
Thanks to this application doesn't need to abuse user data destroy
callback for detecting if read has completed. Since destroy callback
is no longer needed it is removed.

Also note that bt_gatt_read doesn't take any user data parameter
and that destroy callback was acctually called with read parameters.

If application would require to pass user data along with parameters
it may use CONTAINER_OF macro along with bt_gatt_read_params.

Change-Id: I8d6ea136b1e61c1dae73cca868b53c48c45a5492
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-10 18:52:29 -05:00
Szymon Janc 51ac70d42b Bluetooth: GATT: Refactor subscription API
This removes destroy callback for userdata as bt_gatt_subscribe
doesn't take any user data parameters and that destroy callback
was acctually called with subscribe parameters.

We assume subscription is active if bt_gatt_subscribe returned 0
(ie write command was sent). This is due to remote might be sending
notifications before reply to write.

Also note that bt_gatt_subscribe doesn't take any user data parameters
and that destroy callback was acctually called with subscribe
parameters.

If application would require to pass user data along with parameters
it may use CONTAINER_OF macro along with bt_gatt_subscribe_params.

Change-Id: I58ac9cd481ffa08ccc2d7a0464ca75f61fb280c5
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-10 18:52:29 -05:00
Louis Caron 48802c2212 Bluetooth: Add API to update LE connection parameters
Applications should be able to update the connection parameters.

Change-Id: I446f64fcd0b27b605e636e566fb35a362a92de96
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:33 -05:00
Szymon Janc 6645d3f485 Bluetooth: GATT: Remove destroy callback from bt_gatt_discover_params
Instead of destroy callback, call discovery_func with NULL attribute to
indicated that discovery has completed. This makes it clear when
discovery is completed and parameters used for it are no longer used.
Thanks to this application doesn't need to abuse user data destroy
callback for detecting if discovery has completed.

Also note that bt_gatt_discover doesn't take any user data parameter
and that destroy callback was acctually called with discovery
parameters.

If application would require to pass user data along with parameters
it may use CONTAINER_OF macro along with bt_gatt_discover_params.

Change-Id: Iec4eb9795975ef2555502e13a682e13ff37742e0
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:25:32 -05:00
Louis Caron bcb61c6630 Bluetooth: add the connection parameters to le conn info
Applications that need it can retrieve the connection
parameters at any time, connected callback for example,
and eventually handle the connection update callback or
not, this gives maximum flexibility for handling these
parameters and requesting change.

Change-Id: Iba7d30ade045875ebc721fd332e031d9008e248c
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:32 -05:00
Szymon Janc 87d8bfeaa2 Bluetooth: Add clarifying comment about usage of struct bt_uuid
This type should only be used as a pointer.

Change-Id: Icf656f310344cecbde527e809af6d00dcfc7ef82
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:25:32 -05:00
Johan Hedberg 479d25d035 Bluetooth: Rename BT_LE_ADV_ADDR_PUBLIC to BT_LE_ADV_ADDR_IDENTITY
In anticipation of supporting a local static random address in the
future it makes more sense to call BT_LE_ADV_ADDR_PUBLIC
BT_LE_ADV_ADDR_IDENTITY.

Change-Id: I4826f1dfb50b54e13a35cbe7ee74e28641c81ad1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:31 -05:00
Johan Hedberg 08c594049d Bluetooth: Update documentation of BT_DATA & BT_DATA_BYTES
Change-Id: Ia523cc2f0602dcd9b7c0877121c678b049d64956
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:31 -05:00
Johan Hedberg 7d8303bbbf Bluetooth: Introduce BT_DATA_BYTES convenience macro
This way we don't need a special BT_BYTES macro and avoid bugs coming
from wrongly counted number of bytes (which is now evaluated at
build-time).

Change-Id: Ic6319234a816fe2fab6229b3bb980d0e3503e241
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:31 -05:00
Johan Hedberg 56ba2ffb6b Bluetooth: Remove unused bt_uuid_copy() API
There are no more users of this API, and the only user it had in the
past was quite a special corner case. Just remove it for the time
being.

Change-Id: I696139b493f9ca75530665de25a4a4e03fc0ac5b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:28 -05:00
Johan Hedberg d5e23e86d2 Bluetooth: UUID: Introduce new API
Introduce new UUID API with bt_uuid, bt_uuid_16 and bt_uuid_32
structs. The specific size structs are derived from the common bt_uuid
struct to make it possible to use CONTAINER_OF().

Change-Id: I9cb03c73406acb7768d410fdf29eae75d252163c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:28 -05:00
Luiz Augusto von Dentz 23ac865f33 Bluetooth: L2CAP: Fix bt_l2cap_chan_send documentation
bt_l2cap_chan_send does actually return the number of bytes sent.

Change-Id: I9dd79da992577f2e1e8d30d42eeb0c398e48ff33
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:28 -05:00