Commit Graph

34 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz 4197aa814c Bluetooth: Refactor fixed channel data
This refactorer fixed channel data so that the channel itself carries
any extra context necessary.

Change-Id: Iea0f29fb7913a29dccdcbef72d92ec4cf4711bf3
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:37 -05:00
Szymon Janc 36d5294f8c Bluetooth: Pass LTK length to bt_conn_le_start_encryption
This is in preparation for supporting different encryption key sizes.

Change-Id: I36ed61a35fbe4988ce863127ae318c63f9298dd3
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:30 -05:00
Luiz Augusto von Dentz e8bc54d9d8 Bluetooth: L2CAP: Handle connection request
This handle connection request looking up for existing servers and
responding properly:

> ACL Data RX: Handle 3585 flags 0x02 dlen 18
      LE L2CAP: LE Connection Request (0x14) ident 1 len 10
        PSM: 128 (0x0080)
        Source CID: 64
        MTU: 672
        MPS: 230
        Credits: 10
< ACL Data TX: Handle 3585 flags 0x00 dlen 18
      LE L2CAP: LE Connection Response (0x15) ident 1 len 10
        Destination CID: 64
        MTU: 65
        MPS: 230
        Credits: 1
        Result: Connection successful (0x0000)

Change-Id: Ic0339518b80d9e38109f3efee6be4f0d2b084f1d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-02-05 20:24:30 -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 89f8453ebe Bluetooth: Don't delay bt_conn connected callback
Delaying only connected callback resulted in races where security
or pairing callback could be called before bt_conn connected.

Currently only procedure that relies on read features is connection
parameters update and that should not conflict with other traffic.

Change-Id: I835535abbff21ea8d86b728f5681f90ef9fd337c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:26 -05:00
Szymon Janc 888fac8ac8 Bluetooth: Move connection code to reduce number of ifdefs
Gather SMP related code together so that it can be placed under
single blocks of ifdefs.

Change-Id: I3c2e71243b694e9984ae8e88025a6ead7969e020
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:26 -05:00
Szymon Janc 9c2ad108b8 Bluetooth: Add option for disabling SMP support
This allows to not compile SMP support for devices that don't
require pairing. It is required to support SMP channel and reply
with error for any command received even if pairing is not supported.
To handle this cleanly a null smp implementation is used that case.

Change-Id: I656a52dac882839db904eee65f25a4e29ea2d8c2
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:24:24 -05:00
Johan Hedberg 4817c96b68 Bluetooth: Fix returning unacknowledged packets upon disconnection
The core specification says the following about the treatment of
unacknowledged packets when a disconnection occurs (page 773 in core
spec 4.2):

"When the Host receives a Disconnection Complete, Disconnection Physical
Link Complete or Disconnection Logical Link Complete event, the Host shall
assume that all unacknowledged HCI Data Packets that have been sent to the
Controller for the returned Handle have been flushed, and that the
corresponding data buffers have been freed. A Primary Controller does not
have to notify the Host about this in a Number Of Completed Packets event"

This patch adds tracking of unacknowledged packets on a per-connection
basis and makes sure the semaphore that counts controller buffers is
given back the appropriate amount when a disconnection occurs.

Change-Id: I2ff4d12ffa50d4dda5b3e8c75fc75b4c0927e609
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:16:16 -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
Szymon Janc 57daca9341 Bluetooth: Add callback for security changed
This callback is called if security level of a connection was changed.

Change-Id: I268da245cf4b7f6d2bfbd57969ce2da6c34fc69f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:38 -05:00
Mariusz Skamra 26124136b1 Bluetooth: Set bt_conn role based on LE Connection Complete Event data
bt_conn role can be set when LE Connection Complete event is received.
Controller indicates to both Hosts forming the connection their role
in this connection.

Change-Id: I35455eff54afa30665611415ac52e19089f2e649
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:38 -05:00
Szymon Janc 393dad0ccf Bluetooth: Add callback for identity resolution
This callback is called if identity was resolved for remote device
that was using Resolvable Private Address while connection. From
now on only Identity Address is used.

Change-Id: I5976be575a8e4ad8c13f56d7bc274d751ae37511
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:38 -05:00
Szymon Janc 81c445c02e Bluetooth: Remove not needed src from bt_conn
Since initiator and responder addresses are already tracked it is
no longer needed to store source address in bt_conn structure.

Change-Id: I048e4d4659f4b7d29b101f9f3c5708f66c773906
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:38 -05:00
Szymon Janc 4bf5573055 Bluetooth: SMP: Fix using identity address while re-pairing
When remote device initiate pairing but its IRK is already known
identity address was used to calculate confirmation value. This
resulted in 'Confirm Value Failed' error and pairing failure.

To avoid any confusion simply track initiator and responder addresses
used for connection.

This fix re-enabling security with iPhone if device was unpaired
only on iPhone side.

Change-Id: I07d9589bee5fea7f6b028472b1709090a5755e31
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:38 -05:00
Mariusz Skamra 2b2e67a220 Bluetooth: Move connection callbacks to the conn.c
Since then bt_conn_connected as well as bt_l2cap_disconnected callback
can be called from bt_conn_set_state directly.
Also connected cb could be called from there, however
eg. introduction of some additional state is required TBD.

Change-Id: Ida6906272e1468ef5b41ba8dba2a936db049d308
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:15:37 -05:00
Szymon Janc 9de0ef392f Bluetooth: Add connection security level tracking
Change-Id: Ib2a84f964e5b189969127774ae982539ba38ad87
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-02-05 20:15:24 -05:00
Arkadiusz Lichwa 55607e5e9a Bluetooth: Allocate room for LE read remote features
Prepare room in connection object for result of LE read remote
features procedure.

Change-Id: I30a557656d44a6c35a2a022e8e6e574b52d257be
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:44 -05:00
Johan Hedberg 9e1c434ad9 Bluetooth: Move bt_conn timeout handling into conn.c
Change-Id: I865e86d41e2744a41653195f2b99d365426aee7d
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:43 -05:00
Mariusz Skamra f3232cb999 Bluetooth: Add simple timeout for connection establishment
Adds fiber which starts with some specified delay.
If the fiber is not cancelled, bt_disconnect is called to
cancel creation of connection.

Change-Id: I06667d970ba3398f205f19f1d2e76ab6c283f274
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
Mariusz Skamra b210d53172 Bluetooth: Add initial auto connect support
Calling bt_conn_set_auto_conn one can decide if auto connect shall
be used. If so, everytime the connection is lost, passive scanning
will be enabled to listen for connectable advertisements from
remote device and re-establish the connection.

Auto connect can be disabled if one decide to disconnect from
this device using bt_disconnect or call bt_conn_set_auto_conn
with auto_conn flag set to false.

Change-Id: Ic9952e313cb8612ea6c72838be0755805daeffcf
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:40 -05:00
Johan Hedberg d7ccefd0bd Bluetooth: Fix doxygen comment style
Change-Id: I37b85e83b54f7efb8aded70ec95fd87cafaf7e2b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:35 -05:00
Mariusz Skamra 7ec1617b9f Bluetooth: Introduce BT_CONN_CONNECT_SCAN state
This state will be used for connection establishment during passive scan.
This additional state is necessary, because only one connection can be
in BT_CONN_CONNECT state (LE Create Connection has been sent).
It's because the LE Create Connection Cancel looks for connection in this
state (we cannot look by address, if some controllers respond with
LE Create Connection with address set to 00:00:00:00:00:00).

If connection is BT_CONN_CONNECT_SCAN state it means that we wait for
an advertisement from remote to send LE Create Connection and then we
can change the bt_conn state to BT_CONN_CONNECT.

Change-Id: I48b0352fe08e438f7bfbb1dd12de3d1719f994d8
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:35 -05:00
Mariusz Skamra 648a4923ed Bluetooth: Add bt_conn_lookup_state function
bt_conn_lookup_state looks up for connection with "peer" in specific
state "state". Returns NULL if there is no connection with peer or
connection state differs from the given one.

Passing BT_ADDR_LE_ANY will return the first connection with the
specific state.

Change-Id: Iaa3bb22c9aa31192b8782adb6b11c5051b403758
Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2016-02-05 20:14:31 -05:00
Arkadiusz Lichwa e57984e3be Bluetooth: Make ref on connection object atomic
This makes it possible to perform these operations without
locking once per-conn locking is added in the future.

Change-Id: I342d55856116d9c87daeda4088b65e78e8ef0768
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:31 -05:00
Arkadiusz Lichwa 5e79bfb662 Bluetooth: Refactor internal bt_conn_add() API
Delegates connection object to new connection when there exists
in pool of available connections an object with zeroed destination
LE address.
When there's no reference to the active connection object resets its
peer LE address member.
Replaces routine's input connection handle parameter with LE address.
Moves to the caller setting connection state, connection handle and
call to bt_l2cap_update_conn_param() since connection handle needs
to be valid when such update going to be made.

Change-Id: I81743a915da6cb008f9593dd1940c186a357be6b
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:29 -05:00
Arkadiusz Lichwa 83dab3854d Bluetooth: Refactor existing connection states
Applies new bt_conn_set_state() internal API that now participate in
tracking connections. It concerns only connected and disconnected
events from controller.
Remove bt_conn_del() internal API.

Change-Id: Ic8da46785a7b5e19cae2186047e84e1a5a45a78a
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:28 -05:00
Arkadiusz Lichwa b65e6f3640 Bluetooth: Add new connection states
Adds new possible transitions in tracking connection state.
Reorder available transition value set.

Change-Id: I4f5959c7f98f7a39d8405c23bff9af330e12fcaa
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:28 -05:00
Arkadiusz Lichwa 86001d81f4 Bluetooth: Introduce set connection object state
Typedef so far anonymous enum values allowable connection states
to be set.
Adds interface to allow track connection state.
Update struct bt_conn definition using introduced enum's typedef.

Change-Id: Id91f5a814e4801438f1dcef36fff058faab7beda
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-02-05 20:14:28 -05:00
Johan Hedberg ea15db12ba Bluetooth: Make bt_conn_lookup_addr_le public
This API is useful for applications wanting to monitor and disconnect
connections.

Change-Id: Ib1a98ece364f137262515fbb1163c6b08ddf792c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 2b61b44cbc Bluetooth: Add conn.h public header file
This one should be used for all public connection related APIs. Right
now it includes the reference counting and connection callback APIs.

Change-Id: Ib9b67e6115bb2e51322644757da1170851c3ca17
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00
Johan Hedberg 651e9a4b2e Bluetooth: Rename conn.h to conn_internal.h
We'll have a public conn.h header file soon, so to avoid confusion
rename the existing conn.h to conn_internal.h.

Change-Id: I5e5c89ec184a0a2de63e244b034c55a3d97af9dc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:14:23 -05:00