Commit graph

922 commits

Author SHA1 Message Date
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
Johan Hedberg f448b6810d Bluetooth: UUID: Add value definitions
In some cases we need the raw 16-bit UUID value instead of a full UUID
object. Add definitions of these values so that the code doesn't need
to do complicated tricks to get hold of them.

Change-Id: I98f276402f20fe03fea2777743f15ca7fcae42c6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:27 -05:00
Arkadiusz Lichwa 2dc833880e Bluetooth: BR/EDR: Rename encr_mode to encr_enabled
Adjusts encryption state name in connection complete event.

Change-Id: Ib7e6b2c5738ca9f5832e0e277d8f5718050f4bef
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:27 -05:00
Johan Hedberg 3e9bfe5119 Bluetooth: Add missing nanokernel.h dependency to log.h
Change-Id: Ifcdc2d44dc9223833dc628613fada3d2cf7daa8f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:26 -05:00
Arkadiusz Lichwa 9b0d42930c Bluetooth: BR/EDR: Define HCI Link Key request
Enable HCI protocol for handling Link Key request event and
responses.

Change-Id: Ib3e24782257a87028b63198d210203b442883211
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:25 -05:00
Peter Mitsis a0e4568760 c++: Add extern "C" { } block to header files
Adds extern "C" { } blocks to header files so that they can be
safely used by C++ source files.

Change-Id: Ia4db0c36a5dac5d3de351184a297d2af0df64532
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Arkadiusz Lichwa cdd0d308c7 Bluetooth: BR/EDR: Add all legacy and SSP link key types
Adds all valid link keys types available during legacy and SSP
authentication.

Change-Id: I42f2aba0122d33a984bd84c56b7a6a290f5e9e1d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:20 -05:00
Luiz Augusto von Dentz d65dcc5e4b Bluetooth: GATT: Replace handle with attribute object in bt_gatt_notify
This make more sense since the handles are normally self allocated by
the stack.

Change-Id: I198dd9c3ef6259cff8a0e528514918ec18990dea
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:20 -05:00
Luiz Augusto von Dentz ea1534f100 Bluetooth: GATT: Add bt_gatt_attr_next function
This add bt_gatt_attr_next function that can be used to iterate to next
attribute which is convenient if original attribute is known and using
bt_gatt_foreach_attr would require a lookup and another function to pass
as callback.

Change-Id: I1bd522fd4ae784e08aa375b35320191cbfc03a54
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:20 -05:00
Luiz Augusto von Dentz c44ef91e56 Bluetooth: GATT: Add support for static DB
This enable applications to build with a single table representing the
database where attributes don't have to store a pointer to the next
attribute thus reducing its size.

Change-Id: I4c84e2d50f9088a2f9879068890f0646e586e007
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:20 -05:00
Johan Hedberg f190371781 Bluetooth: Add stubs for directed advertising API
Add API definition and stubs for directed advertising.

Change-Id: Ib22d3acb6d2e76b0c638b26b8e07860cd189f640
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg bc073cdb59 Bluetooth: Add bt_conn prefix for auth APIs
All of the authentication APIs deal with bt_conn objects. For
consistency it makes therefore sense to use the proper bt_conn name
space with them.

Change-Id: I47912d542373df511524cc6ad2532d6c9a76ca68
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg 25f6579016 Bluetooth: Move all bt_conn related APIs to conn.h
To have some proper split of conn.h and bluetooth.h APIs make sure all
bt_conn related ones are in conn.h. This also helps avoid forward
declarations for some upcoming patches where we need bluetooth.h
defines from within conn.h.

Change-Id: Ief3d32118a6749fb5785dab6cb3fee4ebb86ddb4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg 432c2db4d8 Bluetooth: Add err/reason parameters to connected/disconnected calls
This is essential so that the application can be notified of
connection failures and also be able to know the reason for the
disconnection.

Change-Id: I30108958963f6aeac690612bb26738dc4c67ca80
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg 0df7a2fac6 Bluetooth: Add error return to authentication APIs
The authentication APIs may fail, so it's fair to give the application
a chance to catch these errors.

Change-Id: I323df86b94a823b201fe22d412e6bbcaa9029550
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg 8bf880a388 Bluetooth: Use smallest possible size for enums
Use __packed so that enums consume the smallest possible size (in our
case the same as uint8_t).

Change-Id: I0440113e88a24509f406375d99173ddb54890925
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg 3c47e9515c Bluetooth: Update advertising API
Update the advertising API according to what has recently been
discussed and agreed upon.

Naming-wise the most important change is the removal of "EIR" which
was confusing since this is mainly used with LE at the moment. The
Core Specification Supplement consistently uses the generic terms data
and data type to describe what we're dealing with here, so the new
names are bt_data and BT_DATA.

Another change is to detach the actual data from the struct by
converting it from an array to a pointer. This is not only essential
for supporting BR/EDR (which has a different length) but to also
minimize memory usage.

Another change is to require the caller of bt_le_adv_start() to
provide the array lengths of the ad and sd paramters. This way we
don't have to have the empty (8-byte) element at the end of each
array.

Lastly, the bt_le_adv_start() logic is slightly modified so that it
will always clear the respective data if necessary. Previously the
user might have been left with a previous callers data if it passed
NULL to the API.

Change-Id: I318026ceb1b52bb688edf4dcfed82613bd15c3e1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:19 -05:00
Johan Hedberg a524f335fd Bluetooth: Add missing include needed by size_t
Change-Id: Id1f5d3c28d10850072b0963660b851f096598ccf
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:18 -05:00
Mariusz Skamra 4e5d6581c0 Bluetooth: GATT: Split Authorization Permission for Read and Write
According to Core Specification 4.2 Vol 3, Part G, 3.3.3.4,
Server Characteristic Configuration descriptor shall be:
"Readable with no authentication or authorization.
Writable with authentication and authorization defined by a
higher layer specification or is implementation specific."
So there shall be separate authorization permissions
for write and read access.

Change-Id: Ia2850acbb976571743bf96cf9cbe0c1128534073
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:25:17 -05:00
Mariusz Skamra 4a94c7f559 Bluetooth: GATT: Correct GATT Discovery related comment
This patch fixes some outdated or invalid comments and adds some
clarification of GATT Discovery procedure.

Change-Id: I91994917bea246a2d112df65123a3e6dec42ee92
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:25:10 -05:00
Szymon Janc dcd8e188da Bluetooth: Fix bt_gatt_discover_func_t callback definition
bt_gatt_discover function doesn't take user data and therefore
bt_gatt_discover_func_t is not providing any user data. It was
always providing discovery parameterts used so just match that
in function definition.

Change-Id: I90086285d02e2ef50be1d5d25299bb1c6819fdd7
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:25:10 -05:00
Johan Hedberg 005b9904a4 Bluetooth: Don't pass length of PIN code to bt_auth_pincode_entry
We can calculate the length with strlen() and there should be no need
to consider anything else except nul-terminated C strings.

Change-Id: I02ec4b1dddbb1bd457f035926c86b27f4c2ab050
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:10 -05:00
Szymon Janc 0542d6df90 Bluetooth: Add passive scan helper macro
This allows to conveniently start passive scan from central
applications.

Change-Id: Idf470be747ab7c6e7413cc368227b0b69e7b78a4
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:25:10 -05:00
Louis Caron 45804e6ccb Bluetooth: Add PPCP UUID declaration
When the BLE GAP service needs to declare the preferred connection
parameters.

Change-Id: Iff8a6f68f2dfe478c44dcc5a3e95abda271ecc00
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:10 -05:00
Luiz Augusto von Dentz a855c68943 Bluetooth: GATT: Add note about parameters of async procedures
Asynchronous functions use the parameters to store relevant data even
after the scope it has been called which means they have to remain valid
while the operations are in course.

Change-Id: I2cc79e5ce352fef4e077e9fb4cb0f4d111463d00
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:09 -05:00
Luiz Augusto von Dentz b839882c69 Bluetooth: UUID: Introduce bt_uuid_copy
This introduces bt_uuid_copy which can be used to copy UUID values.

Change-Id: I22d996bcace454769ac871a43b9acebe8b23db39
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:09 -05:00
Arkadiusz Lichwa d34e498d04 Bluetooth: BR/EDR: Extend bt_conn_info type
Enables get basic connection info support for non-LE connections.

Change-Id: If295b552567886256cfc1e215bfe3149d2f1f60c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:09 -05:00
Arkadiusz Lichwa c5f22a20b8 Bluetooth: BR/EDR: Add PIN code HCI protocol data
Defines objects mapping of HCI protocol for:
1. PIN code event from controller
2. Link key event from controller
3. PIN code reply to controller
4. PIN code negative reply to controller

Change-Id: Id06c2b74f6e4dadb6d97a95072a7b227bab197b7
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:09 -05:00
Arkadiusz Lichwa 98f1ef7192 Bluetooth: BR/EDR: Add PIN code authentication API
Defines authentication interface for legacy 2.0 devices

Change-Id: I28fe07fa4f5b9f4e0bcb707eab73a0cd5df2b425
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:09 -05:00
Arkadiusz Lichwa bce38d9f9e Bluetooth: BR/EDR: Enable authentication interface
Gets included authentication API in BR/EDR variant

Change-Id: I4fa55bb3baa8db79f6e9f5f1c65c0d93f8f8780a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:09 -05:00
Szymon Janc bc18a867b4 Bluetooth: Fix compilation with SMP disabled
This fix SMP dependency checks in connection code.

Change-Id: Ic7e515885381bd243c89f2a6e10c356095e79b55
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:25:08 -05:00
Andrei Emeltchenko 7160c9c95e Bluetooth: Move BT_STACK definitions to log.h
BT_STACK depends on BT_STACK_DEBUG_EXTRA, therefore moving it there.
It also allows to use BT_STACK in drivers, at the moment only
Bluetooth stack uses it.

Change-Id: I41e0e0d49dae6abef2dc3a8d1d109127787d3db0
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:25:08 -05:00
Louis Caron 7fdb42a46f Bluetooth: add CPF descriptor support
In order to support more standard descriptors, the PF macro and helper
function are added.

Change-Id: I52db3c32f40f39b9c6bfdb9573d0a614d0f3295e
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:08 -05:00
Louis Caron d566c3314b Bluetooth: add CUD descriptor support
In order to support more standard descriptors, the UD macro and helper
function are added.

Change-Id: Ic9a82658668107b40abc5c98002fe5091dc10f08
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:08 -05:00
Mariusz Skamra b90d2c6dbd Bluetooth: GATT: Pass bt_conn to the discovery function callback
This patch replaces bt_gatt_attr_func_t with bt_gatt_discover_func_t
to be used as a type of discovery callback. The reason is
bt_gatt_attr_func_t don't return bt_conn which could be used
later on to issue other commands and to application to know
from which connection this results come.

Change-Id: I1f26c72ad5c8a0b97485a337c7005d34281586d7
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:25:08 -05:00
Louis Caron be72f6d197 Bluetooth: UUID: Add the SCC UUID
Change-Id: I5b9d3ef5745be46b5453e1c5b90fe4dc05d76073
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:07 -05:00
Louis Caron 12f40ebd8c Bluetooth: GATT: Fix small typo
Change-Id: Ie70354e9b80db5b6a08fe639d1e3393df6294115
Signed-off-by: Louis Caron <louis.caron@intel.com>
2016-02-05 20:25:07 -05:00
Luiz Augusto von Dentz 4a20bc14a7 Bluetooth: Make use of BT_UUID_DECLARE_16 for services
This makes it simpler to add the services directly into GATT services
table.

Change-Id: I090c7f9396329cf524947dd6647230c663a55f60
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:07 -05:00
Johan Hedberg 401fccf7ce Bluetooth: log: Remove redundant 'bt:' prefix from assert
BT_ERR() already inserts the bt: prefix.

Change-Id: I7feda0e28caad4f0e1f18e5d9099fa21684e4b35
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:07 -05:00
Johan Hedberg 30e0e64407 Bluetooth: Add color logging support
Add basic color logging support. Error logs will be printed in red
whereas warn() logs in yellow. The support is behind a Kconfig option
in case someone needs to build the stack for a terminal that doesn't
support the ANSI color codes.

Change-Id: I080e32db68f87e81f1bb54aa4c634f7cd38f1e33
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:07 -05:00
Johan Hedberg 966acc1980 Bluetooth: Don't default to continuous scanning with BT_LE_SCAN_ACTIVE
Change-Id: I76d7db24bb9459f1df1d1e9881accc970b60aaf8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:03 -05:00
Arkadiusz Lichwa 853ab787e7 Bluetooth: BR/EDR: Initial connection complete handling
Enables getting by host connection complete event and handle
internal state of related to the event connection object.

Change-Id: Ie6252ff33cc2e1fff5a4ce746fda7c3a59bf8aab
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:03 -05:00
Arkadiusz Lichwa db57e259a7 Bluetooth: BR/EDR: Rename BT_CONN_TYPE_BREDR
To conform to API convention rename BT_CONN_TYPE_BREDR to BT_CONN_TYPE_BR.
Updates stack code so far uses it.

Change-Id: Ia759ef68bbdb232e3b0992740e0536d310e19010
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 719aab5ce3 Bluetooth: BR/EDR: Reject SCO connections until we support them
Change-Id: I73ae6d02a00d06ccfc382c86599df338f68cb6a5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Arkadiusz Lichwa 08c40b1034 Bluetooth: BR/EDR: Validate incoming conn request
Initilizes conn object and defines accept and reject response to
incoming connection request.

Change-Id: I8f50ce535a43f5d04f12951f5c855004910a81a5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:02 -05:00
Arkadiusz Lichwa 1453613acc Bluetooth: BR/EDR: Enable handling incoming conn request
Upsizes event mask to accept incoming connection and
defines initial handler for incoming connection request.

Change-Id: I93490c0916761aba3d6bc7a6b7cb5dcb8153c9c7
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 4087728345 Bluetooth: Provide API to advertise with local NRPA
Applications may want to protect the privacy (identity of the local
device). One way to do this is to generate a Non-resolvable Private
Address and use that when advertising.

Change-Id: Ib852b03c14af062f914aa99a14e50c2e52ac78c2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg d13a338689 Bluetooth: Use NRPA for active scanning
There's no reason for us to go revealing our public address when doing
active scanning.

Change-Id: I27bed74bb377b8bba75843ea76acb8f0d58f70f7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 784e391bef Bluetooth: Add define for Connectable low duty cycle directed advertising
Change-Id: Id17df93e086a16e12f2b12172fda8e351b07cdf3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 47044cd677 Bluetooth: Add advertising interval to LE adv params API
Change-Id: Id61589ca723c822ea8eb84c67ac9ed57b00cc305
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 7fb1900511 Bluetooth: Fix typo in LE GAP timer definitions
Change-Id: I390043bf44bab2e99fd5d58f52691b50a7763818
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 9533fbcfe1 Bluetooth: Add latency & timeout to LE conn param API
Change-Id: Icd6122b9056dd686d70a2d213a18dcab34f5e80a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 1a32d5ed55 Bluetooth: Add support for specifying connection parameters
Applications may want fine-grained control of connection parameters.
The two APIs to provide this through are bt_le_set_auto_conn() as well
as bt_conn_create_le().

Change-Id: If5cddbbf017b868d768d18d2a09daf4af8aa00d8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg defd4aa4d5 Bluetooth: Update GAP timer definitions
Change-Id: I8376752e10d21289ebeef4e02a24759ec8352c67
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:02 -05:00
Johan Hedberg 70669756ff Bluetooth: Add convenience macros for defined GAP timers
Change-Id: I6315c7791249d07fa2df0682decc0049718b5a06
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg 266721018d Bluetooth: Add proper defines for scan enable parameters
Change-Id: I2d915517986007356c14e805eaed60a0f4290109
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg 5a5061ef97 Bluetooth: Convert bt_conn_set_auto_conn to bt_le_set_auto_conn
Once we start persistently storing the addresses of devices we want to
reconnect to we also need a way to reload them to the stack. Since we
don't have a connection object at this point the API cannot take that
as a parameter. Instead rename the function and have it take
bt_addr_le_t as a parameter.

The feature was also lacking proper reference counting for the
connection, which this patch now adds (the flag itself owns a
reference). The function is now also possible to call before bt_init()
so that if we load the stack with multiple devices the HCI doesn't get
bombarded with lots of scan enable/disable commands.

Change-Id: I9072bf061eb64f2ecec96f74fb176be13e5bdaee
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg 3226780a3c Bluetooth: Add LE scan interval & window to bt_le_scan_param
Change-Id: If2ae26625b98485c3495f4f4f48e49600a1ffd14
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg 610d32311e Bluetooth: Add LE scan type to bt_le_scan_param
This way the app can start passive scanning if it wants.

Change-Id: Iab3e60863d5a1a013a5f069a98664628c7b14418
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg dd353487c4 Bluetooth: Create active scanning helper macro
All current user just want basic active scanning so a corresponding
macro makes more sense than something based on duplicate filtering.

Change-Id: I97787be24b89fad66f2a952c5d53ab76f4e062fb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Luiz Augusto von Dentz 095da440cd Bluetooth: GATT: Make use of BT_UUID_DECLARE_16
This uses BT_UUID_DECLARE_16 in macros that can only be of 16 bits
format.

Change-Id: I45d4bcca9859a2e279b1199546891df75a039589
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:00 -05:00
Luiz Augusto von Dentz 2cd5f53d86 Bluetooth: UUID: Add macros to declare 16 and 128 bits UUIDS
This makes it easier to declare 16 and 128 bits UUIDS and also save space
in case of 16 bits.

Change-Id: I5790afd9504ee0cca4a951be6bc542685d0a35fb
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:25:00 -05:00
Johan Hedberg f5a238b665 Bluetooth: Add ability to specify dedicated LE advertising parameters
We'll need to have a much more flexible LE advertising API. This is a
first step in that direction. A convenience BT_LE_ADV() macro is
provided to ease converting application code.

Change-Id: I74854487bbdfb4b1cf1bee0b6351d1750a56ff86
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:00 -05:00
Johan Hedberg 6f470dcbce Bluetooth: Add ability to specify dedicated LE scan parameters
We'll need to have a much more flexible LE scanning API. This is a
first step towards it. The existing BT_LE_SCAN_FILTER_DUP_* enum
values are converted to macros to avoid having to update application
code at this point.

Change-Id: I0c8d29dc156bad67cddc9401c0d72aee8ec6d8de
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:00 -05:00
Johan Hedberg 52989aeecc Bluetooth: Move bt_le_scan_cb_t definition to better place
Change-Id: I9b17d2237654e651465d054f60f6c4e44576250b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:00 -05:00
Johan Hedberg f1d4b686b6 Bluetooth: Rename bt_bredr_* prefix to bt_br_*
bt_br_* is equally understandable and the same length as the
corresponding bt_le_* prefix on the LE side.

Change-Id: I1820f9b9fab6363b696072f6b70d57c0bc780078
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:00 -05:00
Johan Hedberg 5619d1114b Bluetooth: Rename LE scan & advertising APIs for consistency
To have a clear split between LE & BR/EDR rename these APIs with the
appropriate prefixes.

Change-Id: I983df2b5880947d96f0ad289d12f3383f44894be
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:00 -05:00
Arkadiusz Lichwa 1b66376a61 Bluetooth: Fix misused forward declaration
Instead of struct forward declaration there should be used
struct type with at least empty body.
Otherwise compiler doesn't know the size of variable of that type
used later and emits error.

Change-Id: Ie0643ed92b8eb95c1d55c9295117a2a9b8cc95cc
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:59 -05:00
Arkadiusz Lichwa 2ebf636fe2 Bluetooth: BR/EDR: Add basic SCAN support
Adds capability to stack to make controller discoverable and
connectable.

Change-Id: Iffe380d2bde0c193f806b76cce3933914c9a4796
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:59 -05:00
Luiz Augusto von Dentz c05ea4c21c Bluetooth: Add bt_conn_get_info
Change-Id: I32fd5b1c159623c59a353e1084f47f3cc9f704e6
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:59 -05:00
Luiz Augusto von Dentz 2f275c86b9 Bluetooth: UUID: Add IPSS UUID definition
Change-Id: Iff14213b734a3eb10c1c386c0b638849e9232465
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:59 -05:00
Szymon Janc 51f8ca59cd Bluetooth: Add newline to log macros
Make newline part of log macros so that caller doesn't have to
append '\n' every time logs are used. This make sure that no
log will be missing new line which results in concatenated log
messages.

Change-Id: I3231ae747c790816dbc1608e0a3bd56467ba0a1b
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:59 -05:00
Peter Mitsis 42bb6227dc doc: Change "None" return value to "N/A"
Improves documentation consistency by using "N/A" instead of "None"
when the routine does not return a value.

Change-Id: I429a159b3037742cbc431db0cb4828ab9d6d35c3
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:24:53 -05:00
Luiz Augusto von Dentz 7d2d2838fb Bluetooth: L2CAP: Implement segmentation for incoming packets
If the SDU length is bigger than the amount data received in the first
packet it means it will be segmented in 2 or more packet until the SDU
is completed.

Since the MTU required by the upper layer could be much bigger than the
ACL buffer the code now request a buffer to reassemble the SDU.

Change-Id: I286d16e185f59a8128c4357dddebdc13145dfe31
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:51 -05:00
Luiz Augusto von Dentz 81af3feb01 Bluetooth: L2CAP: Use semaphore to control credits
This use struct nano_sem to control the credits so when sending if the
credits hit zero it now waits more credits to continue instead of
failing.

Change-Id: I2da4692eaa16828f74a1df4346583258bb4cf8f0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:51 -05:00
Luiz Augusto von Dentz 6a4affef19 Bluetooth: L2CAP: Add bt_l2cap_chan_send
This adds bt_l2cap_chan_send which can be used to send data to
dynamic channels resulting in the following trace:

< ACL Data TX: Handle 3585 flags 0x01 dlen 17
      Channel: 64 len 24 [PSM 128 mode 0] {chan 5}
        a0 02 ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
        ff ff ff ff ff ff ff ff                          ........

Change-Id: I753e301b1125ef21a345ab96470f15bc53a4869a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:51 -05:00
Szymon Janc 48249bf34a Bluetooth: Add public API for passkey confirmation
This allows to request user to confirm displayed passkey with remote
device. This allows to have authenticated LE SC link resulting in FIPS
security level.

Change-Id: I5b6c1666e3d1687cc04c5d66529372db090dd000
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:51 -05:00
Szymon Janc 856cba6d8b Bluetooth: Read supported commands on init
This will be used to determine if controller supports
"LE Read Local P-256 Public Key" and LE Generate DH Key" commands.

Change-Id: Ib2bf7cfa99a20c07af0d3043ac9f9c2e0a6c2fcb
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:47 -05:00
Szymon Janc 217c649a5e Bluetooth: Add HCI definitions used in LE Secure Connections
"LE Read Local P-256 Public Key" and LE Generate DH Key" commands
are used for LE Secure Connections pairing. "LE Set Event Mask"
is used to unmask events generated by those commands.

Change-Id: I601c8e21093ed2170dfe8e5618b34493268fe68d
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:47 -05:00
Szymon Janc cf1ec9fb7f Bluetooth: Explicitly set LE event mask on init
This allows to disable events not required by application. In future
this can be extended to enable events that are not enabled by default.

< HCI Command: LE Set Event Mask (0x08|0x0001) plen 8                                                                                 24.018392
        Mask: 0x000000000000001f
          LE Connection Complete
          LE Advertising Report
          LE Connection Update Complete
          LE Read Remote Used Features Complete
          LE Long Term Key Request
> HCI Event: Command Complete (0x0e) plen 4                                                                                           24.019215
      LE Set Event Mask (0x08|0x0001) ncmd 1
        Status: Success (0x00)

Change-Id: I29bfaa0743ac9e604a637f51503ff28a9b2074c2
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:47 -05:00
Mariusz Skamra 7dc3d35da6 Bluetooth: gatt: Unsubscribe notification from callback directly
With this patch application can unsubscribe notifications
from Subscribe value callback directly, if BT_GATT_ITER_STOP
is returned.

Change-Id: I7873594f5dbe6e8c5bef11bf397a74cdc870a464
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:24:47 -05:00
Mariusz Skamra d42a70288b Bluetooth: gatt: Refactor read of attributes as a gatt client
This patch refactor reading of attribute values as a client.
Current MTU size is taken into account to determine if read
procedure has been completed or not.
For now, read procedure will be continued until whole is read,
or stopped by client.
Core Specification says that "The Read Blob Request is repeated
until the Read Blob Response’s Part Attribute Value parameter is
shorter than (ATT_MTU – 1)." (Vol 3, Part G 4.8.3)
Because application didn't know the current MTU value,
there was no way to determine if data received is complete.

Change-Id: I9d0e3f8638b58c3a4e39060333aedc133b775e3d
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:24:46 -05:00
Luiz Augusto von Dentz a983eff168 Bluetooth: L2CAP: Add bt_l2cap_chan_disconnect
This adds bt_l2cap_chan_disconnect which can be used to disconnect
dynamic channels resulting in the following trace:

< ACL Data TX: Handle 3585 flags 0x00 dlen 12
      LE L2CAP: Disconnection Request (0x06) ident 2 len 4
        Destination CID: 64
        Source CID: 64
> ACL Data RX: Handle 3585 flags 0x02 dlen 12
      LE L2CAP: Disconnection Response (0x07) ident 2 len 4
        Destination CID: 64
        Source CID: 64

Change-Id: I77ec29c8879a330b7f73e217621436045fa5163e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:46 -05:00
Luiz Augusto von Dentz 973bd0f4d7 Bluetooth: L2CAP: Add bt_l2cap_chan_connect
This adds bt_l2cap_chan_connect which can be used to connect dynamic
channels resulting in the following trace:

< ACL Data TX: Handle 3585 flags 0x00 dlen 18
      LE L2CAP: LE Connection Request (0x14) ident 1 len 10
        PSM: 128 (0x0080)
        Source CID: 64
        MTU: 63
        MPS: 65
        Credits: 4
> ACL Data RX: Handle 3585 flags 0x02 dlen 18
      LE L2CAP: LE Connection Response (0x15) ident 1 len 10
        Destination CID: 64
        MTU: 672
        MPS: 230
        Credits: 10
        Result: Connection successful (0x0000)

Change-Id: I73b2bd62fdca4a3ffa35577f0b66c2e6bb0083cd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:46 -05:00
Johan Hedberg 50256ea514 Bluetooth: Move BT_L2CAP_BUF_SIZE to a more appropriate place
This doesn't need to be exposed in the public API.

Change-Id: Ib6d4336684620bd1e03d128765f289b5ebd744ef
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:45 -05:00
Johan Hedberg b9d13664ab Bluetooth: Create protocol-specific outgoing ACL buffer pools
With this split we get better control of the buffer sizes and counts.
We also anyway will need a fragments pool so a simple generic ACL_OUT
pool doesn't make sense anymore. The related Kconfig options for that
have been removed.

Change-Id: I616cf49915a1cc0dc0ddc724e2e182bcbe0c80f6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:45 -05:00
Johan Hedberg 1f6841c9c1 Bluetooth: Convert driver header info to hidden Kconfig options
We know the needed values at build-time, so there's no point in having
a runtime mechanism of accessing them in the code. Having the values
as defines makes it e.g. possible to use them as input for defining
the size of buffer pools.

Change-Id: Ib7556644719bfb631e638fa5bf29f3d1747a5072
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:45 -05:00
Mariusz Skamra 992237bc51 Bluetooth: Add bt_conn_enc_key_size function
This patch adds bt_conn_enc_key_size function which will be used
by application to check encryption keys size of a encrypted connection.
This will be used especialy by GATT applications, because some
attributes to be accessed require encryption with specified
minimum encryption key length.

> ACL Data RX: Handle 64 flags 0x02 dlen 7         [hci0] 708547.536685
      ATT: Read Request (0x0a) len 2
        Handle: 0x0003
< ACL Data TX: Handle 64 flags 0x00 dlen 9         [hci0] 708547.544302
      ATT: Error Response (0x01) len 4
        Read Request (0x0a)
        Handle: 0x0003
        Error: Insufficient Encryption Key Size (0x0c)

Change-Id: Idbc9afde7ec80504898bd8d1e193f3e71a93f3f9
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:24:45 -05:00
Mariusz Skamra f3f63d0fb0 Bluetooth: Cleanup comments in GATT API
This removes some outdated comments, adds missing ones
and fixes some major typos.

Change-Id: I3e6c0c1b88c67852fc8c24eb2ff35d74af8bc656
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:24:44 -05:00
Luiz Augusto von Dentz 8eaae649a7 Bluetooth: L2CAP: Fix documentation of bt_l2cap_server_register
Fix format of bt_l2cap_server_register documentation.

Change-Id: I22322a235bb1d6b6752bfe13ce8e305481649125
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:44 -05:00
Johan Hedberg db946d8bae Bluetooth: Add convenience defines for ACL handles
These make the code more readable when it comes to encoding and
decoding ACL handle values.

Change-Id: Ibd1972d6001c6c0c55428300f839b288dff1ce52
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:44 -05:00
Johan Hedberg 4b433d4fa6 Bluetooth: Differentiate send/recv of needed driver headroom
The space that the HCI driver needs to reserve for its own use is not
necessarily symmetrical. E.g. even with the current H4 driver we only
need to reserve space for sending data but not for receiving it.
Keeping track of these values independently enables more efficient use
of the buffers.

Change-Id: I64917b545c5cd77356ed038d09afe76422334661
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 5f4daa1551 Bluetooth: Merge send_acl/cmd back to a single callback
Now that we have the buffer type enum as part of the HCI driver API we
can take advantage of it to pass the buffer type information and not
have to have two separate callbacks.

Change-Id: Ib2ee5b1540e532c9b27903e97660a276c1293fbc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg ff2d104105 Bluetooth: Move buffer type enum to driver.h
Since the buffer type is essentially a HCI driver - HCI core
communication detail the appropriate place for it is driver.h. At the
same time remove the unnecessary and slightly confusing BT_DUMMY type.

Change-Id: Ic813ad24d8f0530d3779006063ea21b010d29cf6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 3822aecd24 Bluetooth: Merge buf.[ch] functionality into hci_core.[ch]
There's no need to maintain a separate module for this anymore.
Subsequent patches will have further simplifications thanks to this
being now handled in a single c-file.

Change-Id: I4510c9f72b121e1e5fd19eeb8b5d5ddf2f4bfffe
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 1ddc3edcaa Bluetooth: Introduce HCI-driver specific buffer functions
This way we avoid dealing with the specific buffer type value and to
make it clear that these are for drivers onle.

Change-Id: I8aef7ec6a767b2fa68cbe374eb371e2a6192f675
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 7ff1cbd976 Bluetooth: Split HCI driver ACL/CMD send callback
This is a necessary step in preparation for removing the buffer type
information from the buffers.

Change-Id: I29d8fae32aa660416a1c12e87840499c711e659f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg ea11d4b5cd Bluetooth: Add helper macros for accessing Bluetooth user data
To avoid unnecessary stack variables and to simplify code, add helper
macros to access the Bluetooth specific ACL and HCI user data that's
part of the buffers.

Change-Id: Idc337537721115c4091982c04f8a05bbbf0d5a19
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 6e84d77151 Bluetooth: Remove old bt_buf API
Now that all code is converted remove the temporary helpers for the
old bt_buf API.

Change-Id: I5183add527d204c51103549fda3378040d5f8f68
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 529a12338b Bluetooth: l2cap: Convert to net_buf API
Convert the code to use the net_buf API instead of the soon to be
removed bt_buf API.

Change-Id: I5f376caeb861ac8b815a0a2e235bd188b9e8185b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:38 -05:00
Johan Hedberg c73b131b3b Bluetooth: core: Convert to net_buf API
Convert the code to use the net_buf API instead of the soon to be
removed bt_buf API.

Change-Id: I226de212d4f8d4f5b613708ffe42570443bc2182
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:38 -05:00
Johan Hedberg 581fa90ea8 Bluetooth: Initial conversion to net_buf API
This patch performs the minimal necessary conversion to the net_buf
API. It uses a temporary "#define bt_buf net_buf" to make it possible
to convert the code in smaller increments. Most old bt_buf function
also serve as one-line wrappers to the matching net_buf APIs. Once
everything is converted these helpers will be removed.

Change-Id: Ie31433d33576022c9c193a35d2389267005545d6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 929d4f4c86 Bluetooth: GATT: Make BT_GATT_CHARACTERISTIC declare its value
This makes BT_GATT_CHARACTERISTIC declare a local bt_gatt_chrc so the
applications don't need to declare themselves.

Change-Id: Icf3fad7dffea5667c6f13aa022a5722900da51e8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 1617f5580b Bluetooth: GATT: Remove value_handle from bt_gatt_chrc
The spec says it should always be the very first descriptor after the
characteristic:

  "BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part G] page 534:
   3.3.2 Characteristic Value Declaration
   The Characteristic Value declaration contains the value of the
   characteristic. It is the first Attribute after the characteristic
   declaration. All characteristic definitions shall have a
   Characteristic Value declaration."

Change-Id: I6c38dea9cc4c1a05997edbd348e2759680472725
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 148ce3013c Bluetooth: GATT: Remove unused field of _bt_gatt_ccc
value_handle is not used for anything.

Change-Id: I3885d221b162eb3bd44956af64280baf61dc001b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 1284e608ac Bluetooth: GATT: Remove handles from macros
bt_gatt_register will assign a handle if not initialized and removing
the handle makes it simpler to change the attributes since it is no
longer possible to have conflicting handles.

Change-Id: I787f7325cc990c360056b1aefd07bb7d7876b445
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 1c8ab98114 Bluetooth: GATT: Make attribute database into a list
This allow calling bt_gatt_register multiple times so different tasks
can add their own services separately.

Change-Id: I8143ddedfa1079087d608013d1a97b552a3007dc
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:38 -05:00
Johan Hedberg 49885879f2 Bluetooth: Rename bt_conn_get/put to bt_conn_ref/unref
We want to make the naming convention ref/unref rather than get/put.
So far the only reference counted objects are the buffers and the
connections. For the buffers the new generic buffer API will also use
ref/unref.

Change-Id: I9fe8b8a6a50a8baf06ba231e8f6717a5a47dd292
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 6f410176ef Bluetooth: Make bt_uuid_str parameter const
bt_uuid_to_str uuid param is const therefore bt_uuid_str should be const
as well.

Change-Id: I043d66d16c863ed92e60477dbbb9c37bcde92703
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:38 -05:00
Luiz Augusto von Dentz 6cb42e1e20 Bluetooth: Make use of bt_uuid_to_str
This make use of bt_uuid_to_str to when printing UUID values, to make it
simpler when it is just going to print so the patch introduces a new
function that does the conversion in place using a static variable.

Change-Id: Idfedf05a5ad201653fff2e01387f046cd5647c83
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:37 -05:00
Luiz Augusto von Dentz 118dc75cea Bluetooth: GATT: Add connection to bt_gatt_notify
This allow sending direct notification to a specific peer without
using CCC which is allowed by the spec:

  BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F page 507
  3.4.7.1 Handle Value Notification

  A server can send a notification of an attribute’s value at any time.

Change-Id: Ieff29216cb9ba197c0da92d7b22b26e63101cfa8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:37 -05:00
Mariusz Skamra e35203e863 Bluetooth: Add Limited Discoverable Flag definition
For limited discoverable mode, we need to have a define
for this advertisement flag.

Change-Id: I774b68546983697844eca2644b0ca0a85b8026e8
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:24:37 -05:00
Luiz Augusto von Dentz d55e4ca91c Bluetooth: Add CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL
This adds an option to enable L2CAP dynamic channel support, fixed
channels are not affected by it.

Change-Id: If36bece46b7b94142ea1ac976b878d1b5ae6a578
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:37 -05:00
Luiz Augusto von Dentz 30b6a9fe7b Bluetooth: L2CAP: Add initial public API
This split L2CAP API so that server API is available to applications
while the rest of the API is keep internal to the stack.

Change-Id: I031926ff906ce100684fba0947b2e9eb2c8fcaeb
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:37 -05:00
Dan Kalowsky 39063598db checkpatch: error - spacing
Change-Id: Ie6e1c43581dd4b0734625b3a4e59a4ca79619e99
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky 978851fb6a checkpatch: code_indent failures
Corrects the checkpatch code_indent failures

Change-Id: I2ff93b8907d3eddbaa543ccbd12aecef8af7f698
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Mariusz Skamra 50e2355754 Bluetooth: Add bt_uuid_to_str function
To be used for debugging purposes.

Change-Id: I471e1a0c1affc52e900ae99a53f58346e9f997ef
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:24:30 -05:00
Javier B Perez Hernandez f7fffae8aa Change BSD-3 licenses to Apache 2
Change all the Intel and Wind River code license from BSD-3 to Apache 2.

Change-Id: Id8be2c1c161a06ea8a0b9f38e17660e11dbb384b
Signed-off-by: Javier B Perez Hernandez <javier.b.perez.hernandez@linux.intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:29 -05:00
Szymon Janc 68382388ce Bluetooth: Disable parts of public API if not configured
Depending on selected Kconfig options some parts of public API
are disabled with #ifdefs. This should make it easy for user to
figure out which options should be enabled to specific API.

Change-Id: I4ae1bfd7bf535ea45869772c429ccd3d3d4c214e
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:24 -05:00
Luiz Augusto von Dentz 7a441e7424 Bluetooth: GATT: Refactor discover API
Add discover type to bt_gatt_discover_params to the API is reduced to
just bt_gatt_discover, this should simplify adding support for
discovering secondary and included services.

Change-Id: Iadeed86fed115afee1340b2c09821d7fafdda0f4
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:24 -05:00
Luiz Augusto von Dentz 1b4fb0d8a6 Bluetooth: GATT: Add value support to bt_gatt_subscribe
This enables bt_gatt_subscribe to subscribe using indication value in
addition to notification.

Change-Id: I25f3b057e36b023a79fb66b11b70716ecc299ba9
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:16:16 -05:00
Szymon Janc 8b7097fd20 Bluetooth: Make parts of GATT API internal
Move parts of the API that are not usable for applications to
an internal header.

Change-Id: Idbcd3db8acda74375ea9deec2bf3d7eddc8a4ddb
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:16:16 -05:00
Luiz Augusto von Dentz 1354dc9a90 Bluetooth: Add bt_buf_clone
This adds bt_buf_clone which can be used to duplicate a buffer, including
its contents.

Change-Id: I473841e1fce00fddbfac1fb2c55d40741658484f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:16:16 -05:00
Mariusz Skamra a679ffbfa8 Bluetooth: gatt: Fix non-passing service handles to the callback
Pass service handles to the callback during service discovery.

Change-Id: I616de5188faf76c84cc02ceb29a6f5aab631b89c
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:16:15 -05:00
Arkadiusz Lichwa 0f507833f8 Bluetooth: Add defines for LE Connection Update Complete event
Adds HCI layer event defines to be used by LE Connection Update
Complete event handler.

Change-Id: I5c3502054acd4f838a33c55df8d1eefe1acec6b4
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:40 -05:00
Mariusz Skamra 252ddb1565 Bluetooth: Shorten LE Conn Param define names
Shorten LE Remote Connection Parameters Request Event
HCI define and struct name.

Change-Id: Ia094b16caa2716f24afd4cc7db57404050fafeef
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:39 -05:00
Szymon Janc 57daca9341 Bluetooth: Add callback for security changed
This callback is called if security level of a connection was changed.

Change-Id: I268da245cf4b7f6d2bfbd57969ce2da6c34fc69f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:38 -05:00
Arkadiusz Lichwa 93968a91bf Bluetooth: Add defines for LE Remote Connection Parameter Request
Adds HCI layer defines to be used by LE Remote Connection Parameter
Request routines.

Change-Id: I7274a33c704c47d81612dd67bd732ba48d3aa1c8
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:38 -05:00
Arkadiusz Lichwa aa7226b6f7 Bluetooth: Add additional HCI error defines
Adds new error codes to be used by Remote Connection Parameter
Request handlers.

Change-Id: Ief163350c677f251ea30c0ff2f1b70b86ee2a5f6
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:38 -05:00
Szymon Janc 393dad0ccf Bluetooth: Add callback for identity resolution
This callback is called if identity was resolved for remote device
that was using Resolvable Private Address while connection. From
now on only Identity Address is used.

Change-Id: I5976be575a8e4ad8c13f56d7bc274d751ae37511
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:38 -05:00
Szymon Janc 01c76d9fa4 Bluetooth: SMP: Add support for passkey entry
This allows to request passkey being entered by user.

Change-Id: I6a56c65ca689473659a13c19f8578058476d2685
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:37 -05:00
Benjamin Walsh 0dcad8331b clarify use of term 'context'
The term 'context' is vague and overloaded. Its usage for 'an execution
context' is now referred as such, in both comments and some APIs' names.
When the execution context can only be a fiber or a task (i.e. not an
ISR), it is referred to as a 'thread', again in comments and everywhere
in the code.

APIs that had their names changed:

  - nano_context_id_t is now nano_thread_id_t
  - context_self_get() is now sys_thread_self_get()
  - context_type_get() is now sys_execution_context_type_get()
  - context_custom_data_set/get() are now
    sys_thread_custom_data_set/get()

The 'context' prefix namespace does not have to be reserved by the
kernel anymore.

The Context Control Structure (CCS) data structure is now the Thread
Control Structure (TCS):

  - struct ccs is now struct tcs
  - tCCS is now tTCS

Change-Id: I7526a76c5b01e7c86333078e2d2e77c9feef5364
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:15:27 -05:00
Andrei Emeltchenko f9cd4105da Bluetooth: Add GATT Signed Write command
Add support for signed write with sign parameter for write without
response.

Change-Id: I79008532d88b10d34db1f68898ad4258dd3e761b
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:15:24 -05:00
Szymon Janc 947f7100c5 Bluetooth: Validate callbacks in bt_auth_cb_register
This adds validation for passed callbacks. Previously registered
callbacks need to be explicitly unregistered by passing NULL.
It is no longer possible to implicitly overwrite callback
structure.

Input Output Capabilities generation is factored out to separate
function. This is in preparation for adding more callbacks.

Change-Id: Ie809ea2daa80f9c54585efb459b49af1107007d3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:24 -05:00
Szymon Janc 8423871b90 Bluetooth: Add initial support for authenticated pairing
This allows to register agent with display capability resulting
in DisplayOnly InputOuput Capability being used.

Change-Id: I98931af35c51a71882b60303c0f5d4da19eefbc4
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:24 -05:00
Szymon Janc faec70c367 Bluetooth: Move security levels to conn.h
For now this is used only in conn.h. Allows to reduce includes
dependencies.

Change-Id: I60dbe588e711fa0332049cbea43ffb6838a58823
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:24 -05:00
Luiz Augusto von Dentz c6c89a8529 Bluetooth: GATT: Add bt_gatt_write_without_response
This split the use of ATT Write Command and ATT Write Request since with
the former it is possible to sign the data thus making combinations of
parameters in bt_gatt_write complex/confusing.

Change-Id: I0349acd16d22ea4e38ac3e5ad8c3cdc318851633
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:15:23 -05:00
Luiz Augusto von Dentz 0636edfdd7 Bluetooth: GATT: Add offset to bt_gatt_write
This enables writing from offset using Prepare Write + Execute Write
procedures including Long Write procedure when the data is bigger than
the MTU.

Change-Id: Id35d66c011ba582a4ba92ffe75444226e479335a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:15:22 -05:00
Johan Hedberg 79696d3b34 Bluetooth: Redesign Bluetooth init API
We need to be able to perform the init procedure asynchronously
through a callback. The RX fiber is a good candidate to use for the
callback since it's not active in its normal operation before
drv->open has been called. In order to prepare for a future
bt_disable() API the init API is renamed from bt_init() to
bt_enable(). If a NULL pointer is given as the callback the API
behaves synchronously like the old bt_init().

Change-Id: I4e78fa8f32dcf5477ea05a8db75aca5cdce591fd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:44 -05:00
Arkadiusz Lichwa 35ba35db7a Bluetooth: Add bitmask for LE exchange features
Adds bitmask to be used for validation of LE features
exchange support.

Change-Id: I96a79f5e5c4fef330933480f9dd5ec567cd9523f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:44 -05:00
Arkadiusz Lichwa 6035dc2300 Bluetooth: LE read remote features HCI abstraction
Adds LE read remote features command and event types.

Change-Id: I3270142379c6f822f6f4be2e720c9cabb5d3df3e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:44 -05:00
Arkadiusz Lichwa d63811079f Bluetooth: Adjust update connection params over L2CAP
The slave may request a change to the connection parameters using
the L2CAP LE signaling channel if either the master or the slave
or both do not support the Connection Parameters Request procedure.
Therefore if local controller doesn't support this, the request
can be made for sure.

Change-Id: I23e70793763693e40dab3bfb6a9634816f5b02b2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:44 -05:00
Luiz Augusto von Dentz 7540844891 Bluetooth: GATT: Make bt_gatt_notify length parameter uint16_t
This is consistent with the rest of the API since the attribute length
can be at most 512 bytes long.

Change-Id: Ia2e60cf8dadcb93d0d091cda5be1b80de98fae94
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:44 -05:00
Luiz Augusto von Dentz 8697d207a0 Bluetooth: GATT: Fix using uint8_t for attribute length
Attribute length can be up to 512 bytes long so it needs to be at least
uint16_t, ATT already takes care that the MTU does not exceed 512 bytes.

Change-Id: I6c8dc80a4b63f212420c26c0a24d93939fa510fe
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:44 -05:00
Mariusz Skamra 6b4f7025f2 Bluetooth: Start using atomic flags to indicate bt_dev state
With this patch advertising state and scanning state are stored as flags.

Change-Id: I5d2dc37972620ee89aaf55d45e294e8be82863d3
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:43 -05:00
Luiz Augusto von Dentz 7006b5ae92 Bluetooth: GATT: Add bt_gatt_unsubscribe
This adds bt_gatt_unsubscribe which can used to unsubscribe to attribute
value notification using CCC handle.

Change-Id: I8a3b1594787a3322834516d0306a84c8ef7792dd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:43 -05:00
Luiz Augusto von Dentz fac5df2bae Bluetooth: GATT: Add bt_gatt_subscribe
This adds bt_gatt_subscribe which can used to subscribe to attribute
value notification using CCC handle.

Change-Id: I0983843836b0c2253f750b34b7765dd880cb10a0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:43 -05:00
Luiz Augusto von Dentz 9c47d065a7 Bluetooth: GATT: Add missing return documentation to bt_gatt_read
All public APIs shall contain the complete documentation including
@return in case the function return something.

Change-Id: I1f16eaf988ace1a3ac760c59eacd71a6a5912df9
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:41 -05:00
Luiz Augusto von Dentz dc55a3741e Bluetooth: GATT: Add bt_gatt_write
This adds bt_gatt_write which can used to write attribute value.

Change-Id: I45a02e6dbf642ed1bcab8234180f2c48a28e2874
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:41 -05:00
Arkadiusz Lichwa 70c7e8825c Bluetooth: GATT: Add bt_gatt_read_multiple
Introduction of GATT client API to enable read attributes
determined by set of handles.

< ACL Data TX: Handle 64 flags 0x00 dlen 21
      ATT: Read Multiple Request (0x0e) len 16
        Handle: 0x0001
        Handle: 0x0002
        Handle: 0x0003
        Handle: 0x0004
        Handle: 0x0005
        Handle: 0x0006
        Handle: 0x000a
        Handle: 0x000b
> ACL Data RX: Handle 64 flags 0x02 dlen 27
      ATT: Read Multiple Response (0x0f) len 22
        00 18 02 03 00 00 2a 54 65 73 74 20 70 65 72 69  ......
        70 68 65 72 61 6c

Change-Id: Ic8e6edcf79a63bc52cb4c657e5b09529fa87879e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg fe41cec885 Bluetooth: Move bt_security to conn.h and rename it appropriately
Change-Id: Ibea6e4ef08c68e9debf0c53036dd2e4f75ea9a72
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg a33047f7a5 Bluetooth: Move bt_connect_le to conn.c and rename it appropriately
This function operates on bt_conn so it should be in conn.c and
exported through conn.h. Rename it with the appropriate bt_conn_*
prefix.

Change-Id: Id17c67f0e95cc1afb10aa7742b2d2ce0110ea616
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg 824135122f Bluetooth: Move bt_disconnect to conn.[ch] and rename it appropriately
The bt_disconnect deals with the bt_conn object and should therefore
reside in conn.c and be exported through conn.h. It should also have
the appropriate bt_conn_* prefix.

Change-Id: I75eb648fd9aa8ced9a991d472c319d25f4b772af
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:40 -05:00
Luiz Augusto von Dentz d982120a7e Bluetooth: GATT: Add bt_gatt_read
This adds bt_gatt_read which can used to read attribute values.
Note: Attributes which values are bigger than the MTU need to be read
multiple time until the end since the stack cannot cache any data.

Change-Id: I09c502eeb674a577673182c35a0e1a84519fd3b7
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:40 -05:00
Mariusz Skamra b210d53172 Bluetooth: Add initial auto connect support
Calling bt_conn_set_auto_conn one can decide if auto connect shall
be used. If so, everytime the connection is lost, passive scanning
will be enabled to listen for connectable advertisements from
remote device and re-establish the connection.

Auto connect can be disabled if one decide to disconnect from
this device using bt_disconnect or call bt_conn_set_auto_conn
with auto_conn flag set to false.

Change-Id: Ic9952e313cb8612ea6c72838be0755805daeffcf
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:40 -05:00
Arkadiusz Lichwa 8f7c8a3969 Bluetooth: buf: Add bt_buf_add_le16() API
Enables directly add 16-bit value at the end of operational buffer.
Value is converted to little-endian format before is appended.
Position of buffer's tail is updated during addition.
Usage of bt_buf_add() call enables monitoring available limited room
in the buffer when CONFIG_BLUETOOTH_DEBUG is on.

Change-Id: Id7ac62cd3b11ef03302e94185a7faae747eccb20
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:40 -05:00
Luiz Augusto von Dentz e0792a1ba2 Bluetooth: GATT: Add bt_gatt_discover_descriptor
This adds bt_gatt_discover_descriptors which can used to discover all
descriptors in the given range.

Change-Id: Idf93852ef9d8ba3bfce20dc0b95f4e11aa0dc73d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:40 -05:00
Mariusz Skamra f45bbec4a1 Bluetooth: hci: Add bt_stop_advertising
This adds above function to stop ongoing advertising.

Change-Id: I16b3913524a61e844a81cbe733f2b8e6072ab442
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:39 -05:00
Johan Hedberg 410a8a8165 Bluetooth: Fix doxygen documentation for bt_connect_le()
Change-Id: Ib40d5a23ee60dad16686f43dee172a31c456e7e1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:39 -05:00
Johan Hedberg 5e5c87503d Bluetooth: Add BT_ASSERT() helper macro
Change-Id: Ib9cfb6494cb3369f4c1e029010589c4d6967afcb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:36 -05:00
Luiz Augusto von Dentz df92f7c4c6 Bluetooth: GATT: Add bt_gatt_discover_characteritic
This adds bt_gatt_discover_characteristic which can used to discover all
characteristics in the given range.

Change-Id: Ia7ddb93dfdb0f979409e133c902a1cbd9ae9fe71
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:36 -05:00
Johan Hedberg d7ccefd0bd Bluetooth: Fix doxygen comment style
Change-Id: I37b85e83b54f7efb8aded70ec95fd87cafaf7e2b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:35 -05:00
Luiz Augusto von Dentz 1e7016a823 Bluetooth: GATT: Include uuid.h
gatt.h API depend on bt_uuid so make use uuid.h is always included.

Change-Id: If9d4e5a668ac4e0b167eda8fe41e8b4810dfe298
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:35 -05:00
Luiz Augusto von Dentz 4c640515c7 Bluetooth: GATT: Add bt_gatt_discover
bt_gatt_discover can be used to discover primary GATT service by UUID in
a selected handle range, after it attribute found the function callback
is called so the user can interact the attribute found and decide to
continue to the next or stop.

Change-Id: I37514f00c82ce5520d7a14757a6ff12ee34f0736
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:35 -05:00
Mariusz Skamra 296c76c7a8 Bluetooth: Fix status returned by bt_stop_scanning and bt_start_scanning
If the Command Complete status is read, this status shall be returned.

Change-Id: Ic3fe102c16da4b01d002a2d39952fd401e9f832d
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:34 -05:00
Luiz Augusto von Dentz 96fbd6636c Bluetooth: Add bt_gatt_exchange_mtu
bt_gatt_exchange_mtu can be used to exchange MTU used by GATT, the MTU
is selected automatically based on the amount of data bt_buf can hold.

Change-Id: Id49a506663d922132e81c0a753a983b93579ffd0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:34 -05:00
Anas Nashif ea0d0b220c doxygen: change comment style to match javadoc
The change replaces multiple asterisks to ** at
the beginning of comments and adds a space before
the asterisks at the beginning of lines.

Change-Id: I7656bde3bf4d9a31e38941e43b580520432dabc1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:32 -05:00
Anas Nashif 20764a2e8d doxygen: javadoc style
Change all occurances of /*! to /** to match javadoc
style.

Change-Id: I3a759d34e0e928216f61252682266e64c5b875f8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:32 -05:00
Mariusz Skamra 30b50a3227 Bluetooth: Cancel pending connection
Adds HCI routine to cancel creation of outgoing connection.
bt_disconnect is called to cancel connection or disconnect based on current
connection state.

Change-Id: I462a61308a580bb24aa9a6c398eb7e443b995655
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:31 -05:00
Arkadiusz Lichwa b62f778664 Bluetooth: Start outgoing connection with tracking
Enables make outgoing connection with error handling.
Free connection objects maintained in polls are assigned to active
connection by result of lookup on the polls based on input
peer LE address.
Updates shell application to reflect above changes in stack.

Change-Id: Ibc71343c0d122cc78c48bac2ff1e50533369b7d2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:31 -05:00
Szymon Janc a14314e913 Bluetooth: Move security related code to bluetooth.h
Also rename bt_conn_security function to bt_security and
bt_conn_security_t to bt__security_t.

Change-Id: I543c7b97241c4389ef0eb491b6869f93105ae533
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:31 -05:00
Szymon Janc 3e1023cdcd Bluetooth: Remove 'none' security level
This was same as low security and is not needed. This also match
security levels with LE Mode 1 security level from Core Specification.

Change-Id: Ia82e1f4d94c281d7e7f88f03a16a1e34eb49f710
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:31 -05:00
Szymon Janc bd0642958b Bluetooth: Add doxygen for bt_conn_security
Change-Id: I8d2f609e803931bc5cd4c8cd60a017b1956eb726
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:31 -05:00
Szymon Janc 1fc691ed42 Bluetooth: Add support for sending HCI LE Start Encryption command
This command will be used to enable encryption when acting as master.

Change-Id: Iaaf1d5b98bfcfcf17a5cc7006a6c40d0905011fd
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:31 -05:00
Szymon Janc 81a4dbcf8f Bluetooth: Allow to set required security for connection
This adds bt_conn_security function that can be used to elevate
security on connection. If device is not paired it will trigger
pairing first.

For now only JustWorks pairing is supported so full security level
tracking is not needed as only medium level is supported.

Change-Id: I6d344f55286a79bd989bd18f852a6859dc8ea96a
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:31 -05:00
Luiz Augusto von Dentz 016f6e7d6a Bluetooth: Replace peer address with conn in GATT API
Now that bt_conn is public using it directly is much more convenient
and in some cases save a lookup by address.

Change-Id: Ia489948634984fe4f1a430da553f8a2a740fb531
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:30 -05:00
Luiz Augusto von Dentz 207402006a Bluetooth: Reorder GATT struct members to avoid padding
This makes sure the bigger members are always list first in non-packed
struct to minimize the use of padding for alignment by the compiler.

Change-Id: I64419e9b27f4e7d3abb4eeb0ef2a88beda5b22e3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:30 -05:00
Peter Mitsis 9f084d7d33 Typo: acknowledgement -> acknowledgment
Changing the spelling to comply with the checkpatch tool.

Change-Id: I7f28fd73bfbc89d91e4d7caccffa2c018dcadf6d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:14:28 -05:00
Arkadiusz Lichwa ac98b4e221 Bluetooth: Handle update connection parameters
When connected, the peripheral/slave can trigger changing connection parameters.
Handle such request on central/master and if needed update controller settings
regarding the relevant connection parameters.

Change-Id: If3c1d91752f8d3875918bd8bfe923330790f530e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:24 -05:00
Szymon Janc 441e01ec04 Bluetooth: Add bt_conn_get_dst function
This function allows to pick connection destination address.

Change-Id: I3e4959eec00905c64de3d8b9ef810b613c2e9f91
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:24 -05:00
Johan Hedberg 5a72e9aaaa Bluetooth: Add doxygen documentation for buf.h
Change-Id: Ia60227e9f960f9563c82cdc4a044a2f9a538331c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:24 -05:00
Johan Hedberg f77d80121e Bluetooth: Clean up doxygen documentation in gatt.h
Change-Id: Idc554e46f5806b4b7bf84f9d5c4ac8a46fdd7888
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:24 -05:00
Johan Hedberg 640a8cdc96 Bluetooth: Add doxygen documentation to conn.h
Change-Id: Ifb7b7c5bf089590059aa97f498751679e34ae35e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:24 -05:00
Johan Hedberg 32388b9a5f Bluetooth: Clean up doxygen documentation in bluetooth.h
Make the documentation style consistent and add documentation to
functions that were missing it.

Change-Id: I1822480a604bb2efcb0dbfc63ae0675ebf4b5987
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:24 -05:00
Johan Hedberg 55218cd6de Bluetooth: Be consistent with the spelling of 'Bluetooth'
Change-Id: Ic9cbfe792f0b46071e38b52d1e082ce1da83e708
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:24 -05:00
Arkadiusz Lichwa 1d748ba760 Bluetooth: Address conversion user helpers
Adds user helper functions dealing with formatting bluetooth
address.
Refactors internal helpers using public ones.

Change-Id: If7b9f9a93b2aef3d25df55d6cfae9de05d8830b0
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:24 -05:00
Arkadiusz Lichwa d81689e915 Bluetooth: Introduce LE scan callback
Enables sending LE discovery results to user app.
Updates central apps to use new scan API.

Change-Id: Id319c96e15554f2eed4cf507cddd114ca74aa8e5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:24 -05:00
Luiz Augusto von Dentz 168446d058 Bluetooth: Disable GATT notifications while disconnected
Once disconnected disable CCC configuration and enabling it back once
reconnected:

bt: bt_gatt_disconnected (0x0010c610): conn 0x0010a1f4
bt: disconnected_cb (0x0010c610): ccc 0x00108e44 reseted
Disconnected
Connected
bt: bt_gatt_connected (0x0010c610): conn 0x0010a1f4
bt: gatt_ccc_changed (0x0010c610): ccc 0x00108e44 value 0x0001

Change-Id: Ia4ac6793176f80ea9c6f255a4d151f9080660b0d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg ea15db12ba Bluetooth: Make bt_conn_lookup_addr_le public
This API is useful for applications wanting to monitor and disconnect
connections.

Change-Id: Ib1a98ece364f137262515fbb1163c6b08ddf792c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Mariusz Skamra 0b501a1f5c Bluetooth: Add defines of HCI error codes
Adds defines of HCI error codes used in HCI disconnect command.

Change-Id: If06f9342338cf88209c20856b41675f45184b89f
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg fe669a52e8 Bluetooth: Clean up document style in bluetooth.h
Change-Id: Icd5cbda6ff73b7f4b2d6a4183bb23138fd1ad0be
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 8c26ce63d1 Bluetooth: Remove bt_hci_reset() API
There's no clear need for this API (at least for now) and supporting
it means we really need to get all state cleanup procedures correct.
Remove it for now.

Change-Id: Ia2c7d51d410117bef12bc08f4f97a4e38ccfb77a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 9bea2c3cfc Bluetooth: Move HCI driver API to dedicated header file
This makes it clearer that this is a specialized API not intended for
general app usage (unlike most other things in bluetooth.h).

Change-Id: I0ce1d5903610a9b3a99cf0be9f0e1462b04bf45a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 939544b75d Bluetooth: Move logging helpers to a dedicated header file
To make it clearer that these helpers are intended only for
Bluetooth-subsystem internal code, move them to a separate file.

Change-Id: Iea64780f5c61c1c96e12c9df378676bc49498fe4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg c816923003 Bluetooth: Add missing stddef.h include for size_t
Change-Id: I716382a9d29f39cf6d3b94e66df0c4db3ff1156c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Szymon Janc 19fe40764c Bluetooth: Make bt_stop_scanning parameters explicit void
Change-Id: I47ece76e00719d2fef702763c061055a1e9c5f76
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:23 -05:00
Luiz Augusto von Dentz 32eb9150f7 Bluetooth: Make Bluetooth UUID defines consistent
Always prefix UUIDS for characteristics with service name.

Change-Id: Ic435fa725e6bc8918af631632156b071121cd0e0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:23 -05:00
Luiz Augusto von Dentz f9281b7eef Bluetooth: Update documentation of Bluetooth UUID API
This makes use of new guidelines to document Bluetooth UUID API.

Change-Id: Ib4c96f97709610b762f6e839294a4db3ac447e73
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:23 -05:00
Mariusz Skamra b2574b645b Bluetooth: Terminate connection
Adds routine for termination of connection.

Change-Id: I444e4cba3297c51fbd9f89bbdba89db45af195c6
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:23 -05:00
Arkadiusz Lichwa f5ae4b70f1 Bluetooth: Add basic interface for LE connection
Adds internal HCI interface routine for creation of basic ACL LE link.
Most of the command interface parameters are fixed.
The internal interface is then used directly by simple public interface with
no connection validation.

Change-Id: I8ed72a9d01348e2a05b62facc9e85060e4500631
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 224abaab0e Bluetooth: Update bt_conn_cb to pass bt_conn instead of bt_addr_le_t
Now that we have a publicly exposed connection object it makes sense
to pass that to the connection callbacks rather than an address.

Change-Id: I8e9b17733d1789539a83c3dbc7a778336d2b71ff
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 2b61b44cbc Bluetooth: Add conn.h public header file
This one should be used for all public connection related APIs. Right
now it includes the reference counting and connection callback APIs.

Change-Id: Ib9b67e6115bb2e51322644757da1170851c3ca17
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Luiz Augusto von Dentz 15980aa2b8 Bluetooth: Fix typo in the GATT documentation
Change-Id: I61b05d10912020f2e8c396f13154e65cf482216a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:23 -05:00
Andrei Emeltchenko fab2d401a1 Bluetooth: Document bt_init and bt_start_advertising
Functions bt_init and bt_start_advertising are referenced in the
doxygen documentation. Documenting them gives better overview.

Change-Id: I70cb19a0a3232ce5abfb22c3a352bf3868c6f8fb
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 7250393678 Bluetooth: Add macro for CEP and long descriptors
Add BT_GATT_CEP and BT_GATT_LONG_DESCRIPTOR so which can be used by
a task to declare long attributes.

Change-Id: I37a0bb1851b60f3cdfa7e2f00ade70d5c344abbf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 66d6cf77ce Bluetooth: Fix GATT CEP not using 16 bits
Characteristic Extended Properties has 16 bits not 8 bits as value.

Change-Id: I307fd27a6d589d6614829df178ff890301a9b6be
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 14ff92cea0 Bluetooth: Handle ATT execute write request
This introduce a new callback called flush to bt_gatt_attr to indicate
when and attribute can cache data, the data is automatically flushed if
regular write request happens and in case of prepare write it checks if
flush is supported otherwise return an error, then upon receiving an
execute write it perform flush over the entire database and respond
with result:

< ACL Data TX: Handle 42 flags 0x00 dlen 6
      ATT: Execute Write Request (0x18) len 1
        Flags: Immediately write all pending values (0x01)
> ACL Data RX: Handle 42 flags 0x02 dlen 5
      ATT: Execute Write Response (0x19) len 0

Change-Id: I2c47f962858b8a741bf40509a648fe2cd6755691
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz 537e65b05b Bluetooth: Update documentation of GATT API
This makes use of new guidelines to document the GATT API.

Change-Id: I5544f449e11dd72c68b0efb15bd06db44ec30279
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:19 -05:00
Arkadiusz Lichwa df4257f174 Bluetooth: Track role for connections
When a connection is made, track its role.

Only peripherial/slave role may trigger update of L2CAP connection
parameters.

Change-Id: I72244581650248c7b020c9e5673b73ce46e7399d
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:19 -05:00
Luiz Augusto von Dentz aa1260999e Bluetooth: Fix persisting CCC config for non-bonded devices
The spec says that CCC shall only be persistent accross connection for
bonded devices:

  'The Client Characteristic Configuration descriptor value shall be
  persistent across connections for bonded devices. The Client Characteristic
  Configuration descriptor value shall be set to the default value at each
  connection with non-bonded devices'.

To handle this now each configuration has a valid field indicating if the
configuration is valid.

Change-Id: Id74ac54f5e23a7a0b286f90dbc9af4e9ee966dd4
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Mariusz Skamra 7f1bff8b2d Bluetooth: Add callbacks for connections
This patch adds callbacks to notify app about connection and disconnection.

Change-Id: If8091254d929fe53d12b153e6f216223a8913f2d
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg 451b105978 Bluetooth: Use __packed instead of the deprecated PACK_STRUCT
The PACK_STRUCT macro will be removed soon and __packed is what all
code should use. Convert all the usages in Bluetooth code.

Change-Id: Id5c724566565f67fa8167b61398c508194ece89b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg 1004e8bf19 Bluetooth: Reorganize buffer variable for smaller size
Reorganize and compress some of the buffer variable to achieve smaller
struct size.

Change-Id: I1ce711c22844470403b085b0f13e77f762f25262
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg 5e16f9b849 Bluetooth: Add missing include to gatt.h needed by ARRAY_SIZE
All public headers should be self-contained. Since gatt.h uses the
ARRAY_SIZE macro it should also include the <misc/util.h> header file
that provides it.

Change-Id: I1fea66d10f452e51d9af5f5c6c345b5bb5a92d00
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz 8c66427b05 Bluetooth: Add permission field to GATT attributes
This field can be used to set the required permissions for an attribute
which can be checked by Bluetooth core before calling the callback.

Change-Id: Idcab8cdc5744358fab0b3c67b9c0503f1d1d9736
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz 0b6eea8345 Bluetooth: Add Device Information Service to peripheral sample
Add Device Information Service along with model characteristics and
descriptor to the database table.

Change-Id: I28775cf48abe76d0a841ebc92e1579e2d4cdfa09
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg 4e25230204 Bluetooth: Add support for encrypt key refresh complete event
This event comes instead of Encrypt Change when we re-encrypt an
already encrypted connection.

Change-Id: I7fe9545e6c58392a34d72f3dd3962c475ebb7871
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg 5dd8fd7f91 Bluetooth: Add missing stdint.h dependency to buf.h
The public header file buf.h uses stdint.h definitions and should
therefore have the necessary include statement (since public header
files are supposed to be self-contained).

Change-Id: I9e2a9e13e5d2c35aa61c7552c3ba9fa73b8886a6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz e4e6f4dbe9 Bluetooth: Add bt_gatt_notify
bt_gatt_notify can be used to send ATT notifications:

< ACL Data TX: Handle 3585 flags 0x00 dlen 8
      ATT: Handle Value Notification (0x1b) len 3
        Handle: 0x0010
          Data: 64

Change-Id: I908f10f9e60dc7cef221e4b27c3b6e49e7b0cfc9
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz e8e0fbe63a Bluetooth: Add BT_GATT_CCC macro
BT_GATT_CCC uses _bt_gatt_ccc internal struct to handle peer
configurations and special helpers to read and write to minimize the
code necessary to handle CCC in the task.

Note this not yet include handling of connection and disconnection but
the idea is that the core would automatically disable the configurations
while disconnected and re-enable once peer connect back.

Change-Id: I89325b8a074766b9fd2423085565df669f7275e1
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz c6ce7792a7 Bluetooth: Add Bluetooth remote address to attribute callbacks
To implement CCC properly it is required to know the remote address since
it is per client, futhermore bt_gatt_notify requires an address where to
send the notification.

Change-Id: I9d9fdf72d668831bed76e2aef06816af3620f4b8
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz e7ac889bf0 Bluetooth: Fix codying style of EIR defines
Hexadecimal values should be in lower case.

Change-Id: Id79347997bab0673fb90f6f00ec9c2cff1440ee2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:17 -05:00
Andrei Emeltchenko 6a8ba74df5 Bluetooth: Add UUID definitions for Current Time profile
Change-Id: I7f953d0f4819924a1f08bbd495dcb3cf4adc1ee3
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:16 -05:00
Luiz Augusto von Dentz dd41c3375c Bluetooth: Add bt_gatt_foreach_attr
bt_gatt_foreach_attr iterates over attributes via callback, it will be
used to implement discovery functionality.

Change-Id: Ice66f4b3d0d12b3616986931d5da0fe0f202e533
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 862835d8a6 Bluetooth: Add bt_uuid_cmp
bt_uuid_cmp compares 2 UUIDs returning if they match, if the types are
different it converts both to 128 bit format before performing the
comparison.

Change-Id: Iacf330cc0271a7e5429cbb2f405a7d9ef249a1a3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz a8f34a1c1e Bluetooth: Add Battery Service to peripheral sample
Add Battery Service along with its characteristics and descriptors
to the database table.

Change-Id: Ifb83ebcb4d6cdafa5df84d643b2e2a69e5a6c1e3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz 1b793139db Bluetooth: Add Heart Rate Service to peripheral sample
Add Heart Rate Service along with its characteristics and descriptors
to the database table.

Change-Id: Ibff52da7352883edccb7c5b903538a81aad2ba55
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Luiz Augusto von Dentz de52b09a3f Bluetooth: Add GATT skeleton
This adds initial API and definitions to create a database.

Change-Id: I69d5b3f5fd2f04cc309c2f76a84581673aa54e7b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:04 -05:00
Johan Hedberg 9b40ec3360 Bluetooth: Introduce dedicated Bluetooth address types
We use addresses in lots of places and with LE we always need to pass
around the type in addition to the address value. Defining dedicated
types for addresses makes the code much simpler.

Change-Id: Ie8b495dce50e3f084685909c19acc5d08e2cca10
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Luiz Augusto von Dentz 0b21762db2 Bluetooth: Add enum for UUID types
UUID types don't come from any spec so it is safe to have a enum which
can be changed whenever we want.

Change-Id: I7549f3a487191eeb847a239936f882ff88f4d345
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:03 -05:00
Luiz Augusto von Dentz 7f6a66c04e Bluetooth: Move UUID code to its own file
UUID defines, etc, will be needed by multiple files including GATT.

Change-Id: I855d3934242f54a8b5bf31652a4f8b9dfb63ef06
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 62c82f0c97 Bluetooth: Add support for Encrypt Change HCI event
There will be various scenarios where we need to know what the current
encryption mode for a connection is.

Change-Id: I9836ffe51bfb6ebfc09497c7c716bd13a4064305
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 0821341d3f Bluetooth: Add support for responding to LTK requests
Add an event handler for LTK requests that looks up the LTK using the
new bt_keys API.

Change-Id: Ifc4e5f96e84026d7e8c68eacb64154dc0a9c72b3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg 6e20c3b838 Bluetooth: Move all logs behind CONFIG_BLUETOOTH_DEBUG
The BLUETOOTH_DEBUG config option bumps the stack sizes to cope with
printf requirements. Since all the logs use printf now they should
only be available with the bigger stack sizes to avoid surprises.
There are still basically two levels of log enabling where
BLUETOOTH_DEBUG enables the ERR/WARN/INFO everywhere and the
BLUETOOTH_DEBUG_* enables BT_DBG for a specific subset of the stack.

Change-Id: Ie8d64e47f44485efde32b40cd5bb34389c8e39da
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Andrei Emeltchenko fa77083bf4 Bluetooth: Fix printf specifier for debug
printf() '%x' expects type 'unsigned int' for 'x', but parameter has
pointer type.

Change-Id: Id2d365a32b2e3e711359bd56741370d8167db868
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko 9b9e9e66c5 Bluetooth: trivial: Fix coding style
Change-Id: Ie0bdad384ea353733bb37acd5422269cc49ea08b
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg d6600e075f Bluetooth: Include context ID in debug logs
Including the context ID in debug logs can help track down various
issues, e.g. stack corruption.

Change-Id: I3cd70edd5bfd1d726f6d35e7331afb313cf3cacb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 8930a13b60 Bluetooth: Prefer printf over printk
The printf API has a much richer support for various format
specifiers. Switch the Bluetooth logging macros to use printf instead
of printk and make sure STDOUT_CONSOLE gets selected when
BLUETOOTH_DEBUG is selected (so printf actually works).

Change-Id: I9a9818d51a677c6c79a35fef6daca7979f61c78d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg a648bbe9a1 Bluetooth: SMP: Add local random number generation support
The SMP procedures require us to establish a local random number. Use
the HCI_LE_Rand command to generate the necessary 16 bytes (the
command needs to be called twice since it only returns 8 bytes at a
time). Store this number in the SMP context.

To help debugging with various crypto related values add a local h()
helper function for printk/BT_DBG to do hexadecimal conversion.

Change-Id: Id3e8793a77ac635023b3cc3a94e8679170455870
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg 19707e8257 Bluetooth: Use 'void *' also for bt_buf_pull/push return value
To make the bt_buf APIs consistent with the recent bt_but_add changes
and more user friendly, change the pull() and push() return values
also to 'void *'.

Change-Id: I25242635c87882db99152735c22316d4de00d363
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg d6a03600b2 Bluetooth: Change bt_buf_add return type to 'void *'
Almost all callers of bt_buf_add end up having to do explicit type
casts of the return value since 'uint8_t *' rarely fits what's needed.
Changing the return type to 'void *' removes this extra type casting
need and makes the API friendlier to its users.

Change-Id: I6a79605006153b6d09f0d662a051cb599af68c37
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz d1b61254f3 Bluetooth: Add bt_buf_pull_le16 helper
bt_buf_pull_le16 convert the initial 16 bits to little endian.

Change-Id: I6f6e9d63fc19b0579d9f445e15e975929fc63ba9
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Yonattan Louise d133f9661d Fix checkpatch issue - WARNING:SPACING
This commit fixes the issue marked as SPACING by the checkpatch script
deleting the whitespaces between the function name and the open parenthesis.

Change-Id: I972b1646904bf6e1131263f94ab5024a528ae07d
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:13:59 -05:00
Arkadiusz Lichwa e60b8f1927 Bluetooth: Intro of basic ADV handler
Adds basic handler deserializing advertising data.
Adds helper reformat function.

Change-Id: I6385249c39e92b2f068a01e89d34530b7a321f34
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:13:58 -05:00
Arkadiusz Lichwa d46de84c03 Bluetooth: Create basic LE scan interface
Adds needed data structures.
Adds basic HCI interface to start/stop LE scan.

Change-Id: I69790b11d191078952ce05da386961c5c55a7172
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:13:58 -05:00
Andrei Emeltchenko 94fc5b27c5 Bluetooth: Add definitions for LE Encrypt command and reply
Add definitions for implementing HCI controller encryption.

Change-Id: I4e919c8a081c9e61174e6b08f5b2ac088e4b1a4d
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:13:57 -05:00
Luiz Augusto von Dentz b3cdfed003 Bluetooth: Extend advertising API
Extend bt_start_advertising to make it possible to add any data type
instead of just the name.

Change-Id: I3f2afe1eb64aec51f321f7fd7439e97b3d67374c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:56 -05:00
Luiz Augusto von Dentz 77db73142a Bluetooth: Add advertising data types definitions
Adds remaining AD types definitions that can be used in BLE.

Change-Id: Ic9c63a111a5269a53326005012dff955cf399fcf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:13:55 -05:00
Johan Hedberg fbe3a4634d Bluetooth: Add return parameter support to bt_hci_cmd_send_sync()
Instead of having global command completion handler we can keep the
code more concise by letting bt_hci_cmd_send_sync() give back the
return parameters straight to the caller. This patch extends the
buf->hci.sync variable to not just contain the initial semaphore, but
to have the return parameter bt_buf once the semaphore is given back.

The bt_hci_cmd_send_sync() function receives an extra parameter which
may be NULL if the caller isn't interested in the return parameters.

Change-Id: I41e3e4b1189c4a19d0159947a03fd7052cc98fa9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 89a083f888 Bluetooth: Add reference counting for buffers
In certain scenarios we want to keep the buffers around for longer
and avoid the default bt_buf_put() calls from putting them back to the
available buffers queue. This patch adds reference counting for the
buffers, along with a bt_buf_hold() API to increment the reference
count. Now bt_buf_put() will only put the buffer back to the pool if
the reference count hits 0.

Change-Id: I1590c5574e18600939f55e5339a6da3d061f7682
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Andrei Emeltchenko b3e25209a8 Bluetooth: Add BLUETOOTH_DEBUG configuration option
BLUETOOTH_DEBUG option enables extensive debug output to serial
console. Disabled by default.

Change-Id: I71a6ca4c4f1dfb5bd818e6b8320a07249befadfb
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 50a25dcfd3 Bluetooth: Add BT_WARN convenience logging macro
Some logs indicate potentially problematic situations but are not
necessarily errors. Since we do want to log these regardless of the
debug setting it's better to have a separate BT_WARN macro for them.

Change-Id: Iad13fc4b58329113458c97b02855033836618f5b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 041c84c3e6 Bluetooth: Introduce dummy data type
We're already sending 'dummy' buffers to wake up the connection
fibers. The problem is that if we provide a real buffer type it may
have unintended consequences. E.g. with BT_ACL_OUT when bt_buf_put()
is called it may trigger an invalid HCI_Host_Num_Completed_Packets
command.

This patch creates a new BT_DUMMY buffer type to avoid this scenario.
The new type is an alias for BT_CMD since the pool where these buffers
come from is not quota-controlled and synced up with the controller.

Change-Id: I42ac235811dc242345853f7858c10bfc43e4f07d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 586d76b12a Bluetooth: Add support for reporting completed ACL buffers
Every time we put a BT_ACL_IN buffer back to the pool we should report
this to the controller so it knows it can send us more data. This
patch makes the necessary modifications to the bt_buf_put() function
to trigger the HCI command.

The Host Number of Completed Packets command is special in that it
doesn't need to obey the reported ncmd value and also doesn't generate
any command status/complete events. Because of this we need an
exception for it in the bt_hci_cmd_send() function.

Change-Id: If65f28078fd0d81af853447e95bc53822fea75b7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 39a6c7df9b Bluetooth: Enable controller to host flow control in HCI init
To start supporting controller to host flow control we need to tell
the controller our supported packet count & MTU and send the enabling
HCI command. This patch does the necessary addition to the HCI init
procedure.

Change-Id: I51a66f8cc3a85782a5085f9aae0f4aeb59decad3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 25af03265c Bluetooth: Add ACL user data to bt_buf
To track which ACL handle each buffer belongs to (needed for host flow
control) add the necessary information into a new ACL-specific struct.

Change-Id: Ie6cc7c32a70b43a4ff5954bb9dca34e4f62da292
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 5626788eb7 Bluetooth: Refactor buffer HCI user data
To accommodate for ACL user data move the HCI command/event data into
its own struct and put it inside a union in bt_buf.

Change-Id: I680500b15709d14b1e9f70ced88664d607a6568c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg b6804df02e Bluetooth: Split buffers into separate pools
In order to do proper flow control of ACL data to/from the controller
we need to have precise management of the available buffers. Mixing
with the events/commands buffers would make this impossible. This
patch splits the buffer pools into three separate ones:

	1. HCI commands/events
	2. Incoming ACL data
	3. Outgoing ACL data

The total number of available buffers is also increased to match
what's the smallest number supported by current controllers (to avoid
the stack from becoming a bottle neck).

Change-Id: I7e131d61c83a4dda554068d7917c5ee09f2f837d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg d829fe9755 Bluetooth: Consolidate bt_buf_get* functions
We may soon want to have a _wait() variant of bt_buf_get, so to avoid
the number of 'get' function growing too large consolidate the
existing get() and get_reserve() functions into a single one. The new
consolidated function also takes the type as input parameter so that
we know this from the very start and thereby plan for the split into
multiple buffer pools.

Change-Id: Ia09448565349def2be9bc08d9510fedd029480b4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 4e65d0aac2 Bluetooth: Split ACL buffers into two distinct types
We'll soon want to have dedicated pools for outgoing and incoming ACL
data. To know from which pool to get and put the buffers each buffer
should contain enough information to distinguish the two types. This
patch splits the old BT_ACL type into two new BT_ACL_IN & BT_ACL_OUT
types.

Change-Id: I7d3c05c26d2a70f80fb1229e245aa21673ec378b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 550cdd9717 Bluetooth: Add dependency includes to hci.h
The hci.h header file depends on the integer type definitions from
stdint.h and the PACK_STRUCT macro from toolchain.h. This patch adds
those so that users of hci.h don't need to be concerned of this
detail.

Change-Id: Ib1856cdec75a3bab1b86bc832cdec6ad0461db6d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 429240d376 Bluetooth: Move buffer handling into a dedicated file
The buffer handling code is quite large and will continue to grow. As
it's not strictly HCI core material it's better to just manage it in a
separate file. This patch moves the code to include/bluetooth/buf.h
and net/bluetooth/buf.c.

Change-Id: Ie1ff79ac2cfa132359ce9f7674ff812d34b228aa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:50 -05:00
Johan Hedberg 58c5689531 Bluetooth: Add skeleton for handling disconnect complete events
This patch adds a simple event handler for the LE Disconnection
Complete HCI event. An extra thing the handler needs to do is to
re-enable advertising if necessary, since it will have been implicitly
disabled by the controller upon a connection event.

Change-Id: Ie6f2eecb8c1d7de16fea24c8fd1533545f41baa5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg 391260d03c Bluetooth: Add skeleton for handling LE conn complete event
This patch adds a basic event handler for the LE Connection Complete
HCI event.

Change-Id: Iea099fe1b8c87fcd00d13e8793ebce8ced7adec6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg 3739760dc2 Bluetooth: Add skeleton for handling LE meta event
All LE related HCI events come wrapped in a LE Meta 'super' event.
This patch adds a basic event handler for it.

Change-Id: I4a037d4af080c3ba0f982586065c0c49b6cf7640
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg f64e3c08b2 Bluetooth: Add semaphore for counting controller-side ACL buffers
We shouldn't be sending more ACL packets to the controller than it
is capable of accepting. This patch adds a semaphore to track the
number of available controller-side ACL buffers.

Change-Id: Ib280afa06aade68eee03e44e33624eebb700dad5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg a6fbfe4bc1 Bluetooth: Add simple advertising enabling API
This patch adds a simple API for enabling advertising and specifying
the friendly name in the advertising data. The API is probably not a
final one but fulfills the initial need to create apps that are able
to act in the LE peripheral role.

Change-Id: I3ff7e72ece377d872ef1b0e4ad44aeb293cc13e5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg 7bfbe7abf2 Bluetooth: Add basic advertising definitions
To manage LE advertising we need basic HCI definitions for the
commands and events involved. This patch adds those to the hci.h
header file.

Change-Id: Ic6cf17369ad09d97ca5c098f25ba786d265d0bfd
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:49 -05:00
Johan Hedberg d210d306d7 Bluetooth: Add full HCI initialization routine
This patch adds a full HCI initialization routine to retrieve all
relevant information from the controller.

We also need to introduce a new blocking bt_hci_cmd_send_sync() API
since some commands are conditional to the results of others. The API
is implemented with the help of a semaphore that's part of the
command's bt_buf struct. We wait on the semaphore and get it back once
the command has completed (with the help of the hci_cmd_done
function).

The patch also adds variables for storing various controller specific
parameters which will be needed later during the operation of the
stack. These variables are part of 'struct bt_dev' and get updated
through the respective command complete handlers.

A new bt_hci_reset() API is added which allows an application to reset
the controller state at any time by re-running the HCI init procedure.

Change-Id: I5b1a38e910d79ad5fe806467bc51388eedc9c8f9
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg 23a0df8b9b Bluetooth: Add HCI driver API
This patch adds a basic HCI driver registration API along with a fiber
to process data from the driver. A FIFO is used for receiving data
from the driver and waking up the respective fiber. To open and set up
the HCI transport for operation there's an open() callback passed to
the HCI core. This function will be called as soon as an application
initializes Bluetooth functionality through bt_init().

Change-Id: I780cca517a0dfc714f1ca35527e1c61e307345a0
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg 64b117a9b1 Bluetooth: Add support for HCI data buffers
In order to manage incoming and outgoing HCI data (events, commands &
ACL data packets) we need to have some way of storing this into
buffers. This patch implements a 'pool' of buffers with the help of
the nano_fifo API. The pool is initially populated with all available
buffers. After this code can on demand request buffers from the pool
with the help of bt_buf_get() and return buffers back into the pool
with bt_buf_put().

Since we don't always know the execution context from where the API is
operated on, this patch also adds convenience fifo_get/fifo_put
wrappers that look up the exact context before calling the correct
nano_fifo API.

Change-Id: Ie7f6d450de865273171e21a000d5a14274d27d32
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg 63e9480399 Bluetooth: Add basic HCI definitions
For performing a basic HCI initialization procedure we need
definitions for the related HCI commands and events. This patch adds
these into separate hci.h header file. More content will be added to
this file as corresponding functionality gets added to other areas of
the stack.

Change-Id: Ida7555cb0a3d30b8a44324cb14699eba8a1bcdee
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00
Johan Hedberg ac63429177 Bluetooth: Add skeleton for HCI core
To introduce the Bluetooth stack to the tree we need some additions to
the configuration options, as well as the very basic header files. The
patch also adds a skeleton for a bt_init() function that applications
will need to call to initialize Bluetooth functionality.

Change-Id: Ideb24dfea584b71f514e05eb47654b659776133e
Co-authored-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:13:44 -05:00