Commit Graph

59 Commits

Author SHA1 Message Date
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
Johan Hedberg e4e51e3051 Bluetooth: Move random number helper to hci_core.c
We'll need this e.g. for NRPA generation even when SMP isn't enabled.

Change-Id: I4bffca3a180fda8f6757e902f8e255ba497b0bf5
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 f443be7205 Bluetooth: Add flag to track Bluetooth readiness
Change-Id: I1251eccdf474d0f113bde77d7e65f02eef39bade
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg a2276b6fce Bluetooth: Use fast scanning only for initial connection attempt
Change-Id: I68303f1fb98b7ed17eec166639811866df024ea9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg b748f87243 Bluetooth: Simplify duplicate filtering tracking
Change-Id: If797c382eed87fc2c2a54a94bc1fa6ec5dad1914
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg 6df50d474e Bluetooth: Create dedicated flag for explicit scanning
Change-Id: I0d7548c755a277e7741cf0b3a1b97e127ea1d382
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -05:00
Johan Hedberg 93af450977 Bluetooth: Group bt_dev flags more sensibly
Change-Id: I03399604fb95d4856d8e4b4141bce508d6b2558f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:01 -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
Arkadiusz Lichwa baf2f4d28e Bluetooth: Cleanup LE ACL Tx semaphore
Makes consistent and compact ACL Tx semaphore namespace

Change-Id: Ief357e02ff7c3e1c6b7667dc27f057a3499cf1c4
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:51 -05:00
Arkadiusz Lichwa 17fcf67422 Bluetooth: BR/EDR: Initialize ACL Tx semaphore
Defines dedicated semaphore for sync ACL packets out.

Change-Id: I114daad24cd75fa4165128eab697af382ea10c3a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:51 -05:00
Arkadiusz Lichwa 0c3c6ddd90 Bluetooth: BR/EDR: Make room for controller internals
Defines instance for controller specific information.
Prepare room for max ACL packet length controller can get.

Change-Id: I5fb5f83b3f7383337b6b86683dff05b675815b98
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:50 -05:00
Arkadiusz Lichwa a34d114085 Bluetooth: Refactor init LE ACL Tx semaphore
Moves initialization of bt_dev.le.pkts_sem object to handlers reading
controller buffer capabilities. Therefore no need to keep anymore
bt_dev.le.pkts member.

Change-Id: I126cb1d9ad9feed9c11f35b26c44055075734685
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:50 -05:00
Szymon Janc 7426de527f Bluetooth: Read LE Local P-256 Public Key on init
This is needed for LE Secure Connection when tinycrypt is not used.

Change-Id: Ia0419da882d48d9d298b6674803b2e4987e6aa0c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:49 -05:00
Johan Hedberg 7fa137c241 Bluetooth: core: remove unrelated/inaccurate code comment
Change-Id: I41e312b28f8badf211cb9ded3015e7183d10154d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:47 -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
Arkadiusz Lichwa 99bd06deaa Bluetooth: Refactor bt_dev struct
Groups LE stack specific values.

Change-Id: Ia947d25c105f518287293b4f870466daa416385c
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:24:44 -05:00
Johan Hedberg e9ceedcff7 Bluetooth: Introduce config options for buffer counts/sizes
Introduce dedicate Kconfig options for ACL & HCI buffer counts and
sizes.

Change-Id: I96796058f70998e1e721849422c4bc4e950b6d93
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:40 -05:00
Johan Hedberg 13fcc5ca3e Bluetooth: Make ACL/HCI user data private to hci_core.c
Change-Id: I85ccbfd2d844195bffcc6dd3d6490808569ca129
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:24:39 -05:00
Johan Hedberg 31114c384b Bluetooth: Remove buffer type information from user data
Since the type can be determined either from the context or from e.g.
the pool that it belongs to (the 'free' pointer) we no-longer need to
store the type as part of the user data struct.

Change-Id: I090636aaa0a0b1be798b6dadfab072151fc3ab14
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 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
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 cc261005f2 Bluetooth: Remove includes from internal headers
All required includes should be placed in source file that includes
internal header.

Change-Id: I161e7ebe2e62377ea4cf03f759d48f5900103076
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:16:16 -05:00
Arkadiusz Lichwa 134ae99d35 Bluetooth: Refactor LE Connection Params validator
Move le_validate_conn_params() interface to internal HCI
header to be commonly shared between HCI and L2CAP layers.
Refactor the interface and its users and rename related to Connection
Parameters Update procedure values used for validation.

< ACL Data TX: Handle 42 flags 0x00 dlen 16                                                                                                                          [hci1] 2832.387859
      LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8
        Min interval: 40
        Max interval: 56
        Slave latency: 0
        Timeout multiplier: 0
@ Device Connected: 00:AA:01:00:00:23 (1) flags 0x0000
< HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2                                                                                                     [hci0] 2832.389374
        Handle: 42
> ACL Data RX: Handle 42 flags 0x02 dlen 16                                                                                                                          [hci0] 2832.389437
      LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8
        Min interval: 40
        Max interval: 56
        Slave latency: 0
        Timeout multiplier: 0
> HCI Event: Number of Completed Packets (0x13) plen 5                                                                                                               [hci1] 2832.389440
        Num handles: 1
        Handle: 42
        Count: 1
> HCI Event: Command Status (0x0f) plen 4                                                                                                                            [hci0] 2832.389443
      LE Read Remote Used Features (0x08|0x0016) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 12                                                                                                                            [hci0] 2832.389444
      LE Read Remote Used Features (0x04)
        Status: Success (0x00)
        Handle: 42
        Features: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00
          LE Encryption
          Connection Parameter Request Procedure

< ACL Data TX: Handle 42 flags 0x00 dlen 10                                                                                                                          [hci0] 2832.393154
      LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2
        Result: Connection Parameters rejected (0x0001)
> ACL Data RX: Handle 42 flags 0x02 dlen 10                                                                                                                          [hci1] 2832.393181
      LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2
        Result: Connection Parameters rejected (0x0001)

Rejected due to Timeout multiplier: 0.

Change-Id: Idaf4f452f560ff71d9637ec5d793154190e94b35
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 87b219cc05 Bluetooth: Update LE Exchange Features event handler
Adds conditions to trigger L2CAP based Update Connection Parameters
and HCI based Connection Parameters Request Procedure.

Change-Id: I66e4a977b534afc4a10d4eba54ee3eb95c2166ef
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:37 -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
Johan Hedberg e060c621d1 Bluetooth: Move le_conn_update() to conn.c
Change-Id: Iaaf1cce09aef2e09c0cb2cca3500368a5faec2ae
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg 5f33744a4c Bluetooth: Move le_start_encryption to conn.c
Change-Id: Id9c042663e6f58aba6ec34165b7b244650317969
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg e0e6416065 Bluetooth: Export bt_dev through hci_core.h
Rename the hci_core.c (previously internal) variable 'dev' to 'bt_dev'
and export it through hci_core.h. This way e.g. bt_conn doesn't need
to store an internal reference to it.

Change-Id: Ic1368c8f20d307c6a13a412f80d8183b56d7a76b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg 7ed81c7a22 Bluetooth: Enhance bt_le_scan_update() for active scanning
Let bt_le_scan_update() perform all necessary changes to active
scanning so that it's even more helpful to the start/stop scanning
APIs as well as the bt_connect_le() API.

Change-Id: I8ee2daf96297749f782d364dfb66c7d0bbc48f5e
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
Mariusz Skamra d699296a45 Bluetooth: Add passive scanning support
Part of General Connection Establishment Procedure.

Active scanning is enabled by task and has higher priority than
passive scan. If passive scan is running and task wants to enable
scan (active) scanning will be restarted in active mode. Passive
scan is enabled implitly while app calls bt_connect_le.
Instead of directly call hci_le_create_conn, it is called from
device_found if addr obtained from advertisement matches address
we want to connect. App calling bt_stop_scanning can only stop
active scan.

Change-Id: I01805c51f3d821bbd827af75e5d1d4350169241d
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:35 -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
Johan Hedberg fa1bf41477 Bluetooth: Fix minor coding style issues
Change-Id: I0e78bce8cdbf46252f4cfc4483995ba7583915f7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:24 -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
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 e3fd3090ba Bluetooth: Rename cmd_rx_queue/fiber to rx_prio_queue/fiber
With the introduction of the Number of Completed Packets event
handling this FIFO & fiber aren't anymore strictly HCI command
completion related. Rename them therefore to something that more
appropriately describes their purpose.

Change-Id: Ia53dea8b5ec0098459f23918a5483075757d9202
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg 384533912d Bluetooth: Move key handling to separate files
In preparation of adding more key support and to not bloat hci_core.c
prepare a new .c file for the key management code.

Change-Id: I5129a7a3a5d495a299f75e4e669253446a276142
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg 2dc3554e1c Bluetooth: Rename bt_addr_is_rpa to bt_addr_le_is_rpa
The input paramter is bt_addr_le_t so the function should be named
accordingly.

Change-Id: I7b796020d6e43ae1aa76a261cbfbaf7cba163029
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg 12229a8f49 Bluetooth: Fine-tune stack size adjustment for debug
512 is a more accurate description than 1024 of the stack usage impact
of enabling debug logs.

Change-Id: I4b79b4eb9724ba624ff546973a1126c62382d1aa
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg 8eabf208d7 Bluetooth: Add convenience macros for defining stacks
To not have to always do the __noinit, debug log correction and 4-byte
alignement declaration create some helper macros for defining the
stacks.

Change-Id: I2de5068d7044af3f348ed01281498a777d04c97d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg c82b96d425 Bluetooth: Tune stack sizes based on latest analysis
Set the stack sizes based on what the current utilization is for SMP
and GATT tests.

Change-Id: I892282a088d7b244f7abdbc92368addc9c19e4eb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:16 -05:00
Johan Hedberg 8d0d247f23 Bluetooth: Add helpers for checking LE address type
For LE Privacy support we'll need to be able to distinguish which
addresses are RPAs and which are Identity Addresses.

Change-Id: Ie244a4d53ffddc435edbd6d69d7ecca205202f18
Signed-off-by: Johan Hedberg <johan.hedberg@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
Johan Hedberg d8e9e71acd Bluetooth: Add dedicated stack for Command Complete/Status events
These events are special since they release any blocking
bt_hci_cmd_send_sync() calls. In order to be able to use the send_sync
API from HCI Event handlers without deadlocking having the Command
Complete/Status events processed through a dedicated fiber is
essential.

Change-Id: Id5c597d618bf326a8efb7c9ca2500af60a502d77
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
Johan Hedberg a4ecff8dad Bluetooth: Rename cmd_stack/fiber/queue to cmd_tx_stack/fiber/queue
To prepare for a dedicated Command Complete/Status processing fiber,
add 'tx' to the existing names to differentiate from the 'rx' in the
upcoming names.

Change-Id: I59e0ba34502e4a2341396f81bfb5829c296b35a5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:03 -05:00
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 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