Commit Graph

1069 Commits

Author SHA1 Message Date
Szymon Janc 05bdba7768 Bluetooth: Fix clearing BT_DEV_ENABLE on HCI reset complete
BT_DEV_ENABLE flag value must be preserved after HCI reset is complete
to not allow calling bt_enable more then once.

Change-Id: I77bf6111d4fc2a209e0c5a56717decba156068a6
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-06-02 13:37:25 +00:00
Andrei Emeltchenko d9033386bf Bluetooth: log: Enable STDOUT_CONSOLE for printf support
The Bluetooth logs use format specifiers available with printf but not
with printk. Selecting STDOUT_CONSOLE enables printf support, which
makes the logs readable again.

Change-Id: I3e86f0bcf31688148a340eba6cdf33e81c64393d
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-06-01 08:21:29 +00:00
Luiz Augusto von Dentz 4290cf3b77 Bluetooth: SMP: Make use of nano_delayed_work API
This replaces use of delayed fiber with nano_delayed_work which uses the
system workqueue fiber and stack.

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

Change-Id: Ib2974d1331f6c91d119a218ec95e8bf01069377b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-06-01 05:04:10 +00:00
Szymon Janc d1d0ee7b2d Bluetooth: Allow to call enable function only once
Currently enable procedure can be called only once regardles if it
failed or succeeded.

Change-Id: I3869e97442720860baba7bb1b7610738ca95561a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-31 11:37:12 +00:00
Szymon Janc 31912bcb23 Bluetooth: Constify bt_register_starage parameters
There is no need for struct bt_storage being modified by stack.

Change-Id: I732cf94983a29de40d692e802d6a71b8986708df
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-30 12:57:24 +00:00
Szymon Janc 515ec20a06 Bluetooth: SMP: Fix not waiting for remote DHCheck
When doing LE SC pairing with Passkey Confirmation slave must wait
for remote DHCheck before doing comparison. This fix issue with
pairing as slave when passkey was first confirmed locally.

Change-Id: Iba780836341a944997adde24285b2e650b31afa1
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-30 09:37:06 +02:00
Szymon Janc d7ae97de69 Bluetooth: Fix sending DHKey event if invalid key was provided
bt_recv should be used to send event back to stack.

Change-Id: I092e2480b3f0e5c40c0751c30be46d0310012bae
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-30 09:37:06 +02:00
Kumar Gala 9ec2f3be80 Cleanup whitespace in Kconfig files
Convert leading whitespace into tabs in Kconfig files.  Also replaced
double spaces between config and <prompt>.

Change-Id: I341c718ecf4143529b477c239bbde88e18f37062
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-05-25 13:28:07 -05:00
Johan Hedberg 942bbadbf6 Bluetooth: Increase HCI_LE_Rand delay for Arduino 101
20ms doesn't seem to always be enough.

Change-Id: If5ff255d3f043e50e6e1d9ff481607dc17c604d1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-25 11:32:31 +03:00
Szymon Janc 7a82d7f661 Bluetooth: Offload bt_recv to fiber if run from task
Task can be preempted and bt_recv is expected to be atomic. Since
on microkernel with TinyCrypt ECC enabled this can be called from
task context we need to make it run in critical section.

Change-Id: I24414e8d98b0dfe8affc18058eb164ba0cba7b17
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-25 09:52:08 +02:00
Szymon Janc 684ffd1e23 Bluetooth: Offload ECC calculations to task
If TinyCrypt ECC is used for LE SC calculations need to be done
in task to avoid hogging CPU from non-preemptible fiber. To keep
upper layers of stack independent of crypto used (TinyCrypt or
controller) this patch adds HCI ECC emulation.

If ECC emulation is enabled it is always used regardless of ECC
support being present in controller.

Change-Id: I7c5ca873a18c10237e1c0b2f09e6da2a75fb334e
Origin: Original
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-25 09:52:08 +02:00
Arkadiusz Lichwa ade99e7e79 Bluetooth: L2CAP: Handle disconnection request from peer
Adds functionality to clean and release allocated BR/EDR CoC channel
after remote requests to disconnect.

Change-Id: Ie6657b8e72b2958ec79e9a5637f0dddf4bb98a5e
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-20 06:54:10 +00:00
Arkadiusz Lichwa a5d96e3f84 Bluetooth: L2CAP: Refactor l2cap_chan_get() in l2cap.c
Simplify l2cap_chan_get() in l2cap.c file by removing
CONFIG_BLUETOOTH_BREDR preproprocessor check. Now function serves
only getting channel on LE transport.

Change-Id: I20b72f352ad9d5998cc812b28cb3d6951f91f212
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-16 17:00:11 +02:00
Arkadiusz Lichwa 2145907d84 Bluetooth: L2CAP: Handle information response command on BR/EDR
Adds support getting L2CAP information about remote features. To get
the response local stack gets call information request about 'extended
features supported mask' after ACL link is established. Then in
response if 'fixed channels' bits are enabled, next information
request is sent to get details about 'fixed channels'.

Change-Id: I4980c61b12e83fef914e97dea296b0a848d59034
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-16 17:00:11 +02:00
Arkadiusz Lichwa 343789b3a8 Bluetooth: L2CAP: Rename context type bt_l2cap to br_l2cap_br
Let's keep BR/EDR L2CAP channel context type naming aligned to
naming convention applied in l2cap_br.c file.

Change-Id: I2c67e3525ade37a57cf96b0e3841fbd1cb9b783c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-16 16:11:14 +02:00
Arkadiusz Lichwa cffb92bc63 Bluetooth: L2CAP: Handle information request command on BR/EDR
Adds support to handle incoming L2CAP information request from
remote to get local information about 'extended features' and 'fixed
channels'. For now local stack ensures support for L2CAP BR/EDR
signalling channel.

Change-Id: If8c9c9dd041b45a79db5e560394dcd2778176f55
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-13 09:07:50 +00:00
Johan Hedberg 3258ecad80 Bluetooth: SMP: Minor coding style fixes
Use appropriate scope for 'random' and remove unnecessary empty lines.

Change-Id: Idb8d527fa0a88ca738e91887b56a123a5a8831ce
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-12 10:05:55 +00:00
Arkadiusz Lichwa 742c71a186 Bluetooth: L2CAP: Enable handle BR/EDR signal channel traffic
Separates LE and BR/EDR L2CAP signal channel context and starts accept
incoming PDU traffic on BR/EDR signal channel. For now all valid L2CAP
commands are send back as rejected on BR/EDR signal channel.

Change-Id: If4392b2d3ccbe157cb7eeafcaa0804e90f44e2be
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-12 09:16:04 +00:00
Szymon Janc 32da5e6748 Bluetooth: Add comment clarifying condition check in bt_le_adv_start
It is valid to call set_ad with NULL data as long as length is 0.
Improve code comment for unusual condition check explaning why it
is correct.

Change-Id: I29440fb04747f6df06dc4df466eb43e160ff3be4
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-12 09:11:29 +00:00
Arkadiusz Lichwa bc6a2cd7d6 Bluetooth: L2CAP: Implement bt_l2cap_br_connected() notifier
Adds implementation of the BR/EDR connection L2CAP notifier. It makes,
for each registered BR/EDR fixed channel, basic validation and channel
initialization using two local helper functions.

Change-Id: I6393a43b25ff0d9f23deaf93562add08861ea1d2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-12 06:38:10 +00:00
Arkadiusz Lichwa c071b3e770 Bluetooth: L2CAP: Move bt_l2cap_br_fixed_chan_register() to l2cap_br.c
Moves, specific for BR/EDR transport, register fixed channel handler
to l2cap_br.c file and make it local. Then using it register BR/EDR
signal channel (CID 1) context during channel layer initialization
in 'bt_l2cap_br_init'.

Change-Id: I5e23fc5d43ae3d7838ecb44ad4fa631eccc8cb4c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-12 06:37:01 +00:00
Arkadiusz Lichwa 51044bf5f8 Bluetooth: L2CAP: Introduce internal BR/EDR connection L2CAP notifier API
Adds dedicated function informing L2CAP layer about established BR/EDR
connection. Existing 'bt_l2cap_connected()' connection notifier is
refactored to use new API 'bt_l2cap_br_connected()' which is implemented
in l2cap_br.c file.
Currently the new handler is just stub since proper internals of
BR/EDR L2CAP signal channel management are not yet implemented
in l2cap_br.c file.

Change-Id: Idef9be63338c6bb4b3315ec0452d84f2431fbaa2
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-12 06:36:11 +00:00
Arkadiusz Lichwa bc1423f441 Bluetooth: L2CAP: Move init BR/EDR pool signal buffers to l2cap_br.c
Moves initialization of signal buffer for BR/EDR transport to
l2cap_br.c unit and removes existing references to signal buffer in
l2cap.c file to prevent compiler complains.

Change-Id: I784b926df814e632944f3a12b0b6d03d144d2438
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-12 06:34:52 +00:00
Szymon Janc 1fefa34e08 Bluetooth: SMP: Fix ecc_make_key return code check
This function returns TC_FAIL and not negative value on failure.

Change-Id: I36e51e39aca07264339fc6c10a9c2b8db61b580d
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-11 17:19:12 +00:00
Luiz Augusto von Dentz 1157a8f26f Bluetooth: GATT: Remove authorization permission
The application can return BT_ATT_ERR_AUTHORIZATION on the callback
already so there is no reason to have it as a permission as once set
it always fails.

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

Change-Id: I3c62af137b99985690cf88dcc37a977a0be891f5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-10 17:55:06 +00:00
Szymon Janc 232e934351 Bluetooth: SMP: Reduce stack usage when generating ECDH keys
Only 8 random uint32_t digits are required by ecc_make_key function.

Change-Id: Ib0b4d6923b339828281e13b2a1d960d3bb72e65a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-10 16:49:44 +00:00
Luiz Augusto von Dentz 8171965f75 Bluetooth: GATT: Fix coding style
Code shall not have more than 80 columns.

Change-Id: I2ba53c971be1d6936b5092d86c1e2196c100339e
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-05-10 15:48:29 +03:00
Arkadiusz Lichwa bc5497f239 Bluetooth: BR/EDR: Reset pairing context when needed
When pairing procedure ends regardless of the status, reset flags
strictly related to pairing phase and reset security level.
Thanks that next authentication will get known initial pairing 'context'.

Change-Id: Ie3108c6e28e136ea929e564a6820675cc770cb95
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-05-09 16:54:14 +00:00
Johan Hedberg c1ae16adc5 Bluetooth: Use bt_hci_cmd_send_sync in set_ad to catch errors
Using send_sync lets us return an immediate error to the application
if the HCI command fails. This also reduces the pressure on available
buffers since we don't allocate multiple command buffers before
starting to process the command queue.

Change-Id: I5613e4e9dd8dcc0db45bad051d7c4980b49e428d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-09 13:44:41 +03:00
Szymon Janc a5b6daaee3 Bluetooht: Don't mix ssize_t and int error codes
struct bt_storage callbacks return ssize_t while other functions in
set_static_addr return int.

Change-Id: Ic09db711ccf5e85b3118739abb0d5e50ed49d20f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-09 11:49:41 +02:00
Szymon Janc 2471d506b2 Bluetooth: Use set_random_address for setting Static Random address
There is no need to open code this as we have helper for this.

Change-Id: I77ab39206d0c5b10f30624e90e864192b9519d0c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-09 11:48:20 +02:00
Szymon Janc 838206f603 Bluetooth: Fix using NRPA for creating connection
If adapter is using Static Random address as Identity Address and
privacy is disabled we need to restore correct random address (ID)
before creating connection. Otherwise NRPA used for active scan
could be used resulting in SMP confirmation failed due to invalid
initiator address being used.

Change-Id: I7201890ab9475ade3a825f9ea791a30af6b657a5
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-09 11:41:14 +02:00
Szymon Janc c3d71b5414 Bluetooth: Don't update responder for master role connection
Both initiator and responder addresses are already set during
connection creation so there is no need to set responder address
again.

Change-Id: Id477a9e6dd2244c57126d1f985aa41cd1b04650b
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-05 14:30:15 +02:00
Szymon Janc e3013e8ced Bluetooth: Add new conn on LE Connection Complete only for slave
New connection needs to be added only for slave role. For master
connection object is created when LE Create Connection is send.

Change-Id: I24dbfc4b3a647ea230b199fbec09940f486b983f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-05 14:30:15 +02:00
Johan Hedberg 251f1cbc28 Bluetooth: monitor: Add 32-bit timestamp support
Add support for the 32-bit timestamp (1/10th ms units) extended
header.

Change-Id: I67f481a35be6878605b8c2256f6e4bfb6afe55c8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-04 21:19:49 +03:00
Szymon Janc 2450a56ae5 Bluetooth: Use le_set_rpa in check_pending_conn
This makes code simpler and easier to understand as generating RPA and
setting random address are done in same place.

Change-Id: I1f9ebdf3ee322921258c92f3f1a40d6b7764b2fc
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-04 16:40:06 +00:00
Szymon Janc ac52cffa32 Bluetooth: Refactor check_pending_conn error handling
If anything went wrong just report connection failed. This makes
code easier to read and less error prone. Also makes sure that
scanning is reenabled with correct parameters on failure.

Change-Id: I7387571f6dbf308511694a635aa47d5371a81616
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-04 16:34:55 +00:00
Szymon Janc 4031d6d160 Bluetooth: Fix connection leak if failed to generate RPA
If bt_smp_create_rpa failed connection object needs to be unreferenced.

Change-Id: Ie1f2905cafbf15db2970c0f07748d016cbe55c2b
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-04 16:33:54 +00:00
Szymon Janc 6d5ed390b1 Bluetooth: Simplify advertising API
Instead of requiring application to provide both advertising type
and address type used just require app to provide info if advertising
is connectable or not. Advertising type is set based on provided
SCAN_RSP and local privacy support.

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

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

Change-Id: I90e9a683ef3794f155707343c874f75585439325
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-05-04 11:11:34 +00:00
Johan Hedberg 68d1feee59 Bluetooth: SMP: Avoid using hard-coded constant
Change-Id: I9d82fde39cc3221c071ce709a10df53f55af87d8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-03 14:28:00 +03:00
Johan Hedberg 31b37ba639 Bluetooth: Increase HCI_LE_rand delay for MyNewt
1 tick (10 ms on most current boards) doesn't seem to be enough to
completely eliminate the HCI_LE_Rand bug. Increase the delay to 20 ms
(i.e. 2 ticks).

Change-Id: Ibe87d5e4b2ec43b2f96afb2c4e0ac726ffe99bd6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-03 13:05:06 +03:00
Johan Hedberg 3a473134c5 Bluetooth: Move bt_conn functions to conn.c
There's no reason to keep these in hci_core.c. Also remove the
duplicate bt_conn_update_param_le() and make bt_conn_set_param_le()
static since it's only accessed from within conn.c.

Change-Id: I1234e9d2e5d1d367732a7b66965cf10a338c07fb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-05-03 13:05:06 +03:00
Vinayak Kariappa Chettimada de999a81c5 Bluetooth: SMP: Fix unaligned access usage fault.
xor_128 function uses uint8_t instead of uint64_t XORs to avoid
unaligned access faults.

Change-Id: I0b0c73d64ce4158e3d8aeb4dd5416ead2bd7b664
Signed-off-by: Vinayak Kariappa Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-05-03 08:56:00 +00:00
Szymon Janc 7c87c089fd Bluetooth: Fix using invalid responder address as peripheral
If Static Random address is used as Identity Address and local privacy
is not used, responder address for slave connection was not set to
Identity Address.

Change-Id: I7a057c0fcb8e6d7e043952a092d16e959841f792
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-04-29 12:07:07 +02:00
Roger Lendenmann 3278f542eb Bluetooth: gatt: include service api definition proposal
* service include macro definition takes reference to
   first service attribute of the included service

Change-Id: Ib2b1defe2c99aea738da791af74a534d56025eae
Signed-off-by: Roger Lendenmann <roger.lendenmann@intel.com>
2016-04-28 10:35:38 +00:00
Johan Hedberg 48338958e6 Bluetooth: monitor: Update to new protocol format
The updated "monitor over UART" protocol looks like:

    uint16  data_len
    uint16  opcode
    uint8   flags
    uint8   hdr_len
    uint8   extra_hdr[hdr_len];
    uint8   payload[data_len - 4 - hdr_len]

Change-Id: I5fceafe69489a5bfc940d113066f100016f74bc3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-27 18:09:28 +03:00
Johan Hedberg 18cd8ad091 Bluetooth: Add temporary workaround for MyNewt HCI_LE_Random reliability
For some reason the HCI init procedure doesn't complete on the Arduino
101 using the MyNewt HCI firmware if we send HCI_LE_Random commands
too quickly (which probably is crashing the nRF51 RNG, or something
similar). Adding just a tiny delay makes the init complete reliably.

Change-Id: Ic87a965b0e5cb265a2bee09e23d337d741527773
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-04-27 11:39:56 +00:00
Arkadiusz Lichwa 8e34b5869b Bluetooth: L2CAP: Add API to register PSM server
Enables API to register PSM server on BREDR transport.
Adds l2cap_br.c file responsible for BREDR specific functionality to
build path based on Kconfig selection.

Change-Id: I92823b0207ab0da96bfb813353de9f95fa5dd0f4
Origin: Original
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-04-26 10:58:14 +02:00