cascardo/linux.git
9 years agoBluetooth: Fix missing hci_dev_lock/unlock in mgmt req_complete()
Jaganath Kanakkassery [Thu, 11 Dec 2014 06:13:12 +0000 (11:43 +0530)]
Bluetooth: Fix missing hci_dev_lock/unlock in mgmt req_complete()

mgmt_pending_remove() should be called with hci_dev_lock protection
and currently the rule to take dev lock is that all mgmt req_complete
functions should take dev lock. So this patch fixes the same in the
missing functions

Without this patch there is a chance of invalid memory access while
accessing the mgmt_pending list like below

bluetoothd:  392] [0] Backtrace:
bluetoothd:  392] [0] [<c04ec770>] (pending_eir_or_class+0x0/0x68) from [<c04f1830>] (add_uuid+0x34/0x1c4)
bluetoothd:  392] [0] [<c04f17fc>] (add_uuid+0x0/0x1c4) from [<c04f3cc4>] (mgmt_control+0x204/0x274)
bluetoothd:  392] [0] [<c04f3ac0>] (mgmt_control+0x0/0x274) from [<c04f609c>] (hci_sock_sendmsg+0x80/0x308)
bluetoothd:  392] [0] [<c04f601c>] (hci_sock_sendmsg+0x0/0x308) from [<c03d4d68>] (sock_aio_write+0x144/0x174)
bluetoothd:  392] [0]  r8:00000000 r7 7c1be90 r6 7c1be18 r5:00000017 r4 a90ea80
bluetoothd:  392] [0] [<c03d4c24>] (sock_aio_write+0x0/0x174) from [<c00e2d4c>] (do_sync_write+0xb0/0xe0)
bluetoothd:  392] [0] [<c00e2c9c>] (do_sync_write+0x0/0xe0) from [<c00e371c>] (vfs_write+0x134/0x13c)
bluetoothd:  392] [0]  r8:00000000 r7 7c1bf70 r6:beeca5c8 r5:00000017 r4 7c05900
bluetoothd:  392] [0] [<c00e35e8>] (vfs_write+0x0/0x13c) from [<c00e3910>] (sys_write+0x44/0x70)
bluetoothd:  392] [0]  r8:00000000 r7:00000004 r6:00000017 r5:beeca5c8 r4 7c05900
bluetoothd:  392] [0] [<c00e38cc>] (sys_write+0x0/0x70) from [<c000e3c0>] (ret_fast_syscall+0x0/0x30)
bluetoothd:  392] [0]  r9 7c1a000 r8:c000e568 r6:400b5f10 r5:403896d8 r4:beeca604
bluetoothd:  392] [0] Code: e28cc00c e152000c 0a00000f e3a00001 (e1d210b8)
bluetoothd:  392] [0] ---[ end trace 67b6ac67435864c4 ]---
bluetoothd:  392] [0] Kernel panic - not syncing: Fatal exception

Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add USB device 04ca:3010 as Atheros AR3012
Janne Heikkinen [Tue, 9 Dec 2014 05:44:51 +0000 (07:44 +0200)]
Bluetooth: Add USB device 04ca:3010 as Atheros AR3012

Asus X553MA has USB device 04ca:3010 that is Atheros AR3012
or compatible.

Device from /sys/kernel/debug/usb/devices:

T:  Bus=01 Lev=02 Prnt=02 Port=03 Cnt=02 Dev#= 27 Spd=12   MxCh= 0
D:  Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=04ca ProdID=3010 Rev= 0.02
C:* #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
A:  FirstIf#= 0 IfCount= 2 Cls=e0(wlcon) Sub=01 Prot=01
I:* If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=81(I) Atr=03(Int.) MxPS=  16 Ivl=1ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=   0 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=   0 Ivl=1ms
I:  If#= 1 Alt= 1 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=   9 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=   9 Ivl=1ms
I:  If#= 1 Alt= 2 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  17 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  17 Ivl=1ms
I:  If#= 1 Alt= 3 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  25 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  25 Ivl=1ms
I:  If#= 1 Alt= 4 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  33 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  33 Ivl=1ms
I:  If#= 1 Alt= 5 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  49 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  49 Ivl=1ms

Signed-off-by: Janne Heikkinen <janne.m.heikkinen@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: fix err_cast.cocci warnings
Fengguang Wu [Sun, 7 Dec 2014 19:04:38 +0000 (03:04 +0800)]
Bluetooth: fix err_cast.cocci warnings

net/bluetooth/smp.c:2650:9-16: WARNING: ERR_CAST can be used with tfm_aes

Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...))

Generated by: scripts/coccinelle/api/err_cast.cocci

Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix generation of non-resolvable private addresses
Marcel Holtmann [Sun, 7 Dec 2014 19:13:17 +0000 (20:13 +0100)]
Bluetooth: Fix generation of non-resolvable private addresses

When the host decides to use a non-resolvable private address, it
must ensure that this generated address does not match the public
address of the controller. Add an extra check to ensure this required
behavior.

In addition rename the variable from urpa to nrpa and fix all of the
comments in the code that use the term unresolvable instead of the
term non-resolvable as used in the Bluetooth specification.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Check for force_lesc_support before rejecting SMP over BR/EDR
Marcel Holtmann [Sun, 7 Dec 2014 15:19:12 +0000 (16:19 +0100)]
Bluetooth: Check for force_lesc_support before rejecting SMP over BR/EDR

The SMP over BR/EDR requests for cross-transport pairing should also
accepted when the debugfs setting force_lesc_support has been enabled.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Check for force_lesc_support when enabling SMP over BR/EDR
Marcel Holtmann [Fri, 5 Dec 2014 23:35:45 +0000 (00:35 +0100)]
Bluetooth: Check for force_lesc_support when enabling SMP over BR/EDR

The SMP over BR/EDR support for cross-transport pairing should also be
enabled when the debugfs setting force_lesc_support has been enabled.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Enable events for P-256 Public Key and DHKey commands
Marcel Holtmann [Fri, 5 Dec 2014 15:20:15 +0000 (16:20 +0100)]
Bluetooth: Enable events for P-256 Public Key and DHKey commands

When the LE Read Local P-256 Public Key command is supported, then
enable its corresponding complete event. And when the LE Generate DHKey
command is supported, enable its corresponding complete event as well.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add support for enabling Extended Scanner Filter Policies
Marcel Holtmann [Fri, 5 Dec 2014 15:20:14 +0000 (16:20 +0100)]
Bluetooth: Add support for enabling Extended Scanner Filter Policies

The new Extended Scanner Filter Policies feature has to be enabled by
selecting the correct filter policy for the scan parameters. This
patch does that when the controller has been enabled to use LE Privacy.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add support for handling LE Direct Advertising Report events
Marcel Holtmann [Fri, 5 Dec 2014 15:20:13 +0000 (16:20 +0100)]
Bluetooth: Add support for handling LE Direct Advertising Report events

When the controller sends a LE Direct Advertising Report event, the host
must confirm that the resolvable random address provided matches with
its own identity resolving key. If it does, then that advertising report
needs to be processed. If it does not match, the report needs to be
ignored.

This patch adds full support for handling these new reports and using
them for device discovery and connection handling. This means when a
Bluetooth controller supports the Extended Scanner Filter Policies, it
is possible to use directed advertising with LE privacy.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Enabled LE Direct Advertising Report event if supported
Marcel Holtmann [Fri, 5 Dec 2014 15:20:12 +0000 (16:20 +0100)]
Bluetooth: Enabled LE Direct Advertising Report event if supported

When the controller supports the Extended Scanner Filter Policies, it
supports the LE Direct Advertising Report event. However by default
that event is blocked by the LE event mask. It is required to enable
it during controller setup.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add definitions for LE Direct Advertising Report event
Marcel Holtmann [Fri, 5 Dec 2014 15:20:11 +0000 (16:20 +0100)]
Bluetooth: Add definitions for LE Direct Advertising Report event

This patch adds the event id and data structures for the LE Direct
Advertising Report event.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Move LE advertising report defines to the right location
Marcel Holtmann [Fri, 5 Dec 2014 15:20:10 +0000 (16:20 +0100)]
Bluetooth: Move LE advertising report defines to the right location

All Bluetooth commands and events are ordered by its opcode or event
id, but for some reason this one now stands out. So move it to its
correct spot in the list.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agocc2520: adds terminating newline
Varka Bhadram [Fri, 5 Dec 2014 11:49:10 +0000 (17:19 +0530)]
cc2520: adds terminating newline

Signed-off-by: Varka Bhadram <varkab@cdac.in>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agomac802154: use goto label on failure
Varka Bhadram [Fri, 5 Dec 2014 11:49:09 +0000 (17:19 +0530)]
mac802154: use goto label on failure

Signed-off-by: Varka Bhadram <varkab@cdac.in>
Reviewed-by: Stefan Schmidt <s.schmidt@samsung.com>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Report invalid RSSI for service discovery and background scan
Marcel Holtmann [Fri, 5 Dec 2014 12:03:35 +0000 (13:03 +0100)]
Bluetooth: Report invalid RSSI for service discovery and background scan

When using Start Service Discovery and when background scanning is used
to report devices, the RSSI is reported or the value 127 is provided in
case RSSI in unavailable.

For Start Discovery the value 0 is reported to keep backwards
compatibility with the existing users.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Fix discovery filter when no RSSI is available
Marcel Holtmann [Fri, 5 Dec 2014 12:03:34 +0000 (13:03 +0100)]
Bluetooth: Fix discovery filter when no RSSI is available

When no RSSI value is available then make sure that the result is
filtered out when the RSSI threshold filter is active.

This means that all Bluetooth 1.1 or earlier devices will not
report any results when using a RSSI threshold filter.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Remove redundant reverse_base_uuid variable
Johan Hedberg [Fri, 5 Dec 2014 11:40:01 +0000 (13:40 +0200)]
Bluetooth: Remove redundant reverse_base_uuid variable

The mgmt.c file already has a bluetooth_base_uuid variable which has the
exact same value as the reverse_base_uuid one. This patch removes the
redundant variable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix Get Conn Info to use cmd_complete callback
Johan Hedberg [Fri, 5 Dec 2014 11:42:57 +0000 (13:42 +0200)]
Bluetooth: Fix Get Conn Info to use cmd_complete callback

This patch fixes the Get Connection Information mgmt command to take
advantage of the new cmd_complete callback. This allows for great
simplifications in the logic for constructing the cmd_complete event.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix initializing hci_conn RSSI to invalid value
Johan Hedberg [Fri, 5 Dec 2014 11:36:08 +0000 (13:36 +0200)]
Bluetooth: Fix initializing hci_conn RSSI to invalid value

When we create the hci_conn object we should properly initialize the
RSSI to HCI_RSSI_INVALID.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Convert Get Clock Info to use cmd_complete callback
Johan Hedberg [Fri, 5 Dec 2014 11:36:07 +0000 (13:36 +0200)]
Bluetooth: Convert Get Clock Info to use cmd_complete callback

This patch converts the Get Clock Information mgmt command to take
advantage of the new cmd_complete callback for pending commands.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Convert discovery commands to use cmd_complete callback
Johan Hedberg [Fri, 5 Dec 2014 11:36:06 +0000 (13:36 +0200)]
Bluetooth: Convert discovery commands to use cmd_complete callback

This patch converts the Start/Stop Discovery mgmt commands to use the
cmd_complete callback of struct pending_cmd. Since both of these
commands return the same parameters as they take as input we can use the
existing generic_cmd_complete() helper for this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Convert Unpair Device to use cmd_complete callback
Johan Hedberg [Fri, 5 Dec 2014 11:36:05 +0000 (13:36 +0200)]
Bluetooth: Convert Unpair Device to use cmd_complete callback

This patch updates the Unpair Device code to take advantage of the
cmd_complete callback of struct pending_cmd.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Convert Pair Device to use cmd_complete callback
Johan Hedberg [Fri, 5 Dec 2014 11:36:04 +0000 (13:36 +0200)]
Bluetooth: Convert Pair Device to use cmd_complete callback

This patch converts the Pair Device mgmt command to use the new
cmd_complete callback for pending mgmt commands. The already existing
pairing_complete() function is exactly what's needed and doesn't need
changing.

In addition to getting the return parameters always right this patch
actually fixes a reference counting bug and memory leak with the
hci_conn that's attached to the pending mgmt command - something that
would occur when powering off or unplugging the adapter while pairing is
in progress.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Use cmd_complete callback for authentication mgmt commands
Johan Hedberg [Fri, 5 Dec 2014 11:36:03 +0000 (13:36 +0200)]
Bluetooth: Use cmd_complete callback for authentication mgmt commands

This patch converts the user confirmation & PIN code mgmt commands to
take advantage of the new cmd_complete callback for pending mgmt
commands. The patch also adds a new generic addr_cmd_complete() helper
function to be used with commands that send a mgmt_addr_info response
based on a mgmt_addr_info in the beginning of the command parameters.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Convert Disconnect mgmt command to use cmd_complete callback
Johan Hedberg [Fri, 5 Dec 2014 11:36:02 +0000 (13:36 +0200)]
Bluetooth: Convert Disconnect mgmt command to use cmd_complete callback

This patch converts the Disconnect mgmt command to take advantage of the
new cmd_complete callback that's part of the pending_cmd struct. There
are many commands whose response parameters map 1:1 to the command
parameters and Disconnect is one of them. This patch adds a
generic_cmd_complete() function for such commands that can be reused in
subsequent patches.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Store parameter length with pending mgmt commands
Johan Hedberg [Fri, 5 Dec 2014 11:36:01 +0000 (13:36 +0200)]
Bluetooth: Store parameter length with pending mgmt commands

As preparation for making generic cmd_complete responses possible we'll
need to track the parameter length in addition to just a pointer to
them. This patch adds the necessary variable to the pending_cmd struct.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add callback to create proper cmd_complete events
Johan Hedberg [Fri, 5 Dec 2014 11:36:00 +0000 (13:36 +0200)]
Bluetooth: Add callback to create proper cmd_complete events

We've got a couple of generic scenarios where all pending mgmt commands
are processed and responses are sent to them. These scenarios are
powering off the adapter and removing the adapter. So far the code has
been generating cmd_status responses with NOT_POWERED and INVALID_INDEX
resposes respectively, but this violates the mgmt specification for
commands that should always generate a cmd_complete.

This patch adds support for specifying a callback for the pending_cmd
context that each command handler can use for command-specific
cmd_complete event generation. The actual per-command event generators
will come in subsequent patches.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agonet/mac802154: No need for an extra space when casting
Stefan Schmidt [Thu, 4 Dec 2014 10:52:01 +0000 (11:52 +0100)]
net/mac802154: No need for an extra space when casting

Coding style cleanup.

Signed-off-by: Stefan Schmidt <s.schmidt@samsung.com>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agonet/mac802154: Remove extra blank lines.
Stefan Schmidt [Thu, 4 Dec 2014 10:52:00 +0000 (11:52 +0100)]
net/mac802154: Remove extra blank lines.

Signed-off-by: Stefan Schmidt <s.schmidt@samsung.com>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agonet/ieee802154: Remove and add extra blank lines as needed.
Stefan Schmidt [Thu, 4 Dec 2014 10:51:59 +0000 (11:51 +0100)]
net/ieee802154: Remove and add extra blank lines as needed.

Some have been missing and some have been needed. Just cosmetics.

Signed-off-by: Stefan Schmidt <s.schmidt@samsung.com>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agonet/ieee802154: Make sure alignment matches parenthesis..
Stefan Schmidt [Thu, 4 Dec 2014 10:51:58 +0000 (11:51 +0100)]
net/ieee802154: Make sure alignment matches parenthesis..

Follow coding style of the kernel.

Signed-off-by: Stefan Schmidt <s.schmidt@samsung.com>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agonet/6lowpan: Remove FSF address from GPL statement.
Stefan Schmidt [Thu, 4 Dec 2014 10:51:57 +0000 (11:51 +0100)]
net/6lowpan: Remove FSF address from GPL statement.

This might change and we already deliver a copy of the license with
the kernel. This was already removed form the ieee802154 code but
missed here.

Signed-off-by: Stefan Schmidt <s.schmidt@samsung.com>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Acked-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Clear discovery filter before starting background scan
Marcel Holtmann [Fri, 5 Dec 2014 10:45:23 +0000 (11:45 +0100)]
Bluetooth: Clear discovery filter before starting background scan

Currently the discovery filter information are only cleared when the
actual discovery procedure has been stopped. To make sure that none
of the filters interfere with the background scanning and its device
found event reporting, clear the filter before starting background
scanning.

This means that the discovery filter is now cleared before either
Start Discovery, Start Service Discovery or background scanning.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Fix memory leaks from discovery filter UUID list
Marcel Holtmann [Fri, 5 Dec 2014 10:45:22 +0000 (11:45 +0100)]
Bluetooth: Fix memory leaks from discovery filter UUID list

In case of failure or when unplugging a controller, the allocated
memory for the UUID list of the discovery filter is not freed. Use
the newly introduced helper for reset the discovery filter and with
that also freeing existing memory.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add helper function for clearing the discovery filter
Marcel Holtmann [Fri, 5 Dec 2014 10:45:21 +0000 (11:45 +0100)]
Bluetooth: Add helper function for clearing the discovery filter

The discovery filter allocates memory for its UUID list. So use
a helper function to free it and reset it to default states.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add support for Start Service Discovery command
Jakub Pawlowski [Fri, 5 Dec 2014 09:55:59 +0000 (10:55 +0100)]
Bluetooth: Add support for Start Service Discovery command

This patch adds support for the Start Service Discovery command. It
does all the checks for command parameters and configured the discovery
filter settings correctly. However the actual support for filtering
will be added with another patch.

Signed-off-by: Jakub Pawlowski <jpawlowski@google.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add logic for UUID filter handling
Jakub Pawlowski [Fri, 5 Dec 2014 09:55:58 +0000 (10:55 +0100)]
Bluetooth: Add logic for UUID filter handling

The previous patch provided the framework for integrating the UUID
filtering into the service discovery. This patch now provides the
actual filter logic.

Signed-off-by: Jakub Pawlowski <jpawlowski@google.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add framework for device found filtering based on UUID
Marcel Holtmann [Fri, 5 Dec 2014 09:55:57 +0000 (10:55 +0100)]
Bluetooth: Add framework for device found filtering based on UUID

Using Start Service Discovery provides the option to specifiy a list
of UUID that are used to filter out device found events. This patch
provides the framework for hooking up the UUID filter.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Filter device found events based on RSSI threshold
Marcel Holtmann [Fri, 5 Dec 2014 09:55:56 +0000 (10:55 +0100)]
Bluetooth: Filter device found events based on RSSI threshold

Using Start Service Discovery allows to provide a RSSI threshold. This
patch implements support for filtering out device found events based
on the provided value.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add extra discovery fields for storing filter information
Jakub Pawlowski [Fri, 5 Dec 2014 09:55:55 +0000 (10:55 +0100)]
Bluetooth: Add extra discovery fields for storing filter information

With the upcoming addition of support for Start Service Discovery, the
discovery handling needs to filter on RSSI and UUID values. For that
they need to be stored in the discovery handling. This patch adds the
appropiate fields and also make sure they are reset when discovery
has been stopped.

Signed-off-by: Jakub Pawlowski <jpawlowski@google.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add definitions for MGMT_OP_START_SERVICE_DISCOVERY
Jakub Pawlowski [Fri, 5 Dec 2014 09:55:54 +0000 (10:55 +0100)]
Bluetooth: Add definitions for MGMT_OP_START_SERVICE_DISCOVERY

This patch adds the opcode and structure for Start Service Discovery
operation.

Signed-off-by: Jakub Pawlowski <jpawlowski@google.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add HCI_RSSI_INVALID for unknown RSSI value
Marcel Holtmann [Fri, 5 Dec 2014 09:55:53 +0000 (10:55 +0100)]
Bluetooth: Add HCI_RSSI_INVALID for unknown RSSI value

The Bluetooth core specification defines the value 127 as invalid for
RSSI values. So instead of hard coding it, lets add a constant for it.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Split triggering of discovery commands into separate function
Marcel Holtmann [Thu, 4 Dec 2014 10:36:36 +0000 (11:36 +0100)]
Bluetooth: Split triggering of discovery commands into separate function

The actual process of compiling the correct HCI commands for triggering
discovery is something that should be generic. So instead of mixing it
into the Start Discover operation handling, split it out into its own
function utilizing HCI request handling and just providing status in
case of errors or invalid parameters.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Use {start,stop}_discovery_complete handler for cmd_complete
Marcel Holtmann [Thu, 4 Dec 2014 10:36:35 +0000 (11:36 +0100)]
Bluetooth: Use {start,stop}_discovery_complete handler for cmd_complete

Sending the required cmd_complete for the management commands should be
done in one place and not in multiple places. Especially for Start and
Stop Discovery commands this is split into to sending it in case of
failure from the complete handler, but in case of success from the
event state update function triggering mgmt_discovering. This is way
too convoluted and since hci_request serializes the HCI command
processing, send the cmd_complete response from the complete handler
for all cases.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Simplify the error handling of Start Discovery command
Marcel Holtmann [Thu, 4 Dec 2014 10:36:34 +0000 (11:36 +0100)]
Bluetooth: Simplify the error handling of Start Discovery command

The Start Discovery command has some complicated code when it comes
to error handling. With the future introduction of Start Service
Discovery simplifying this makes it easier to read.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Increment management interface revision
Marcel Holtmann [Wed, 3 Dec 2014 18:52:43 +0000 (19:52 +0100)]
Bluetooth: Increment management interface revision

This patch increments the management interface revision due to the
addition of support for LE Secure Connection feature.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Increase minor version of core module
Marcel Holtmann [Wed, 3 Dec 2014 18:46:10 +0000 (19:46 +0100)]
Bluetooth: Increase minor version of core module

With the addition of support for Bluetooth Low Energy Secure Connections
feature, it makes sense to increase the minor version of the Bluetooth
core module.

The module version is not used anywhere, but it gives a nice extra
hint for debugging purposes.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
9 years agoBluetooth: Add support for Broadcom BCM20702A0 variants firmware download
Heinrich Siebmanns [Wed, 3 Dec 2014 18:32:22 +0000 (19:32 +0100)]
Bluetooth: Add support for Broadcom BCM20702A0 variants firmware download

This requires the flag BTUSB_BCM_PATCHRAM to work.

Relevant details from /sys/kernel/debug/usb/devices for my device:

T:  Bus=03 Lev=02 Prnt=02 Port=03 Cnt=02 Dev#=  4 Spd=12   MxCh= 0
D:  Ver= 2.00 Cls=ff(vend.) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=0489 ProdID=e031 Rev= 1.12
S:  Manufacturer=Broadcom Corp
S:  Product=BCM20702A0
S:  SerialNumber=3859F9CD2AEE
C:* #Ifs= 4 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=81(I) Atr=03(Int.) MxPS=  16 Ivl=1ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=   0 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=   0 Ivl=1ms
I:  If#= 1 Alt= 1 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=   9 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=   9 Ivl=1ms
I:  If#= 1 Alt= 2 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  17 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  17 Ivl=1ms
I:  If#= 1 Alt= 3 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  25 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  25 Ivl=1ms
I:  If#= 1 Alt= 4 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  33 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  33 Ivl=1ms
I:  If#= 1 Alt= 5 #EPs= 2 Cls=ff(vend.) Sub=01 Prot=01 Driver=btusb
E:  Ad=83(I) Atr=01(Isoc) MxPS=  49 Ivl=1ms
E:  Ad=03(O) Atr=01(Isoc) MxPS=  49 Ivl=1ms
I:* If#= 2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
E:  Ad=84(I) Atr=02(Bulk) MxPS=  32 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS=  32 Ivl=0ms
I:* If#= 3 Alt= 0 #EPs= 0 Cls=fe(app. ) Sub=01 Prot=01 Driver=(none)

The firmware was extracted from a Windows 7 32-bit installation
and converted from 'hex' to 'hcd' for use in Linux.

The firmware is named "BCM20702A0_001.001.024.0156.0204.hex"
and is located in "%SYSTEMROOT%\system32\drivers\"
(md5 d126e6c4e0e669d76c38cf9377f76b7f)
(sha1 145d1850b2785a953233b409e7ff77786927c7d2)

The firmware file is also available as a download at
http://support.ts.fujitsu.com/Download/
contained in "FTS_WIDCOMMBluetoothSoftware_6309000_1072149.zip"

Search for the file Win32/bcbtums-win7x86-brcm.inf in the archive,
look for the vendor and product ID of your adapter, see the section
'devices' in that file to find out what device name it uses. See
the device entry in the inf file (in my case it was 'RAMUSBE031')
to find out which hex file you need to convert to hcd for upload

'hcd' file should be placed at "brcm/BCM20702A0-0489-e031.hcd"
inside the firmware directory (e.g. "/lib/firmware")

Signed-off-by: Heinrich Siebmanns <harv@gmx.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: btmrvl add firmware dump support
Xinming Hu [Mon, 24 Nov 2014 10:40:53 +0000 (02:40 -0800)]
Bluetooth: btmrvl add firmware dump support

This patch adds firmware dump support for marvell
bluetooth chipset. Currently only SD8897 is supported.
This is implemented based on dev_coredump, a new mechnism
introduced in kernel 3.18rc3

Firmware dump can be trigger by
echo 1 > /sys/kernel/debug/bluetooth/hci*/config/fw_dump
and when the dump operation is completed, data can be read by
cat /sys/class/devcoredump/devcd*/data

We have prepared following script to divide fw memory
dump data into multiple files based on memory type.

 [root]# cat btmrvl_split_dump_data.sh
 #!/bin/bash
 # usage: ./btmrvl_split_dump_data.sh dump_data

 fw_dump_data=$1

 mem_type="ITCM DTCM SQRAM APU CIU ICU MAC EXT7 EXT8 EXT9 EXT10 EXT11 EXT12 EXT13 EXTLAST"

 for name in ${mem_type[@]}
 do
         sed -n "/Start dump $name/,/End dump/p" $fw_dump_data  > tmp.$name.log
         if [ ! -s tmp.$name.log ]
                 then
                         rm -rf tmp.$name.log
                 else
                         # Remove the describle info "Start dump" and "End dump"
                         sed '1d' tmp.$name.log | sed '$d' > /data/$name.log
                         if [ -s /data/$name.log ]
                         then
                                 echo "generate /data/$name.log"
                         else
                                 sed '1d' tmp.$name.log | sed '$d' > /var/$name.log
                                 echo "generate /var/$name.log"
                         fi
                         rm -rf tmp.$name.log
         fi
 done

Signed-off-by: Xinming Hu <huxm@marvell.com>
Signed-off-by: Cathy Luo <cluo@marvell.com>
Signed-off-by: Avinash Patil <patila@marvell.com>
Reviewed-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: btmrvl: remove extra newline character
Amitkumar Karwar [Mon, 24 Nov 2014 10:40:52 +0000 (02:40 -0800)]
Bluetooth: btmrvl: remove extra newline character

BT_INFO/BT_DBG etc. already takes care of adding a newline
An extra newline character inside message is removed in this
patch.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix false-positive "uninitialized" compiler warning
Johan Hedberg [Wed, 3 Dec 2014 14:26:37 +0000 (16:26 +0200)]
Bluetooth: Fix false-positive "uninitialized" compiler warning

Some gcc versions don't seem to be able to properly track the flow of
the smp_cmd_pairing_random() function and end up causing the following
types of (false-positive) warnings:

 smp.c:1995:6: warning: â€˜nb’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);
 smp.c:1995:6: warning: â€˜na’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);
       ^
 smp.c:1995:6: warning: â€˜pkbx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);
       ^
 smp.c:1995:6: warning: â€˜pkax’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);

This patch fixes the issue by moving the pkax/pkbx and na/nb
initialization earlier in the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix minor coding style issue in smp.c
Johan Hedberg [Wed, 3 Dec 2014 14:07:13 +0000 (16:07 +0200)]
Bluetooth: Fix minor coding style issue in smp.c

The convention for checking for NULL pointers is !ptr and not
ptr == NULL. This patch fixes such an occurrence in smp.c.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix SMP debug key handling
Johan Hedberg [Wed, 3 Dec 2014 10:43:39 +0000 (12:43 +0200)]
Bluetooth: Fix SMP debug key handling

We need to keep debug keys around at least until the point that they are
used - otherwise e.g. slave role behavior wouldn't work as there'd be no
key to be looked up. The correct behavior should therefore be to return
any stored keys but when we clean up the SMP context to remove the key
from the hdev list if keeping debug keys around hasn't been requestsed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Organize SMP crypto functions to logical sections
Johan Hedberg [Tue, 2 Dec 2014 11:39:23 +0000 (13:39 +0200)]
Bluetooth: Organize SMP crypto functions to logical sections

This patch organizes the various SMP crypto functions so that the LE SC
functions appear in one section and the legacy SMP functions in a
separate one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix missing const declarations in SMP functions
Johan Hedberg [Tue, 2 Dec 2014 11:37:41 +0000 (13:37 +0200)]
Bluetooth: Fix missing const declarations in SMP functions

Several SMP functions take read-only data. This patch fixes the
declaration of these parameters to use the const specifier as
appropriate.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Introduce SMP_DBG macro for low-level debuging
Johan Hedberg [Mon, 1 Dec 2014 20:03:16 +0000 (22:03 +0200)]
Bluetooth: Introduce SMP_DBG macro for low-level debuging

The various inputs & outputs of the crypto functions as well as the
values of the ECDH keys can be considered security sensitive. They
should therefore not end up in dmesg by mistake. This patch introduces a
new SMP_DBG macro which requires explicit compilation with -DDEBUG to be
enabled. All crypto related data logs now use this macro instead of
BT_DBG.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add basic LE SC OOB support for remote OOB data
Johan Hedberg [Tue, 28 Oct 2014 14:17:05 +0000 (15:17 +0100)]
Bluetooth: Add basic LE SC OOB support for remote OOB data

This patch adds basic OOB pairing support when we've received the remote
OOB data. This includes tracking the remote r value (in smp->rr) as well
as doing the appropriate f4() call when needed. Previously the OOB rand
would have been stored in smp->rrnd however these are actually two
independent values so we need separate variables for them. Na/Nb in the
spec maps to smp->prnd/rrnd and ra/rb maps to smp->rr with smp->pr to
come once local OOB data is supported.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Set SMP OOB flag if OOB data is available
Johan Hedberg [Sun, 26 Oct 2014 20:19:10 +0000 (21:19 +0100)]
Bluetooth: Set SMP OOB flag if OOB data is available

If we have OOB data available for the remote device in question we
should set the OOB flag appropriately in the SMP pairing request or
response.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for adding remote OOB data for LE
Johan Hedberg [Sun, 26 Oct 2014 19:52:27 +0000 (20:52 +0100)]
Bluetooth: Add support for adding remote OOB data for LE

This patch adds proper support for passing LE OOB data to the
hci_add_remote_oob_data() function. For LE the 192-bit values are not
valid and should therefore be passed as NULL values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Store address type with OOB data
Johan Hedberg [Sun, 26 Oct 2014 19:46:09 +0000 (20:46 +0100)]
Bluetooth: Store address type with OOB data

To be able to support OOB data for LE pairing we need to store the
address type of the remote device. This patch extends the relevant
functions and data types with a bdaddr_type variable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Unify remote OOB data functions
Johan Hedberg [Sun, 26 Oct 2014 19:33:47 +0000 (20:33 +0100)]
Bluetooth: Unify remote OOB data functions

There's no need to duplicate code for the 192 vs 192+256 variants of the
OOB data functions. This is also helpful to pave the way to support LE
SC OOB data where only 256 bit data is provided.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add SC-only mode support for SMP
Johan Hedberg [Mon, 8 Sep 2014 23:59:18 +0000 (16:59 -0700)]
Bluetooth: Add SC-only mode support for SMP

When Secure Connections-only mode is enabled we should reject any
pairing command that does not have Secure Connections set in the
authentication requirements. This patch adds the appropriate logic for
this to the command handlers of Pairing Request/Response and Security
Request.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add full SMP BR/EDR support
Johan Hedberg [Thu, 14 Aug 2014 09:34:26 +0000 (12:34 +0300)]
Bluetooth: Add full SMP BR/EDR support

When doing SMP over BR/EDR some of the routines can be shared with the
LE functionality whereas others needs to be split into their own BR/EDR
specific branches. This patch implements the split of BR/EDR specific
SMP code from the LE-only code, making sure SMP over BR/EDR works as
specified.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add skeleton for BR/EDR SMP channel
Johan Hedberg [Wed, 13 Aug 2014 12:12:32 +0000 (15:12 +0300)]
Bluetooth: Add skeleton for BR/EDR SMP channel

This patch adds the very basic code for creating and destroying SMP
L2CAP channels for BR/EDR connections.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add debugfs switch for forcing SMP over BR/EDR
Johan Hedberg [Thu, 16 Oct 2014 08:45:31 +0000 (10:45 +0200)]
Bluetooth: Add debugfs switch for forcing SMP over BR/EDR

To make it possible to use LE SC functionality over BR/EDR with pre-4.1
controllers (that do not support BR/EDR SC links) it's useful to be able
to force LE SC operations even over a traditional SSP protected link.
This patch adds a debugfs switch to force a special debug flag which is
used to skip the checks for BR/EDR SC support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add hci_conn flag for new link key generation
Johan Hedberg [Thu, 14 Aug 2014 09:33:17 +0000 (12:33 +0300)]
Bluetooth: Add hci_conn flag for new link key generation

For LE Secure Connections we want to trigger cross transport key
generation only if a new link key was actually created during the BR/EDR
connection. This patch adds a new flag to track this information.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Use debug keys for SMP when HCI_USE_DEBUG_KEYS is set
Johan Hedberg [Tue, 24 Jun 2014 12:22:59 +0000 (15:22 +0300)]
Bluetooth: Use debug keys for SMP when HCI_USE_DEBUG_KEYS is set

The HCI_USE_DEBUG_KEYS flag is intended to force our side to always use
debug keys for pairing. This means both BR/EDR SSP as well as SMP with
LE Secure Connections. This patch updates the SMP code to use the debug
keys instead of generating a random local key pair when the flag is set.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add dummy handler for LE SC keypress notification
Johan Hedberg [Wed, 4 Jun 2014 19:45:57 +0000 (22:45 +0300)]
Bluetooth: Add dummy handler for LE SC keypress notification

Since we don not actively try to clear the keypress notification bit we
might get these PDUs. To avoid failing the pairing process add a simple
dummy handler for these for now.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix DHKey Check sending order for slave role
Johan Hedberg [Wed, 4 Jun 2014 08:07:40 +0000 (11:07 +0300)]
Bluetooth: Fix DHKey Check sending order for slave role

According to the LE SC specification the initiating device sends its
DHKey check first and the non-initiating devices sends its DHKey check
as a response to this. It's also important that the non-initiating
device doesn't send the response if it's still waiting for user input.
In order to synchronize all this a new flag is added.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add passkey entry support for LE SC
Johan Hedberg [Wed, 25 Jun 2014 08:10:28 +0000 (11:10 +0300)]
Bluetooth: Add passkey entry support for LE SC

The passkey entry mechanism involves either both sides requesting the
user for a passkey, or one side requesting the passkey while the other
one displays it. The behavior as far as SMP PDUs are concerned are
considerably different from numeric comparison and therefore requires
several new functions to handle it.

In essence passkey entry involves both sides gradually committing to
each bit of the passkey which involves 20 rounds of pairing confirm and
pairing random PDUS being sent in both directions.

This patch adds a new smp->passkey_round variable to track the current
round of the passkey commitment and reuses the variables already present
in struct hci_conn for the passkey and entered key count.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Fix BR/EDR Link Key type when derived through LE SC
Johan Hedberg [Sun, 1 Jun 2014 13:33:39 +0000 (16:33 +0300)]
Bluetooth: Fix BR/EDR Link Key type when derived through LE SC

We need to set the correct Link Key type based on the properties of the
LE SC pairing that it was derived from. If debug keys were used the type
should be a debug key, and the authenticated vs unauthenticated
information should be set on what kind of security level was reached.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for SC just-works pairing
Johan Hedberg [Sun, 1 Jun 2014 12:38:09 +0000 (15:38 +0300)]
Bluetooth: Add support for SC just-works pairing

If the just-works method was chosen we shouldn't send anything to user
space but simply proceed with sending the DHKey Check PDU. This patch
adds the necessary code for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Set correct LTK type and authentication for SC
Johan Hedberg [Sat, 31 May 2014 15:53:36 +0000 (18:53 +0300)]
Bluetooth: Set correct LTK type and authentication for SC

After generating the LTK we should set the correct type (normal SC or
debug) and authentication information for it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add check for accidentally generating a debug key
Johan Hedberg [Fri, 6 Jun 2014 12:33:30 +0000 (15:33 +0300)]
Bluetooth: Add check for accidentally generating a debug key

It is very unlikely, but to have a 100% guarantee of the generated key
type we need to reject any keys which happen to match the debug key.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Detect SMP SC debug keys
Johan Hedberg [Sat, 31 May 2014 15:52:28 +0000 (18:52 +0300)]
Bluetooth: Detect SMP SC debug keys

We need to be able to detect if the remote side used a debug key for the
pairing. This patch adds the debug key defines and sets a flag to
indicate that a debug key was used. The debug private key (debug_sk) is
also added in this patch but will only be used in a subsequent patch
when local debug key support is implemented.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add selection of the SC authentication method
Johan Hedberg [Sat, 31 May 2014 15:51:02 +0000 (18:51 +0300)]
Bluetooth: Add selection of the SC authentication method

This patch adds code to select the authentication method for Secure
Connections based on the local and remote capabilities. A new
DSP_PASSKEY method is also added for displaying the passkey - something
that is not part of legacy SMP pairing.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Track authentication method in SMP context
Johan Hedberg [Sat, 31 May 2014 15:48:26 +0000 (18:48 +0300)]
Bluetooth: Track authentication method in SMP context

For Secure Connections we'll select the authentication method as soon as
we receive the public key, but only use it later (both when actually
triggering the method as well as when determining the quality of the
resulting LTK). Store the method therefore in the SMP context.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for LE SC key generation
Johan Hedberg [Fri, 6 Jun 2014 08:54:04 +0000 (11:54 +0300)]
Bluetooth: Add support for LE SC key generation

As the last step of the LE SC pairing process it's time to generate and
distribute keys. The generation part is unique to LE SC and so this
patch adds a dedicated function for it. We also clear the distribution
bits for keys which are not distributed with LE SC, so that the code
shared with legacy SMP will not go ahead and try to distribute them.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for LE SC DHKey check PDU
Johan Hedberg [Fri, 6 Jun 2014 08:47:30 +0000 (11:47 +0300)]
Bluetooth: Add support for LE SC DHKey check PDU

Once we receive the DHKey check PDU it's time to first verify that the
value is correct and then proceed with encrypting the link.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for handling LE SC user response
Johan Hedberg [Fri, 6 Jun 2014 08:44:05 +0000 (11:44 +0300)]
Bluetooth: Add support for handling LE SC user response

With LE SC, once the user has responded to the numeric comparison it's
time to send DHKey check values in both directions. The DHKey check
value is generated using new smp_f5 and smp_f6 cryptographic functions.
The smp_f5 function is responsible for generating the LTK and the MacKey
values whereas the smp_f6 function takes the MacKey as input and
generates the DHKey Check value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for LE SC numeric comparison
Johan Hedberg [Fri, 6 Jun 2014 08:39:49 +0000 (11:39 +0300)]
Bluetooth: Add support for LE SC numeric comparison

After the Pairing Confirm and Random PDUs have been exchanged in LE SC
it's time to generate a numeric comparison value using a new smp_g2
cryptographic function (which also builds on AES-CMAC). This patch adds
the smp_g2 implementation and updates the Pairing Random PDU handler to
proceed with the value genration and user confirmation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add LE SC support for responding to Pairing Confirm PDU
Johan Hedberg [Fri, 6 Jun 2014 08:36:38 +0000 (11:36 +0300)]
Bluetooth: Add LE SC support for responding to Pairing Confirm PDU

When LE SC is being used we should always respond to it by sending our
local random number. This patch adds a convenience function for it which
also contains a check for the pre-requisite public key exchange
completion

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add support for sending LE SC Confirm value
Johan Hedberg [Fri, 6 Jun 2014 08:30:08 +0000 (11:30 +0300)]
Bluetooth: Add support for sending LE SC Confirm value

Once the public key exchange is complete the next step is for the
non-initiating device to send a SMP Pairing Confirm PDU to the
initiating device. This requires the use of a new smp_f4 confirm value
generation function which in turn builds on the AES-CMAC cryptographic
function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add handler function for receiving LE SC public key
Johan Hedberg [Fri, 6 Jun 2014 08:09:28 +0000 (11:09 +0300)]
Bluetooth: Add handler function for receiving LE SC public key

This patch adds a handler function for the LE SC SMP Public Key PDU.
When we receive the key we proceed with generating the shared DHKey
value from the remote public key and local private key.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add basic support for sending our LE SC public key
Johan Hedberg [Fri, 6 Jun 2014 07:50:15 +0000 (10:50 +0300)]
Bluetooth: Add basic support for sending our LE SC public key

When the initial pairing request & response PDUs have been exchanged and
both have had the LE SC bit set the next step is to generate a ECDH
key pair and to send the public key to the remote side. This patch adds
basic support for generating the key pair and sending the public key
using the new Public Key SMP PDU. It is the initiating device that sends
the public key first and the non-initiating device responds by sending
its public key respectively (in a subsequent patch).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add ECC library for LE Secure Connections
Johan Hedberg [Tue, 29 Apr 2014 10:07:45 +0000 (13:07 +0300)]
Bluetooth: Add ECC library for LE Secure Connections

This patch adds a simple ECC library that will act as a fundamental
building block for LE Secure Connections. The library has a simple API
consisting of two functions: one for generating a public/private key
pair and another one for generating a Diffie-Hellman key from a local
private key and a remote public key.

The code has been taken from https://github.com/kmackay/easy-ecc and
modified to conform with the kernel coding style.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add basic support for AES-CMAC
Johan Hedberg [Fri, 2 May 2014 11:19:47 +0000 (14:19 +0300)]
Bluetooth: Add basic support for AES-CMAC

Most of the LE Secure Connections SMP crypto functions build on top of
the AES-CMAC function. This patch adds access to AES-CMAC in the kernel
crypto subsystem by allocating a crypto_hash handle for it in a similar
way that we have one for AES-CBC.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Set link key generation bit if necessary for LE SC
Johan Hedberg [Fri, 6 Jun 2014 07:39:56 +0000 (10:39 +0300)]
Bluetooth: Set link key generation bit if necessary for LE SC

Depending on whether Secure Connections is enabled or not we may need to add
the link key generation bit to the key distribution. This patch does the
necessary modifications to the build_pairing_cmd() function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Rename hci_find_ltk_by_addr to hci_find_ltk
Johan Hedberg [Thu, 29 May 2014 12:02:59 +0000 (15:02 +0300)]
Bluetooth: Rename hci_find_ltk_by_addr to hci_find_ltk

Now that hci_find_ltk_by_addr is the only LTK lookup function there's no
need to keep the long name anymore. This patch shortens the function
name to simply hci_find_ltk.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Remove unused hci_find_ltk function
Johan Hedberg [Thu, 29 May 2014 12:00:03 +0000 (15:00 +0300)]
Bluetooth: Remove unused hci_find_ltk function

Now that LTKs are always looked up based on bdaddr (with EDiv/Rand
checks done after a successful lookup) the hci_find_ltk function is not
needed anymore. This patch removes the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Update LTK lookup to correctly deal with SC LTKs
Johan Hedberg [Thu, 29 May 2014 11:00:39 +0000 (14:00 +0300)]
Bluetooth: Update LTK lookup to correctly deal with SC LTKs

LTKs derived from Secure Connections based pairing are symmetric, i.e.
they should match both master and slave role. This patch updates the LTK
lookup functions to ignore the desired role when dealing with SC LTKs.

Furthermore, with Secure Connections the EDiv and Rand values are not
used and should always be set to zero. This patch updates the LTK lookup
to first use the bdaddr as key and then do the necessary verifications
of EDiv and Rand based on whether the found LTK is for SC or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add mgmt_set_secure_conn support for any LE adapter
Johan Hedberg [Mon, 26 May 2014 08:23:35 +0000 (11:23 +0300)]
Bluetooth: Add mgmt_set_secure_conn support for any LE adapter

Since LE Secure Connections is a purely host-side feature we should
offer the Secure Connections mgmt setting for any adapter with LE
support. This patch updates the supported settings value and the
set_secure_conn command handler accordingly.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Use custom macro for testing BR/EDR SC enabled
Johan Hedberg [Mon, 26 May 2014 08:21:22 +0000 (11:21 +0300)]
Bluetooth: Use custom macro for testing BR/EDR SC enabled

Since the HCI_SC_ENABLED flag will also be used for controllers without
BR/EDR Secure Connections support whenever we need to check specifically
for SC for BR/EDR we also need to check that the controller actually
supports it. This patch adds a convenience macro for check all the
necessary conditions and converts the places in the code that need it to
use it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Set the correct security level for SC LTKs
Johan Hedberg [Fri, 23 May 2014 10:36:10 +0000 (13:36 +0300)]
Bluetooth: Set the correct security level for SC LTKs

When the looked-up LTK is one generated by Secure Connections pairing
the security level it gives is BT_SECURITY_FIPS. This patch updates the
LTK request event handler to correctly set this level.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add mgmt support for LE Secure Connections LTK types
Johan Hedberg [Fri, 23 May 2014 10:15:37 +0000 (13:15 +0300)]
Bluetooth: Add mgmt support for LE Secure Connections LTK types

We need a dedicated LTK type for LTK resulting from a Secure Connections
based SMP pairing. This patch adds a new define for it and ensures that
both the New LTK event as well as the Load LTKs command supports it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Update SMP security level to/from auth_req for SC
Johan Hedberg [Fri, 16 May 2014 07:59:06 +0000 (10:59 +0300)]
Bluetooth: Update SMP security level to/from auth_req for SC

This patch updates the functions which map the SMP authentication
request to a security level and vice-versa to take into account the
Secure Connections feature.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add SMP flag for SC and set it when necessary.
Johan Hedberg [Fri, 16 May 2014 08:03:34 +0000 (11:03 +0300)]
Bluetooth: Add SMP flag for SC and set it when necessary.

This patch adds a new SMP flag for tracking whether Secure Connections
is in use and sets the flag when both remote and local side have elected
to use Secure Connections.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Make auth_req mask dependent on SC enabled or not
Johan Hedberg [Mon, 26 May 2014 10:29:28 +0000 (13:29 +0300)]
Bluetooth: Make auth_req mask dependent on SC enabled or not

If we haven't enabled SC support on our side we should use the same mask
for the authentication requirement as we were using before SC support
was added, otherwise we should use the extended mask for SC.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Add basic SMP defines for LE Secure Connections
Johan Hedberg [Thu, 8 May 2014 11:02:22 +0000 (14:02 +0300)]
Bluetooth: Add basic SMP defines for LE Secure Connections

This patch adds basic SMP defines for commands, error codes and PDU
definitions for the LE Secure Connections feature.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
9 years agoBluetooth: Simplify Link Key Notification event handling logic
Johan Hedberg [Wed, 3 Dec 2014 09:03:06 +0000 (11:03 +0200)]
Bluetooth: Simplify Link Key Notification event handling logic

When we get a Link Key Notification HCI event we should already have a
hci_conn object. This should have been created either in the Connection
Request event handler, the hci_connect_acl() function or the
hci_cs_create_conn() function (if the request was not sent by the
kernel).

Since the only case that we'd end up not having a hci_conn in the Link
Key Notification event handler would be essentially broken hardware it's
safe to simply bail out from the function if this happens.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>