Commit Graph

1867 Commits

Author SHA1 Message Date
Szymon Janc
6526e66b62 Bluetooth: L2CAP: Rename br_channels to br_fixed_channels
This clarify what this list holds making code more readable.

Change-Id: Ia212cf611cbf2c2deab139324120b993bf14d06f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-04 15:44:45 +00:00
Arkadiusz Lichwa
f30b3debc6 Bluetooth: Refactor distribution of security procedure status
Layers (modules) above HCI like L2CAP need to know status of applied
security procedure when it's triggered on existing connection. It gives
them possibility to make action in layer specific context on
post-security-procedure conditions.

Change-Id: Ia10078469847b29bb7eb3b1fb376ac305dd0b0fc
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 15:15:40 +00:00
Johan Hedberg
a8de2de1f2 Bluetooth: Fix compiler warnings/errors related to string casts
Fix the following compiler warnings/errors that show up with llvm:

    tests/bluetooth/shell/src/main.c:594:2: error:
          initializing 'const uint8_t *' (aka 'const unsigned char *') with an
          expression of type 'char [11]' converts between pointers to integer types
          with different sign [-Werror,-Wpointer-sign]
            BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/bluetooth/bluetooth.h:93:11: note: expanded
          from macro 'BT_DATA'
                    .data = (_data), \
                            ^~~~~~~
    1 error generated.
    net/bluetooth/hci_core.c:1759:22: error: passing
          'uint8_t [248]' to parameter of type 'const char *' converts between
          pointers to integer types with different sign [-Werror,-Wpointer-sign]
                            name_len = strlen(evt->name);
                                              ^~~~~~~~~
    lib/libc/minimal/include/string.h:32:34: note: passing
          argument to parameter 's' here
    extern size_t strlen(const char *s);
                                     ^
      CC      net/bluetooth/log.o
    net/bluetooth/hci_core.c:3136:10: error: passing
          'uint8_t [248]' to parameter of type 'char *' converts between pointers to
          integer types with different sign [-Werror,-Wpointer-sign]
            strncpy(name_cp->local_name, CONFIG_BLUETOOTH_BREDR_NAME,
                    ^~~~~~~~~~~~~~~~~~~
    lib/libc/minimal/include/string.h:30:39: note: passing
          argument to parameter 'd' here
    extern char  *strncpy(char *_Restrict d, const char *_Restrict s, size_t n);
    net/bluetooth/conn.c:301:10: error: passing
          'uint8_t [16]' to parameter of type 'char *' converts between pointers to
          integer types with different sign [-Werror,-Wpointer-sign]
            strncpy(cp->pin_code, pin, sizeof(cp->pin_code));
                    ^~~~~~~~~~~~
    lib/libc/minimal/include/string.h:30:39: note: passing
          argument to parameter 'd' here
    extern char  *strncpy(char *_Restrict d, const char *_Restrict s, size_t n);

Change-Id: I342131c6c2b25445382b2317d673561c4087096b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 12:44:24 +00:00
Itankar, Piyush T
76947d7fe6 Bluetooth: A2DP: Added Connect API
API Implemented Connect API. This can be used to establish A2DP connection.

Change-Id: I8cf714283a452c40b33fd46de442514a1341264c
Signed-off-by: Itankar, Piyush T <piyush.t.itankar@intel.com>
2016-10-04 10:55:04 +00:00
Johan Hedberg
a8df6cd14b Bluetooth: Adjust maximum connections & paired devices range
The maximum allowed values in Kconfig were quite conservative.

Change-Id: Icd2d09a2d52fbbaf03671147f08e08385c6776c7
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 10:46:30 +00:00
Johan Hedberg
9adfb4af17 Bluetooth: RFCOMM: Fix some remaining white-space issues
Change-Id: I56f3ffc9dc9dd18ff204224d1a3166f9dbdc4c3f
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
dde0737f1a Bluetooth: L2CAP: Fix sending double connection request
HCI events 'encryption change' and 'encryption key refresh' can trigger
channel ops 'encrypt_change'. For BR/EDR outgoing channel connection setup,
when new security needs to be set over existing one, CoC channel connection
request to remote is on hold since security got precedence. Then when
security procedure ends controller emits these 2 HCI event one by one.
In such case channel ops 'encrypt_change' is called 2 times causing
indirectly resume held request that can in consequence sent two subsequent
connection requests for the same target channel.

> HCI Event: Simple Pairing Complete (0x36) plen 7	[hci1] 132.169432
        Status: Success (0x00)
        Address: 68:17:29:CF:5D:86 (Intel Corporate)
> HCI Event: Link Key Notification (0x18) plen 23	[hci1] 132.191364
        Address: 68:17:29:CF:5D:86 (Intel Corporate)
        Link key: 949749ea9f6e91cae22bbfdeada2f333
        Key type: Authenticated Combination key from P-192 (0x05)
> HCI Event: Encryption Key Refresh Complete (0x30) plen 3	[hci1] 132.222430
        Status: Success (0x00)
        Handle: 72
> HCI Event: Auth Complete (0x06) plen 3	[hci1] 132.224365
        Status: Success (0x00)
        Handle: 72
< ACL Data TX: Handle 72 flags 0x00 dlen 12	[hci1] 132.229865
      L2CAP: Connection Request (0x02) ident 7 len 4
        PSM: 5 (0x0005)
        Source CID: 65
< HCI Command: Set Connection Encryption (0x01|0x0013) plen 3	[hci1] 132.230340
        Handle: 72
        Encryption: Enabled (0x01)
> HCI Event: Number of Completed Packets (0x13) plen 5	[hci1] 132.232363
        Num handles: 1
        Handle: 72
        Count: 1
> HCI Event: Command Status (0x0f) plen 4	[hci1] 132.234361
      Set Connection Encryption (0x01|0x0013) ncmd 1
        Status: Success (0x00)
> HCI Event: Encryption Change (0x08) plen 4	[hci1] 132.235362
        Status: Success (0x00)
        Handle: 72
        Encryption: Enabled with E0 (0x01)
< ACL Data TX: Handle 72 flags 0x00 dlen 12	[hci1] 132.240960
      L2CAP: Connection Request (0x02) ident 8 len 4
        PSM: 5 (0x0005)
        Source CID: 65
> ACL Data RX: Handle 72 flags 0x02 dlen 16	[hci1] 132.245765
      L2CAP: Connection Response (0x03) ident 7 len 8
        Destination CID: 65
        Source CID: 65
        Result: Connection pending (0x0001)
        Status: Authentication pending (0x0001)
> HCI Event: Number of Completed Packets (0x13) plen 5	[hci1] 132.246360
        Num handles: 1
        Handle: 72
        Count: 1
> ACL Data RX: Handle 72 flags 0x02 dlen 16	[hci1] 132.246987
      L2CAP: Connection Response (0x03) ident 8 len 8
        Destination CID: 0
        Source CID: 65
        Result: Connection refused - no resources available (0x0004)
        Status: No further information available (0x0000)

Change-Id: Ib417b0e701d6ac09c988f3aff0276cd488ed9115
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Jaganath Kanakkassery
5f2d121cf1 Bluetooth: RFCOMM: Replace tabs with spaces
As per the coding guidelines spaces should be used for allignment
of macros.

Change-Id: I8947af32ec64ef3791a88bc3ff151f2fbb3c8480
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-04 08:12:14 +03:00
Johan Hedberg
ea5576145a Bluetooth: RFCOMM: Remove reference counting
The reference counting has been an internal trick to handle the TX
fiber, but it's not really needed since we can do the same thing with
the help of the state value.

Change-Id: I9cdaed9afb0b0c07e23d599637328cb863c123b3
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 08:12:14 +03:00
Jaganath Kanakkassery
7fb0894565 Bluetooth: RFCOMM: Introduce dlc destroy
dlc will be destroyed when ref count reaches 0.
This also moves calling user disconnected callback to destroy
since disocnneted callback will be called whenever dlc is
destroyed regardless of dlc previously been in connected state
or not.

Change-Id: I4a13f8118704c59a88923b74e538063c0db11d77
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-04 08:12:14 +03:00
Jaganath Kanakkassery
5743879d85 Bluetooth: RFCOMM: Introduce rfcomm_send_dm()
DM (Disconnect mode) response is to inform the peer that dlc
is in logically disconnected state. It can be used to reject
an incoming SABM or PN request as well.

For example if a PN request comes to a server channel which is
not registered, a DM response can be sent.

> ACL Data RX: Handle 256 flags 0x02 dlen 18
      Channel: 64 len 14 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Info with Header Check (UIH) (0xef)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0xef poll/final 0
         Length: 10
         FCS: 0x70
         MCC Message type: DLC Parameter Negotiation CMD (0x20)
           Length: 8
           dlci 2 frame_type 0 credit_flow 15 pri 7
           ack_timer 0 frame_size 195 max_retrans 0 credits 7

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect Mode (DM) (0x0f)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x1f poll/final 1
         Length: 0
         FCS: 0x73

Change-Id: I1f7576ad97590eed147505802f59faadacc790ea
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-04 08:12:14 +03:00
Arun Jagadish
2b583eac63 Bluetooth: AVDTP: Connect and Disconnect API
- Connect/Disconnect API
- L2CAP Connected/Disconnected Callback

Change-Id: I852b748adb9825541904dbb43bdb169e7125749f
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
ab0b3a8303 Bluetooth: AVDTP: Fix getting inaccessible internal
conn->handle belongs to core stack space. Apps shouldn't get access to
it. This fixes build/compiler error when Kconfig's DEBUG_AVDTP is defined.

Change-Id: Id188b367e1e4b7d377a7ef59c0f672229ad98fd8
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
13ac9cc9c6 Bluetooth: AVDTP: Remove internal headers
The protocol for audio distribution shouldn't have references to internal
core stack space.

Change-Id: Ifce00856dfb8e48d406f815d54cf4b493a7a2770
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
fdfad74bca Bluetooth: A2DP: Remove internal stack headers
The profile code as sort of user application shouldn't use internal core
stack headers.

Change-Id: I3c6aabf0ee8e1bedac0bd99ebc8526d735219369
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Kaustav Dey Biswas
ab30160708 Bluetooth: SDP: Server: Initialize and accept incoming connections
Initialize SDP, register to L2CAP and accept incoming connections

Change-Id: I568db63910d9e6ff418581b9943d528d4260b859
Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
2016-10-04 08:12:14 +03:00
Johan Hedberg
49d2bb13cd Bluetooth: L2CAP: Extend bt_l2cap_create_pdu() with 'reserve' parameter
This makes it possible for protocols to reserve headroom for their own
headers.

Change-Id: I64530febc4b86b45a379660197f0ff63671fab6e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-10-04 08:12:14 +03:00
Jaganath Kanakkassery
58d47f0b99 Bluetooth: RFCOMM: Handle session disconnection from peer
UA response will be sent and session will be cleaned up.
Session will also be cleaned up if l2cap channel is disconnected.

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0xfd

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x03 cr 1 dlci 0x00
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0xd7

Change-Id: I44997d7d13c90a2a0814520ea11e6f14bc60271f
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
ef1a5527e7 Bluetooth: HFP HF: Enforce Kconfig's HFP_HF relation to RFCOMM
Whenever turning on HFP HF support there's a need to toggle on 
automatically RFCOMM support.

Change-Id: I2fb75c09534d0b6e49a403a527e1caa7d6f9ffaf
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
97b32a0468 Bluetooth: HFP HF: Fix getting inaccessible internal
The profile (application layer) shouldn't use direct (de)references
to internal stack context members.

Change-Id: I772134a5016de6706c30f058545b3c64c0894202
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Szymon Janc
7ea426a8f1 Bluetooth: L2CAP: Cleanup flags names for BR/EDR channels
This makes all flags used for BR/EDR L2CAP be stored in single place.
Connection oriented flags and signaling flags are now sharing same
atomic.

Change-Id: If01b29009f9c60ed529338122992b9b5e31f883a
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-04 08:12:14 +03:00
Jaganath Kanakkassery
5c1ce90926 Bluetooth: RFCOMM: Handle dlc disconnection from peer
Sends UA response for the DISC request from peer and clean up
dlc. Disconnected callback will be called to profile. Dummy
buf and credit will be used to wake up the tx fiber for exit
and cleanup.

> ACL Data RX: Handle 256 flags 0x02 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Disconnect (DISC) (0x43)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x53 poll/final 1
         Length: 0
         FCS: 0xb8

< ACL Data TX: Handle 256 flags 0x00 dlen 8
      Channel: 64 len 4 [PSM 3 mode 0] {chan 0}
      RFCOMM: Unnumbered Ack (UA) (0x63)
         Address: 0x0b cr 1 dlci 0x02
         Control: 0x73 poll/final 1
         Length: 0
         FCS: 0x92

Change-Id: I4ec19a93d13a95a9cf4fc5a9beaf48ba8c98689d
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-10-04 08:12:14 +03:00
Arkadiusz Lichwa
e3506ca120 Bluetooth: RFCOMM: Shuffle up Kconfig's RFCOMM_L2CAP_MTU
Moves RFCOMM frames max length settings directly under the main RFCOMM
selector for better relations readability. It uses 'depends on' clause
for RFCOMM dependency and proper indentation.

Change-Id: Ic4dc0ffddaf8b438ace1f455191b7a707c0e9ed6
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
2016-10-04 08:12:14 +03:00
Szymon Janc
36b8e8cdc8 Bluetooth: Add debug keys support to HCI ECC emulation code
This was initialy done in SMP code but was lost when moved to HCI ECC
emulation. With this patch if CONFIG_BLUETOOTH_USE_DEBUG_KEYS is set
ECC emulation code uses debug public and private keys as specified
in Core Specifitation 4.2 Vol 3. Part H 2.3.5.6.1.

Change-Id: I626e7e1c6bde2baeae642d6f2c60c324fdd0369f
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-04 08:12:14 +03:00
Szymon Janc
f4d75398ca Bluetooth: SMP: Fix unused static variable
gen_method_legacy is used only if SMP SC only mode is not enabled.
This fix compilation warning on some GCC version.

Change-Id: I183c5d0072c2f76da78bf0d2b1077c8d0620f688
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-04 08:12:14 +03:00
Szymon Janc
aa6a9b0066 Bluetooth: SMP: Remove unused static const
This is no longer used and can produce warning on some GCC versions.

Change-Id: Ib19903ea41d6446983a738ea99912dc5ba9b88f8
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-10-04 08:12:14 +03:00
Luiz Augusto von Dentz
6877651a30 Bluetooth: GATT: Fix locking RX fiber
If an indication is received while there is an outstanding request the
code will attempt to get a buffer from req_pool to confirm which may
block causing the RX fiber to lock and probably crash as the request
won't release the buffer until it gets a response or timeout.

JIRA: ZEP-940

Change-Id: I3df30db473a0c6c6c3e63b1d0b410a50bdd3accf
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-04 08:12:14 +03:00
Itankar, Piyush T
acb8c75648 Bluetooth: A2DP: Initialization of A2DP
A2DP Initialization, registers callback functions with AVDTP.

Change-Id: I6b24ca5e7906c08774a173f35da28b1711f34577
Signed-off-by: Itankar, Piyush T <piyush.t.itankar@intel.com>
2016-10-04 08:12:14 +03:00
Luiz Augusto von Dentz
52efcf8acd Bluetooth: AVDTP: Add missing BLUETOOTH_DEBUG_AVDTP
Change-Id: Ib2243f85bb06df9d98d258bce11d4e7ac87f212d
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-04 08:12:14 +03:00
Arun Jagadish
3afc05d816 Bluetooth: AVDTP: Module Initialization
- Data Structure Definition
- Registration and Initialization

Change-Id: Icca95ccbd2692a7d41fd41ef2c99e34761e864b3
Signed-off-by: Arun Jagadish <arun.jagadish@intel.com>
2016-10-04 08:12:14 +03:00
Johan Hedberg
27fc467e74 net: buf: Allow NULL head pointer when inserting to frag list
To avoid extra logic in code that creates net_buf fragment lists, make
it possible to pass a NULL pointer as the head net_buf when there are
no previous buffers. Before this change the code would look like this:

	if (head) {
		net_buf_frag_add(head, buf);
	} else {
		head = net_buf_ref(buf);
	}

After the patch the code can simply do:

	head = net_buf_frag_add(head, buf);

This will then do the right thing regardless if head is NULL or
non-NULL.

Change-Id: I300394242e2e243ed3839b25629ec816dd98c148
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-30 15:07:32 +00:00
Johan Hedberg
8afb6fc229 net: buf: Allow head deletion with net_buf_frag_del()
Extend the net_buf_frag_del() API to be usable for deleting the head
of a fragment chain. This is useful when parsing a stream-based
protocol encoded into a fragment chain, making code such as the
following possible:

	...parse data from 'head' buffer...

	/* If current buffer is empty, move to the next one */
	if (!head->len) {
		head = net_buf_frag_del(NULL, head);
	}

Change-Id: I65794bd7fab4e6dadfd2d6b2fa367f9424fd1bde
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-30 15:07:32 +00:00
Paul Sokolovsky
dbb9094b8a net: Set uIP context on newly allocated buffers immediately.
This context must be set for TX buffers, and there's no better place to
set it than at the allocation time. If not set, it may end up NULL,
causing adverse effects (one seen by few parties is dereferencing random
memory locations to get (random again) MSS values). For RX buffers, uIP
context is set elsewhere too, but anyway, common sense says that if a
buffer is allocated for network context X, and that context uses uIP
connection Y, the a buffer should be just cross-linked with Y during
allocation time, not somewhere later.

Change-Id: Icdb3cd724802ca263c1cd0e3909be811e53822ba
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2016-09-22 12:00:24 +00:00
Luiz Augusto von Dentz
eeccdaca05 Bluetooth: HCI: Fix updating RPA too early
Checking work pending flag does not account the delay before the work is
submitted so this make use a flag to track when the RPA is valid.

Change-Id: I2d858e5163455ce90eb6273c6a8824c5c6d44ae1
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-09-15 14:36:09 +00:00
Szymon Janc
c320abc72c Bluetooth: SMP: Factor out BR/EDR encryption check to helper
This make it easier to follow code flow in #ifdefs blocks.

Change-Id: I06941b9db2a76ea587bae02a3bfbc40abf7f2779
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 11:26:05 +02:00
Szymon Janc
e45d08ef2d Bluetooth: SMP: Add helper for reporting BR/EDR pairing complete
Put code for completing pairing (success or failure) into common
helper.

Jira: ZEP-605

Change-Id: If24328cf421f970f87a0dc6729a6fea83fb83489
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:39 +00:00
Szymon Janc
fd8d725283 Bluetooth: SMP: Add support for Signing Information over BR/EDR
This allows to handle CSRK distributed by remote device.

> ACL Data RX: Handle 11 flags 0x02 dlen 21
      BR/EDR SMP: Signing Information (0x0a) len 16
        Signature key: 32b6247f80dc172be6198649a6322532

Jira: ZEP-605

Change-Id: I01ca67e134d7d8068d0336567a3fa9b9fdafc001
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:34 +00:00
Szymon Janc
f711962344 Bluetooth: SMP: Add support for Identity Information over BR/EDR
Allow to handle IRK distributed by remote device.

> ACL Data RX: Handle 11 flags 0x02 dlen 21
      BR/EDR SMP: Identity Information (0x08) len 16
        Identity resolving key: 286f917356baf6aa27f169fe30030c88
> ACL Data RX: Handle 11 flags 0x02 dlen 12
      BR/EDR SMP: Identity Address Information (0x09) len 7
        Address type: Public (0x00)
        Address: 20:68:9D:60:A1:E4

Jira: ZEP-605

Change-Id: I3c7d32cc6e4cf4d8690edb92089bd433e06f1b4d
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:29 +00:00
Szymon Janc
777d2f5f30 Bluetooth: SMP: Add support for sending Pairing Request over BR/EDR
This allows to send Pairing Request.

Jira: ZEP-605

Change-Id: I0ec2989e4dedb25a51e73b27689f0fd1893ceab8
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:22 +00:00
Szymon Janc
68592f06f6 Bluetooth: SMP: Add support for LTK derivation from LinkKey
This allows to derive LTK from Link Key using H6 function.

Jira: ZEP-625

Change-Id: Ife1e0d770f196174b6d7fc5e8074d76af49934cb
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:15 +00:00
Szymon Janc
790a28ccf4 Bluetooth: SMP: Allow to force BR/EDR without SC support
This option allows to register BR/EDR SMP channel without required
Secure Connections support in controller. This is solely for testing
and should never be enabled in production.

Jira: ZEP-605

Change-Id: I1909c900e323f61acef9fa2b46f22e853beeda75
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:10 +00:00
Szymon Janc
756ac5f63c Bluetooth: SMP: Support Pairing Response over BR/EDR
Handle Pairing Response and distribute keys if required.

Jira: ZEP-605

Change-Id: I2014d38896f9f67095228cb09dab017040570448
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:05 +00:00
Szymon Janc
1d06d941da Bluetooth: SMP: Fix encryption key size check in BR/EDR pairing req
Encryption key size for derived LTK should match one used for BR/EDR
encryption.

Change-Id: Ibcb1c3320cd191ce0d2fda8f5cacaf1ee295fcc4
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:02:00 +00:00
Szymon Janc
85195d2d2e Bluetooth: Add support for reading encryption key size for BR/EDR
Make use of "Read Encryption Key Size" HCI command to read real
encryption key size for BR/EDR connection instead of assuming 16
bytes key size.

< HCI Command: Read Encryption Key Size (0x05|0x0008) plen 2
        Handle: 11
> HCI Event: Command Complete (0x0e) plen 7
      Read Encryption Key Size (0x05|0x0008) ncmd 1
        Status: Success (0x00)
        Handle: 11
        Key size: 16

Change-Id: I372028ce73115d34aedbb6b5ce420144844cfce0
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 06:01:55 +00:00
Johan Hedberg
37d204e03d Bluetooth: Fix giving back pkts semaphore when disconnecting
The TX fiber might be blocked waiting for the num_pkts semaphore when
a disconnection occurs. If we only give back the semaphore once
exiting the while-loop we may end up in a deadlock. Giving back the
semaphore in the connection disconnect handler solves this.

An additional fix this patch does is to ensure that we don't perform
integer underflow because of the last iteration.

Change-Id: Ia67dc506885d0c2bad25c598ea349f1fd251218b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-14 08:45:45 +03:00
Szymon Janc
c31fcf4e5a Bluetooth: SMP: Distribute local keys over BR/EDR
< ACL Data TX: Handle 11 flags 0x00 dlen 21
      BR/EDR SMP: Identity Information (0x08) len 16
        Identity resolving key: 732bf430116b328587de5fda0a4b8c80
< ACL Data TX: Handle 11 flags 0x00 dlen 12
      BR/EDR SMP: Identity Address Information (0x09) len 7
        Address type: Public (0x00)
        Address: 00:02:72:33:45:88

Jira: ZEP-605

Change-Id: I6ba203ea4bbd64c0f05150d3865e6c3bb630b41d
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 08:45:45 +03:00
Szymon Janc
8f9eccac25 Bluetooth: SMP: Support Pairing Failed over BR/EDR
Invalidate received keys on Pairing Failed.

Jira: ZEP-605

Change-Id: I4eec85233ed27312b9f61d89d71329cc665b382b
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 08:45:45 +03:00
Szymon Janc
2cac219a36 Bluetooth: SMP: Support Pairing Request over BR/EDR
This allows to handle Pairing Request and reply with Pairing Response.

> ACL Data RX: Handle 11 flags 0x02 dlen 11
      BR/EDR SMP: Pairing Request (0x01) len 6
        IO capability: DisplayOnly (0x00)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: No bonding, No MITM, Legacy,
                                    No Keypresses (0x00)
        Max encryption key size: 16
        Initiator key distribution: IdKey (0x02)
        Responder key distribution: IdKey (0x02)
< ACL Data TX: Handle 11 flags 0x00 dlen 11
      BR/EDR SMP: Pairing Response (0x02) len 6
        IO capability: DisplayOnly (0x00)
        OOB data: Authentication data not present (0x00)
        Authentication requirement: No bonding, No MITM, Legacy,
                                    No Keypresses (0x00)
        Max encryption key size: 16
        Initiator key distribution: IdKey (0x02)
        Responder key distribution: IdKey (0x02)

Jira: ZEP-605

Change-Id: I886c8d345b87dafae93d692ab39b7f1214bff733
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 08:45:45 +03:00
Szymon Janc
355ef5a5a0 Bluetooth: SMP: Clear keys on timeout when running over BR/EDR
If SMP Timeout occured pairing failed and any keys distributed should
be invalidated.

Jira: ZEP-605

Change-Id: Ibdb9d61c720f9da10232c9bc6148d9ff73ccfa6c
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
2016-09-14 08:45:45 +03:00
Johan Hedberg
3a3238d1b0 Bluetooth: GATT: Fix potential bt_conn reference leak
There was a missing bt_conn_unref() when bt_conn_lookup_addr_le()
returns a connection that's not in BT_CONN_CONNECTED state.

Change-Id: I4c6271d5bf596ea4d9b899e99ce1c7b7c8693f5e
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-14 08:45:45 +03:00