Commit graph

42559 commits

Author SHA1 Message Date
Andrei Emeltchenko
3dca06e700 Bluetooth: trivial: Make struct static
Change-Id: Ife8cc60bca8f5c00c5f47d3996c873a9c031feba
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:18 -05:00
Andrei Emeltchenko
960147d829 Bluetooth: Add Manufacturer Name String to DIS
Manufacturer Name String in DIS is a mandatory feature for Heart Rate
profile as specified by HEART RATE PROFILE Spec.

Change-Id: I552b51b68012edfc4389604e91dd43b8b54fe65f
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:18 -05:00
Andrei Emeltchenko
2be30696a9 Bluetooth: Simulate Heart Rate Measurements
Add Heart Rate simulation using 1 second sleeping loop and this is how
it is recommended in the Heart Rate Service Spec.

Change-Id: I1023a4089bc661a399acf865f4fc7afaf72b8f0f
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:18 -05:00
Mariusz Skamra
a44e4544bd Bluetooth: Use connection callbacks in peripheral sample app
This registers two simple callbacks for connection and
disconnection events.

Change-Id: I9e1f87d9e1a3c8ef457e15a1c30396fba7f7df4a
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.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
Luiz Augusto von Dentz
4baa3b9700 Bluetooth: Fix missing braces
Change-Id: I3ad884e38428c48ee08c3778219508bd21bfa106
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz
0000a2d790 Bluetooth: Add check fo connection encrypt flag in ATT
This checks if connection encrypt flag is set if attribute requires
encryption and in case the connection is already encrypted return
success.

Change-Id: I8af4e9786b63a21f478b3aa9f6df448d7f5760c5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz
8f6edeebb8 Bluetooth: Handle attribute read/write errors
Respond with an error if attribute read/write return an error.

Change-Id: I9c2f98ac4b73bca5d3714339a47290ca9ae2391b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Andrei Emeltchenko
aeb448ebba Bluetooth: Add Current Time Notification
Implement Current Time Notification triggered by write().

...
> ACL Data RX: Handle 74 flags 0x02 dlen 17                [hci0]
161704.397398
      ATT: Write Request (0x12) len 12
        Handle: 0x0014
          Data: df07071e0c2e01010000
< HCI Command: Host Number of Comp.. (0x03|0x0035) plen 5  [hci0]
161704.398861
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 5                 [hci0]
161704.398900
      ATT: Write Response (0x13) len 0
> HCI Event: Number of Completed Packets (0x13) plen 5     [hci0]
161704.533356
        Num handles: 1
        Handle: 74
        Count: 1
< ACL Data TX: Handle 74 flags 0x00 dlen 17                [hci0]
161705.189198
      ATT: Handle Value Notification (0x1b) len 12
        Handle: 0x0014
          Data: df07071e0c2e01010000
> HCI Event: Number of Completed Packets (0x13) plen 5     [hci0]
161705.275353
        Num handles: 1
        Handle: 74
        Count: 1
...

Change-Id: I504c4197a0a1d434f7704b76c8abd120eba51b7a
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:18 -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
5efe82a8e9 Bluetooth: Add Number of Completed Packets event to special queue
The Number of Completed Packets HCI event belongs to the same category
as the Command Complete/Status events in that it is likely to unlock a
waiter in one of the other fibers. Events which may affect waiters in
this way need to be processed without delay and through a separate
FIFO & fiber to avoid deadlocks.

Change-Id: Ibc2ee2b4f72e2534a8579ad1c36591867e19e6df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Andrei Emeltchenko
4c2a6a6b14 Bluetooth: Remove quark target from regression test
After quark UART configuration was refactored it is not working
anymore. Since quark was never an officially supported target just
remove it from the regression tests.

Change-Id: If4bae99f5e0dfecfd3729ac0c42d7fd3d8affa0c
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.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
92e3a44b3d Bluetooth: Increase buffer count from 20 to 22
We need to make sure we have more event buffers than outgoing ACL
buffers. Currently we allocate 7 + 7 ACL in/out buffers leaving only 7
left for commands/events. Increase the buffer count by two to make
sure we've got 8 command/event buffers.

Change-Id: I4c54aa07019ad9ef262aeecabf151edd60f91b9e
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
Andrei Emeltchenko
a79c26d9aa Bluetooth: Implement Current Time write
Implement Current Time write callback.

Change-Id: I2a6cb0b411c47e4d20ff34eadf8725bf23b0b7b9
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@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
Arkadiusz Lichwa
0225b6b299 Bluetooth: Update simple LE scan app
Adjust app to build system.

Change-Id: I5366ea9b38b261762724006fef0ec61ed3c6e251
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz
693c40b34d Bluetooth: Add Vendor Service to peripheral sample
This add a vendor service which uses 128 bits UUID adding it to
advertising data:

< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32
        Length: 29
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        16-bit Service UUIDs (complete): 3 entries
          Heart Rate (0x180d)
          Battery Service (0x180f)
          Current Time Service (0x1805)
        128-bit Service UUIDs (complete): 1 entry
          12345678-1234-5678-1234-56789abcdef0

In addition to that it also adds 2 characteristics that test read/write
encryption and authentication permissions:

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Read Request (0x0a)
        Handle: 0x001b
        Error: Insufficient Encryption (0x0f)

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x001b
        Error: Insufficient Encryption (0x0f)

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Read Request (0x0a)
        Handle: 0x001d
        Error: Insufficient Authentication (0x05)

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Error Response (0x01) len 4
        Write Request (0x12)
        Handle: 0x001d
        Error: Insufficient Authentication (0x05)

Change-Id: Id5d42c9f6afdc8625fc8019d606114632d57ae76
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz
51f85ed6ab Bluetooth: Fix bt_gatt_attr_read_chrc for UUID 128 bits
When reading a characteristic attribute which contain a 128 bits UUID the
size of the elements were counting only the UUID alone not other fields
that are part of the value causing invalid responses to be sent.

Change-Id: I7474531f586ba19788eb9e0ed59555c5d7672176
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Luiz Augusto von Dentz
58791718e1 Bluetooth: Check GATT attribute permissions
This checks attribute permission returning an error in case they don't
match.

Change-Id: I56a85ad594cb1ac535b03cdbceb43af84dc6604f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@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
d412b7d799 Bluetooth: Fix build if CONFIG_BLUETOOTH_DEBUG_HCI_CORE is enabled
If CONFIG_BLUETOOTH_DEBUG_HCI_CORE is enabled it causes the following
error:

hci_core.c:514:12: error: 'struct bt_hci_evt_encrypt_key_refresh_complete' has no member named 'encrypt'
         evt->encrypt);
            ^

Change-Id: I1983653eba40b9aea6b19572b39a285883f00450
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg
144115c58e Bluetooth: SMP: Convert handler dispatch to a table
We can do centralized PDU length checks and more compact code size
with the help of a handler table where the index maps to the SMP op
code.

Change-Id: Iba69ecc14f452411dfb6b4db7c7a5fd19ba3e51f
Signed-off-by: Johan Hedberg <johan.hedberg@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
Andrei Emeltchenko
382488bbd0 Bluetooth: Check CCC before allocating buffer
Fixes memory leak when buffer is allocated before CCC check, the best
fix is to move CCC check forward.

Change-Id: Ib0492f629a339b576cf811adce47b2f6ab101c33
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg
0fb7461140 Bluetooth: SMP: Set correct minimum encryption key size
For now we don't support key shortening, so set the minimum value
appropriately to 16 bytes. Once key shortening is implemented this
value can be lowered again.

Change-Id: I172d0bf6d04ba4c5eaa7bbf8ae2accfa373eebb5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Johan Hedberg
5c31ad3ae4 Bluetooth: Look up IRKs during LE scanning
Devices using LE Privacy are identified by their Identity Address
whenever we've paired and received their IRK. We should therefore try
to look up matching IRKs for advertising responses.

Change-Id: I304108da699ff2506e6cc50bd6c5c053a0db024b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:18 -05:00
Andrei Emeltchenko
b53967c3cc Bluetooth: Fix trying to print pointer instead of string
Use correct address to string translation.

Change-Id: Ic766147fd6016894c0f60ec57059984887653a15
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2016-02-05 20:14:17 -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
a6f18d7cc4 Bluetooth: Update the connections address from IRK
When a connection occurs it may have happened with an RPA. If so,
check if there's a matching IRK available and update the connection
address with the Identity Address (stored together with the IRK).

Change-Id: I3d995a35171b514ec1902fce617e8e7d6770e785
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
44795a6574 Bluetooth: Add API for looking up IRKs
Add an API to bt_keys for looking up IRKs based on a given RPA.

Change-Id: If9c0569c8d619f9cb2b6174d77c25dd5358db863
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
86eb6667cf Bluetooth: SMP: Add IRK resolving support
Add support for the SMP ah() crypto function which is used to match up
IRKs with RPAs.

Change-Id: Iaea8397ea401df800259dfab2ce97187aa5e2df6
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
1886981023 Bluetooth: Track keys in the connection context
To avoid spending unnecessary time looking up the same keys multiple
times simply store a pointer to them from the connection context.

Change-Id: I94b550870c863237348a2cab7ba056be2a7f4bc5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
68612ca20c Bluetooth: SMP: Ignore irrelevant encryption changes
If we're not actively performing pairing we should ignore any
encryption changes. If we don't do this the code might e.g.
incorrectly clear out existing keys.

Change-Id: Iac49a09abd7386b773e325b9bc939d6b6c741c92
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
9cdd128eab Bluetooth: SMP: Add support for receiving remote IRK
Add support for handing the Identity Info and Identity Address Info
SMP PDUs.

Change-Id: Ie0ed57e2c1819a1619b9eaa340ed22666c81eea8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
40e6a1288c Bluetooth: Add IRK storage
Add support to store IRKs through the bt_keys API.

Change-Id: I01f713f8ad3657605a8bc2738db349d25bb89649
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
275c0316ff Bluetooth: Refactor key handling to prepare for more key types
We'll need to store many other keys besides slave LTKs. Refactor the
key handling code so that new types can be easily added.

Change-Id: I768db9cb29e8e73e87713e59f7b80af80399f20d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -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
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
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
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
8508bfb2b1 Bluetooth: Make use of BT_GATT_CCC
This uses BT_GATT_CCC to declare CCC descriptors which makes the core
to managed the CCC configuration so the task don't have to do it.

Change-Id: Ied4fc7eaa1f9f3e6c23d4d5b20d5c26d606f93f4
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
1d734fd60f Bluetooth: Fix not passing proper peer address to attribute read
Invalid peer address was being passed since the conn pointer was not
initialized properly.

Change-Id: Ib64584f1eb8bc534389bd4fa057c58dd00ffbd6d
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
Johan Hedberg
68773aa74e Bluetooth: Fix CONFIG_BLUETOOTH_DEBUG_UART dependency
The BLUETOOTH_DEBUG_UART config option should depend on BLUETOOTH_UART
and also be sorted after it in the hierarchy.

Change-Id: I3e049e52c2e353cd0c6f1a99ca8934a289e0cce8
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
7f72d21a96 Bluetooth: Rename bt_conn_lookup_by_addr_le for consistency
Follow the same style as bt_conn_lookup_handle (i.e. drop the 'by').

Change-Id: I6a31104fc8beac13c357088e46a91bd713fcfdd4
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Johan Hedberg
ae58464b43 Bluetooth: Rename bt_conn_lookup to bt_conn_lookup_handle
To take multiple different ways of looking up connections rename the
existing too generic bt_conn_lookup to bt_conn_lookup_handle.

Change-Id: I1c4965ad76738fa08ccca91b28cda552c9a88373
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:17 -05:00
Luiz Augusto von Dentz
c151b84832 Bluetooth: Add bt_conn_lookup_by_addr_le
bt_conn_lookup_by_addr looks up for existing BLE connection by address.

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