Commit graph

2878 commits

Author SHA1 Message Date
Johan Hedberg 8ed846285e Bluetooth: Implement bt_storage_clear()
Add an implementation for the bt_storage_clear() API.

Jira: ZEP-181

Change-Id: Iae01c571c161317ea0cc44513d108301c7b5a069
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Johan Hedberg 77a8516dd2 Bluetooth: storage: Add basic support for internal storage
Add basic implementation of an internal storage handler that uses the
local file system. The root directory for all Bluetooth related data
is /bt. Each remote device has its own subdirectory and each key its
own file. This helps keep the implementation very simple, but does
come with the meta-data overhead for each file.

As an example, the value of a key 0x0001 for a device with a static
random address cc:11:22:33:44:55 would be stored in the following
file: /bt/cc11223344551/0001. Local values such as the identity
address are stored directly under /bt with a file name that matches
the key the same way as remote-device files.

For full functionality the implementation requires a file system that
can support file/directory names of up to 13 characters in length. If
the file system supports less than that (as is the case with FAT12)
then only local values can be stored (in /bt/abcd). Local values
include the identity address as well as the local IRK.

Jira: ZEP-181

Change-Id: I7dc696af6353a154cb00dcd01a5f4ac3d7127e6b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc e18e3ed60a Bluetooth: Controller: Use unified k_sem API for semaphore
Change-Id: I02b4e5f4d0a2995cfae1b9a2edcbdf01d6ec631a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8f800a8bfe Bluetooth: Use unified k_sem API for semaphores
Change-Id: I0099c837cc8ad67b8f927b2debd771acfe626eea
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 8944c25c90 Bluetooth: Controller: Include zephyr.h instead of nanokernel.h
zephyr.h includes required kernel header depending on selected
configuration.

Change-Id: Ib72c4038637c303ee32e433706355299ae1b9a13
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 3808ad0a96 Bluetooth: L2CAP: Limit segments to TX MPS
le_data buffers are no longer limited to the minimun of 23 bytes, instead
it uses CONFIG_BLUETOOTH_L2CAP_IN_MTU which means it can be bigger than
the MPS thus causing invalid data to be sent:

> ACL Data RX: Handle 64 flags 0x02 dlen 18
      LE L2CAP: LE Connection Request (0x14) ident 1 len 10
        PSM: 128 (0x0080)
        Source CID: 64
        MTU: 672
        MPS: 23
        Credits: 65535
< ACL Data TX: Handle 64 flags 0x00 dlen 18
      LE L2CAP: LE Connection Response (0x15) ident 1 len 10
        Destination CID: 64
        MTU: 230
        MPS: 65
        Credits: 4
        Result: Connection successful (0x0000)
< ACL Data TX: Handle 64 flags 0x00 dlen 27
< ACL Data TX: Handle 64 flags 0x01 dlen 2
      Channel: 64 len 25 [PSM 128 mode 0] {chan 0}
        3c 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff  <...............
        ff ff ff ff ff ff ff ff ff

JIRA: ZEP-1219

Change-Id: Id67f1faac8766c66aa24c7421d44112434666a10
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Szymon Janc 3317227437 Bluetooth: Remove workaround for Mynewt firmware bug
This is not needed for Zephyr controller build and should already
be fixed in Mynewt.

Change-Id: I39e81dc3e9b5fd5a3f5f823465527248625caf26
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-11-09 08:57:52 +02:00
Arun Jagadish 227b1d4643 Bluetooth: AVDTP: Set Profile Security Level to Medium
Setting AVDTP Profile Security to Medium

Change-Id: I93aa367ac5bfe4e8bfe08f25d0e7e9d65b891350
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-11-09 08:57:52 +02:00
Luiz Augusto von Dentz 4f39b4ceb1 Bluetooth: L2CAP: Fix regression causing credits not to be restored
Patch 8c118f8673 causes the wrong semaphore
to checked so receiving credits are never restored which caused the
channel to get stuck after all the credits are consumed.

JIRA: ZEP-1199

Change-Id: I9cd5474b3bcaafcb19d15613939ce30d07befe0a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-09 08:57:52 +02:00
Vinayak Chettimada fb032efa90 Bluetooth: Controller: Use configured clock source
Remove hardcoded use of crystal as 32KHz clock source and
20 ppm accuracy; and use the values from config for sleep
clock source and sleep clock accuracy value in Bluetooth
Controller.

Change-id: I1c0d53ecf8ad158153d5186a6680b5eb03d1641b
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-07 12:04:03 +00:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Johan Hedberg f26007d212 Bluetooth: Print full controller info upon init
Provide more detailed information about the controller address and
version upon init when debug is enabled.

Change-Id: I5fe9c7c91f95928cb3cc64b801137bb1466e4115
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:06:31 +02:00
Vinayak Chettimada d62426030c Bluetooth: Controller: Fix re-encryption procedure
During implementation of alternate encryption procedure
usable in nRF51, commited in
c41d3edda8, re-encryption
procedure was broken. This commit fixes the issue, and
now re-encryption should work on both nRF51 and nRF52.

Change-id: Ia41200f42b1d46e1f3f35ff44b582d4ffcc5f4fa
Signed-off-by: Vinayak Chettimada <vinayak.kariappa.chettimada@nordicsemi.no>
2016-11-04 22:06:31 +02:00
Mariusz Skamra 748c00b31e Bluetooth: GATT: Pass data buffer as NULL if length is 0
So that application could check data pointer to see if any
data have been received and if read operation is complete.

Change-Id: I36c3ff81baefbc535374d937e5297938445eafa6
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 1b7c219f8a Bluetooth: L2CAP: Make use of bt_l2cap_chan_set_state on BR/EDR
This makes use of the same code used by LE to print the state transitions.

Change-Id: I90a04f3c3f426fde1e0987acb572f7371c483c1c
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 5fecf98c8e Bluetooth: L2CAP: Log state transitions
This adds a common function to log state transitions including the caller
function and line in case something goes wrong:

[bt] [DBG] bt_l2cap_chan_disconnect: (0x0011b14c) chan 0x001199c0 scid 0x0040 dcid 0x0040
[bt] [DBG] bt_l2cap_chan_set_state_debug: (0x0011b14c) chan 0x001199c0 psm 0x0080 connect -> disconnect
[bt] [WRN] bt_l2cap_chan_set_state_debug: bt_l2cap_chan_disconnect()1562: invalid transition

Change-Id: I246a9004a04d93a38b8c7f7633705f6c191698b2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 349230321f Bluetooth: L2CAP: Fix not updating CoC channel state
Channel state shall be updated properly otherwise it may cause unexpected
errors.

Change-Id: Ifd54d6bd3c5b44a40c315fd8a2946b30168aa65f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery 88038d1782 Bluetooth: RFCOMM: Define macro for PF bit
This defines and clarifies PF bit macro for both UIH and
non UIH packets.

Change-Id: Ide7736c0fc8607708824766adbfccf1bd7bc48e9
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Jaganath Kanakkassery 70f1df22a4 Bluetooth: RFCOMM: Set sec_level to LOW during L2CAP register
Security will be elevated based on the DLC required level
during connection.

Change-Id: I0b63885582f34a5689f7bc8081c1f9f011b2325f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:06:31 +02:00
Sathish Narasimman 56392e5c2e Bluetooth: Fix initialization of variable
Initialize the variable to zero before computing.

Change-Id: Iccdf77a085667728dbb68779f001c8d940a7a89d
Signed-off-by: Sathish Narasimman <sathish.narasimman@intel.com>
2016-11-04 22:06:31 +02:00
Luiz Augusto von Dentz 807bd5fec8 Bluetooth: L2CAP: Handle LE connection response security errors
If there are security errors bump the security of the connection and
retry:

7C:7A:91:18:82:5F (public)> l2cap-connect 0x0080
[bt] [DBG] bt_l2cap_chan_connect: (0x0011ae8c) conn 0x0011b940 chan 0x00119700 psm 0x0080
[bt] [DBG] l2cap_chan_tx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] l2cap_chan_rx_init: (0x0011ae8c) chan 0x00119700
[bt] [DBG] bt_l2cap_chan_add: (0x0011ae8c) conn 0x0011b940 chan 0x00119700
L2CAP connection pending
7C:7A:91:18:82:5F (public)> [bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 2 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0000 mtu 0 mps 0 credits 0 result 0x0005
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 7
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 7
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 65
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 65
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 6 len 17
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bf00 len 17
Security changed: 7C:7A:91:18:82:5F (public) level 2
[bt] [DBG] bt_l2cap_recv: (0x0011ced8) Packet for CID 5 len 14
[bt] [DBG] l2cap_chan_recv: (0x0011ced8) chan 0x0011bd00 len 14
[bt] [DBG] l2cap_recv: (0x0011ced8) Signaling code 0x15 ident 3 len 10
[bt] [DBG] le_conn_rsp: (0x0011ced8) dcid 0x0040 mtu 672 mps 230 credits 10 result 0x0000
Channel 0x00119700 connected

Change-Id: I2402fd86cc6bdf41a537053325e0a1973c23377a
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Luiz Augusto von Dentz d1ae81eddd Bluetooth: L2CAP: Make CoC depend on SMP
This is necessary in order to properly handle security errors which are
part of the testing specification thus can influence qualification.

Change-Id: If444e753be9196f3d5bb36cea00e332a33aa249f
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery 5d40ea1d15 Bluetooth: RFCOMM: Introduce helper to initialize dlc
This is to avoid code duplication while implementing outgoing
connection.

Change-Id: I52f882b7be9180f29def59c8ac3ef0a4798b719d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery e3c258e286 Bluetooth: RFCOMM: Introduce helper to get session
This is to avoid code duplication while implementing outgoing
connection.

This also moves setting initiator flag while allocating, than
doing it when SABM is received.

Change-Id: I8e811c995bf0eaa0bd24715e2e96d8a578a79c5d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery 2eba256fd2 Bluetooth: RFCOMM: Define enum and macros for role and CR
This replaces initiator flag of session and dlc to enum which has
two values INITIATOR and ACCEPTOR.

Also this defines macros for CRs in header. Basically there are
three types fo CRs. Frame header CR has different meaning for
UIH and non UIH packets. Also this renames the existing msg hdr
CR to make it consistent.

These changes are basically done to make it more readable

Change-Id: Ic15e93465b0afbd19d8805f27d7a43f34ef38689
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Jaganath Kanakkassery f6f4acbced Bluetooth: RFCOMM: Remove extra tab
Change-Id: I2edafa32711cbac933d719a1ea0736e955bbb12c
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 26d39cd107 Bluetooth: Move controller code to subsys/bluetooth
Move controller code from drivers/controller to
subsys/bluetooth/controller.

Change-Id: I73f675188485aa3267507bad7647796e593a3da0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00
Johan Hedberg 6bc645962a Bluetooth: Move Bluetooth host stack to subsys
Move the Bluetooth host stack from net/bluetooth to
subsys/bluetooth/host. This is preparation for having both host and
controller under the same root, i.e. subsys/bluetooth/.

Change-Id: I3bc796f7e331fca0c485f3890d62b9c03e027b96
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-04 22:05:05 +02:00