Commit graph

18576 commits

Author SHA1 Message Date
Johan Hedberg
6140bd04fe Bluetooth: Store full LTK information
We also need to store the EDiv & Rand values to be able to do correct
look-up of LTKs.

Change-Id: If6dbfc7569d18a4c8597a401deccad3ef8cb51ad
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
2469d04ce2 Bluetooth: SMP: Update le_rand() to support arbitrary sizes
We'll soon need to generate other amounts of random bytes than 16.
Update the le_rand() helper to generate any amount of random bytes.

Change-Id: I9295e6e3d79b0577c7bced31604a0fa45f1a9424
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
764dd444e5 Bluetooth: Fix coding style (missing braces)
Change-Id: If96f4ce601499345e8e29143a03742594cac35af
Signed-off-by: Johan Hedberg <johan.hedberg@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
5c9421ff32 Bluetooth: Move SMP & ATT contexts to protocol specific files
Now that we have the connected/disconnected callbacks available for
L2CAP channels we can use these to associate the bt_conn with a
respective protocol-specific context.

Change-Id: I7c4d9a54f73ae7029a73372a1b0c93d473b28881
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
7650dabdab Bluetooth: Add L2CAP callbacks for connection state changes
Add callbacks to notify L2CAP channels of connections, disconnections
and changes in the encryption state.

Change-Id: I66f86f20f551f01459abdbec6ccd214992828470
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
0b099acb4c Bluetooth: Add registration mechanism for L2CAP channels
We'll either way need various callbacks as well as get rid of the
channel-specific contexts in conn.h, so add a dynamic way of
registering fixed channels. The LE signaling channel is handled in the
same way as any other channel.

Change-Id: I5f8c1af3c8e3d107212becf507a5a6485838e081
Signed-off-by: Johan Hedberg <johan.hedberg@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
066a0e103c Bluetooth: Fix handling of connect/disconnect_complete events
The handles do not need ACL data-like decoding and the handlers should
be no-op for any non-zero status.

Change-Id: I40006ef7e5d01e8841ae0bebeda87755b2a32938
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
8aec59f010 Bluetooth: Use more appropriate printf format specifiers
Now that the logging macros use printf we can use more appropriate
format specifiers for various values.

Change-Id: I01025133b6a075f3478957a60163a1574cd85df7
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
3075658253 Bluetooth: SMP: Store STK using new bt_keys API
Take advantage of the new bt_keys API to store the generated STK.

Change-Id: I7dc20c8581e55a98f2f4f804d3a01bc636364ad0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
619bf02559 Bluetooth: Add runtime storage & API for pairing related keys
Add runtime storage of pairing related keys, along with a config
option to control how many pairings are supported.

Change-Id: Ib5177d2b6fbb0d2d458b539a3f1095c1dce135ff
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
7ce57dd762 Bluetooth: SMP: Implement key generation function s1()
The s1() crypto function is used to generate keys for SMP Legacy
Pairing.

Change-Id: I839cb8210d8babe64551f8d958c97d0addd459b4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
5190c37967 Bluetooth: Make max supported connection count configurable
Add a kernel config option to specify how many simultaneous
connections can be supported.

Change-Id: I963aacb7cece3436ecd5049683a19a350224a156
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg
63552b1485 Bluetooth: Add error logs for bt_init() failures
These may help debug early initialization issues.

Change-Id: I18a8043b2da46ec50f03fedfce46e48d9b41b373
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
44e67698a6 Bluetooth: Move L2CAP header encoding to sending stage
Encoding the L2CAP header when allocating the buffer means that we
must know the final size up-front. This is not always possible, so
move the header encoding to bt_l2cap_send() and only have the
bt_l2cap_create_pdu() function reserve enough headroom without
actually encoding anything.

Change-Id: Ic1c3b6b72c265cd0db4e835790fa915e0acd9388
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
e104fa5928 Bluetooth: Fix accounting for driver header in ACL MTU
When we notify the controller of our ACL MTU we should subtract from
the buffer size not just the ACL header but also the headroom reserved
by the driver.

Change-Id: Id05b1becab3682425f9b591217ac29659a13a6d0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
80824d459e Bluetooth: Fix coding style (too long lines)
Change-Id: I6573eee755d26290626e1a44a5f56fe56b92c55c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
60cf3146f7 Bluetooth: Fix minor typo in debug log
Change-Id: I0478e22b69d7a0ed5f5c642aa651cd58810aa035
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
7f9aeeb2e8 Bluetooth: Add debug logs to connection data path
Add debug logs to the rx/tx fibers so issues relating to them can be
more easily debugged.

Change-Id: Ie02d3e760772a3e47ff495c47d83b23744202941
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
24a0e0eeb5 Bluetooth: Improve debug logs for HCI core data paths
Add debug logs to the HCI core data handling to catch potential
issues.

Change-Id: I39bd3aeec9ed7b64156a9e2e899a153c0d484f38
Signed-off-by: Johan Hedberg <johan.hedberg@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
c533552497 Bluetooth: Increase fiber stack sizes when debug is enabled
The debug logs may cause a considerable overhead to stack utilization
(especially with printf). Increasing the fiber stack sizes when debug
is enabled decreases the chance of stack overflow.

Change-Id: I26e96c6516e0c1210e787cc5491fd5d59cbc75db
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko
3933278948 Bluetooth: Add ARM configuration for shell app
Change-Id: Ifa5bd8c82e4accd3778b45d7bb1af71b058c77e7
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Arkadiusz Lichwa
022d67096d Bluetooth: Initialize LE ACL MTU to proper value
Fix stack initialization.
When LE read buffer size returns 0 length LE buffers and controller
supports LE & BR/EDR functionality then ask controller about max ACL data
length it can accepts using BR/EDR read buffer size.
It should return value that can initialize LE MTU if that one still has 0.

Change-Id: Ib0bce89d47de5549d629a4ce771325e640443378
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko
87139e5e87 Bluetooth: Add peripheral app quick test to bt_regression
Build peripheral app for targets: pentium4 and ti_lm3s6965

Change-Id: Id98c94217ad39e1716b8f8bc6031b8814bae06f3
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Andrei Emeltchenko
b428ef6d65 Bluetooth: Add ARM configuration to peripheral app
Change-Id: I23428811de2d825c75a3938354b1079550ba3911
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz
18af2d839b Bluetooth: Make local variable static in peripheral sample
Change-Id: I6ce9a8ccab3461c8e7bbd15b2b129c01c5bdaa9e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
a60a4aba2e Bluetooth: Fix includes for sample apps
Update the includes in the sample apps to match what their actual
dependencies are.

Change-Id: I6fdfa4ba0cda563433d51f0ec35fef8f2ee0fa40
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
5071a46ac8 Bluetooth: SMP: Add full Pairing Confirm & Random handling
Add tracking of the confirmation values, remote random value and the
temporary key value. This also involves implementing the SMP e()
function with the help of the HCI_LE_Encrypt command.

Change-Id: I4cdad917e9689bbe16cd908941d0335c1c33f870
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
1e5efb9fb7 Bluetooth: SMP: Store original pairing req/rsp values
These values are needed later in the SMP pairing procedure as inputs
to various crypto functions.

Change-Id: I68334ed6d32625c4e7e0668300844af09018e126
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
38a7d345ae Bluetooth: SMP: Fix minor coding style issues
Add missing braces to a couple of one-line branches.

Change-Id: Ie4d703eede3cc03b823bd0a0764a5b999f317322
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
653378d031 Bluetooth: Track remote address for connections
We'll need to know the remote address for connections e.g. when
performing SMP based pairing.

Change-Id: I7e398a75c2418ec534b3cac15ab72f76586c2e9b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
4dae513d4b Bluetooth: Add contexts for SMP & ATT specific data
All fixed channels will need per-connection contexts. Right now in
addition to the L2CAP (LE) signaling channel the other two fixed ones
are ATT and SMP.

Change-Id: I56dda6b903ef703e453438e03a99c704aa77899a
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
19deebbecf Bluetooth: Move L2CAP context into dedicated struct
In preparation for having per-fixed channel contexts move the L2CAP
signaling channel specific data into a dedicated struct.

Change-Id: Iaacb5e1c7408be67740434f31ef56f94706ad327
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:02 -05:00
Szymon Janc
62267639ac Bluetooth: Fix not waiting for all commands to complete on init
For LE-only controller init procedure should wait for last HCI command
(Set Controller To Host Flow Control) to complete before returning.

Change-Id: Ic01e0cbaebf19d61560faab2ae01205c2eb22b77
Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
2016-02-05 20:14:02 -05:00
Johan Hedberg
46372d712c Bluetooth: Fix missing bt_buf_pull when parsing adv report
The code would only have worked for reports with num_reports being
equal to 1. Any event with multiple reports would have been
incorrectly parsed because of a missing bt_buf_pull() for the initial
one-byte num_reports value.

Change-Id: I0ac92edb792d559fb8ff84e40a4b4766f46afe58
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
90b27c478d Bluetooth: Remove unnecessary bt_buf_add type casts
Now that bt_buf_add() returns 'void *' there's no need to explicitly
type cast its return value anymore.

Change-Id: I6d5c9d323dc08cb5a2b928977c1bbf3d741e5d8e
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
dd52c0109f Bluetooth: Make use of bt_buf_pull_le16
Remove the memcpy code and instead use bt_buf_pull_le16 for unaligned
access and byte order conversion.

Change-Id: I0216042566e27d6a513b302ae1ea78b49f2f1c31
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@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
Luiz Augusto von Dentz
009899116d Bluetooth: Fix missing braces in ATT code
Change-Id: Icc241250a357efb06614d841cc37de77dddece2e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:02 -05:00
Luiz Augusto von Dentz
09f8409bfe Bluetooth: Fix using wrong PDU in handlers
Both Write Command and Signed Write command should use their respective
packed struct.

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