Bluetooth : Ignore incomming events when the hci device is down

In error conditions Adapter state machine via Bluez tries to reset
the hci device, during that in some rare scenario if some pending event
comes from riva, the command complete apis tries to access some already
freed memory in reset sequence.

CRs-fixed: 369658
Signed-off-by: Bhasker Neti <bneti@codeaurora.org>
(cherry picked from commit 6f4ceb1f8588aec11b4d9380cd328d0008c8d167)

Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
(cherry picked from commit d686446400fd0a5645ff2d1e1b9f0249748ce5f8)

Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
(cherry picked from commit 69c592dd2a4b3ea95fe82970737bbbd2da8588b7)

Change-Id: Ic4cb65d405a4928b5a45aaad9c1d8ad1f6e67907
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
Bluetooth : hidp: Get the valid hci_conn while unlink

Since the context where unlink will be called is unaware of
validity of hci_conn pointer, fetch the valid hci_conn
before unlink.

CRs-fixed: 370274
Signed-off-by: Mallikarjuna GB <gbmalli@codeaurora.org>
(cherry picked from commit f411769619b631aa0d9f7d460bcfec4ff3e6f54a)

Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
(cherry picked from commit fce25f117ec7ea4296f550f8ed819dc517f89172)

Signed-off-by: Sunil Joseph <sunilj@codeaurora.org>
(cherry picked from commit 025e910a412c9f5d2e8d247e69afdb3041706a3a)

Change-Id: I60c9024c1c27d18ee2852166eed03a4c8593ca88
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>
Bluetooth: hidp: use dest address from session info

While hid device unpair process, we are trying to access released
socket as apart of getting hci device which results a kernel panic.

CRs-fixed: 387164
Signed-off-by: Ram Mohan Korukonda <rkorukon@codeaurora.org>
(cherry picked from commit 27e77d2bda65c96815cb5f785df9ffd7bd733e6a)

Change-Id: Ic4359adf41c3da4effba25856169629787b5f7e0
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
Bluetooth: Disable sniff when the subrate values doesnt match.

Found there is possibility of sniff subrate collision with some
IOT devices. When this collision happned if the remote device
send subrate values that doesn't match with DUT supported
values exit sniff mode. This will allow DUT to reconfigure
sniff after idle time.

CRs-fixed: 380811
Signed-off-by: Srinivas Krovvidi <skrovvid@codeaurora.org>
(cherry picked from commit a7c3d7e6d905bab198003f16316971ae872eec9f)

Change-Id: Ibe3d02c6a404bbce677c7d980f0ad124e31bca26
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
Bluetooth: fix shutdown on SCO sockets

shutdown should wait for SCO link to be properly disconnected before
detroying the socket, otherwise an application using the socket may
assume link is properly disconnected before it really happens which
can be a problem when e.g synchronizing profile switch.

CRs-fixed: 365445
Signed-off-by: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Signed-off-by: Srinivas Krovvidi <skrovvid@codeaurora.org>
(cherry picked from commit 2e02b861173406a1287a53ca7b836a4ad5fd4255)

Change-Id: Icc38e940f8008d908077dbdea16bc5c6420d1371
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
Bluetooth: Block SCO disconnect operation on BT_CLOSED state.

Have maximum blocking time for shutdown operation as DISCONNECT_TIMEOUT.
During this period when SCO connection closes, the userspace will be
updated on the close operation. Existing approach of immidiate return
on shutdown call can cause synchronization issues on SCO state between
kernel and userspace. This happens when disconnect operation takes
more time at kernel space.

CRs-fixed: 365445
Signed-off-by: Srinivas Krovvidi <skrovvid@codeaurora.org>
(cherry picked from commit f799996e309cad545b3a7f84ef6f333a09c8b876)

Change-Id: Ifa74d2568d2ee157a605a405017d4cc0f05d41fc
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
bluetooth: Add support for LE conn param

Added support to let the userspace know about the updated
LE connection parameters. On receiving successful connection
complete and connection parameters update event from the BT
Controller, send a mgmt event to the userspace bluetoothd.

CRs-fixed: 380271
Change-Id: If8c3d785188e0d4f38c7431d01c016f399137408
Signed-off-by: Sunny Kapdi <sunnyk@codeaurora.org>
(cherry picked from commit a42b50244cdb71f93bf842a28b0fc1cecc622c55)

Conflicts:

	include/net/bluetooth/hci.h
	include/net/bluetooth/hci_core.h
	include/net/bluetooth/mgmt.h
	net/bluetooth/hci_event.c
Bluetooth: Prevents update of Low Energy connection parameters

The start encryption command fails when the LE update
connection parameters request is pending.
Hence, prevent the update of LE connection parameters during the
bonding process. The update of connection parameters is
not necessary during bonding process.

CRs-fixed: 380257
Change-Id: I41cb3998fecc2297d61ec97d66ac35a0bd41ca80
Signed-off-by: Subramanian Srinivasan <subrsrin@codeaurora.org>

Conflicts:

	net/bluetooth/smp.c
Bluetooth: Send Disconnection reason to Bluez

Send device disconnection reason to bluez on receiving the
diconnection complete event so that low energy profiles
such as proximity can decide to reconnect if the reason
is link loss.

CRs-fixed: 378240
Signed-off-by: Archana Ramachandran <archanar@codeaurora.org>
(cherry picked from commit da09d26a75ee1c7c1911dcfbe0128fd09f6631f4)

Change-Id: I5fb2041c34922dab95a483b3409553d3be5b5042
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
Bluetooth: Add sockopts for LE Connection Params

Various LE profiles require very specific LE parameters for
both establishing and maintaining LE connections to remote
peripherals. These LE only parameters are encapsulated into
a single sockopts structure, and may be passed from user space.

CRs-fixed: 335971 387146
Signed-off-by: Brian Gix <bgix@codeaurora.org>
(cherry picked from commit a94b6122f4f7a44dc1d6e6a5dfd2533cad7a3abf)

Change-Id: Iaa2e6a8b371a5463d335d5ea30fd96493a1688b6
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

Conflicts:

	include/net/bluetooth/bluetooth.h
	include/net/bluetooth/l2cap.h
	net/bluetooth/hci_conn.c
	net/bluetooth/l2cap_core.c
	net/bluetooth/l2cap_sock.c
	net/bluetooth/mgmt.c
Bluetooth: Fix for supervision timeout must be 6X connection interval

Added a new function to verify whether the LE Connection Update
parameters are valid instaed of verifying all the LE Connection
parameters since only update parameters are set in the Connection
Update Request.

CRs-Fixed: 387146
Signed-off-by: Archana Ramachandran <archanar@codeaurora.org>
(cherry picked from commit 95319af0612d58788279748f586cc57221c3443e)

Change-Id: I3b803235150fc2b4508977d766b0f309a74de0c0
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
bluetooth: LE conn whitelist implementation

Add support to create connection to LE devices using
whitelist. With this, the Controller can try to connect
to multiple devices at the same time. The following
interfaces are added.
1. Add/Remove device from whitelist
2. Clear all the devices from whitelist
3. Create Connection to devices from whitelist
4. Cancel create connection to whitelist devices

CRs-fixed: 388980
Signed-off-by: Sunny Kapdi <sunnyk@codeaurora.org>
(cherry picked from commit 93bef895b01b79f49af60ba1394c9c3f6e563212)

Change-Id: Ib2f7879287d3b9fb453f52ebe6e63e961e91d4e4
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>

Conflicts:

	net/bluetooth/mgmt.c