Bluetooth: Add ANT apis

ANT uses libbt vendor for SOC initialization as part of
enable. ANT_USERIAL_OPEN and CLOSE has been added

Change-Id: I5a6d2b1ab87f857bc90e7a93aea2af46582ee672
FTP: Register FTP SDP record.

FTP SDP Record registeration in Bluedroid Stack.

Change-Id: I7b3c3d85c5c6a7ac20a0a9361a646d2d494f8fec
CRs-Fixed: 504049
Bluetooth: Add get baudrate opcode

To optimize GKI dynamic memory allocation, it needs to control
the memory allocation based on baudrate. So, add opcode to get
baudrate from transport layer.

Change-Id: I135c3f920a86f372075aa90be447154e854126ac
CRs-Fixed: 690830
Conflicts:
hci/include/bt_vendor_lib.h
DUN: Add DUN SDP record to the Bluedroid stack.

Add DUN server SDP record in Bluedroid stack.

CRs-Fixed: 557180
Change-Id: I432496079ae0d7325805b1b1cf684629bbf51035
GAP: Delay setting Visibility mode.

This patch delays setting of Connectable mode until data profile
are registered from Bluetoothapk. without this patch stack was
enabling visibility as connectale even before sdp record of data
profile was added to sdp server resulting in incoming connection
failure if remote devices tried to connect to data profiles.

Change-Id: Ifd43034ebe167aa308449cb6817801f18a1540cb
CRs-Fixed: 538672, 681360
GAP: Clear pairing callback based on BD Address

This patch clears the pairing callback when pairing state is either
BT_BOND_STATE_NONE or BT_BOND_STATE_BONDED based on bd address of
device whose pairing state has changed. Without this patch it was
observed that if some other device was unpaired at same time when
outgoing pairing was initaited, pairing callback was being reset
unnecessarily resulting in UI stuck at pairing indefinately.

Change-Id: I5af80891c37e24f004c5318804350daea96ce2e2
CRs-Fixed: 581124
HID: Set sniff subrate with optimize latency value on HID link and add JW MT002 and BORND Mouse(s) to blacklist

- If HID is connected & SCO is active, then disabling Sniff subrate
  to fix connection timeout on HID link.

- If HID is connected & SCO is not active. Setting sniff subrate with
  optimize value based on the remote parameter to fix connection
  timeout on HID link to avoid HID IOT issue.

- Adds behaviour of host disabling SSR for JW MT002 and prevents
  Host from sending Sniff subrating command to SoC for BORND mouse
  so as to avoid IOT issues of disconnection and slow mouse movements
  respectively with these device.

Change-Id: I6d60df88ea33e00b0fb173447351da4874dc97e5
CRs-Fixed: 613984, 635632, 646480
GAP: Always try to retrieve remote name after ACL creation

This patch tries to retrieve remote name request after remote extended
feature  is retrieved, so that if remote device has changed its
friendly name, DUT updates the same in its database and doesn't always
use remote name from last paired information.

Change-Id: I8a66aa4f937fcbadbccc7112502a2017bdc9cda8
CRs-Fixed: 593828, 599638
Conflicts:
bta/include/bta_api.h
btif/src/btif_util.c
Bluetooth: Pan fixes Squashed commit of the following:

commit e91b27c13d16a26500c7138a7e54b054ca44a0cf
Author: Nitin Shivpure <nshivpur@codeaurora.org>
Date:   Thu Jan 2 13:39:36 2014 +0530

    Bluetooth: Fix to avoid A2DP choppiness while disconnecting PAN

    A case where A2DP is going on & PAN is connected. A2DP
    choppiness is observed while disconnecting PAN. Because A2DP
    media task is unable to write data on L2CAP. As BTU task is
    blocked while disconnecting PAN for destroying tap_read_thread,
    tap_read_thread should be destroyed in btif context to avoid
    the A2DP choppiness.

    Change-Id: I0d8c5110743eedf9bce8a41b71a364d0d076ca76
    CRs-Fixed: 593440

commit 2d10f50b168d789e78fbc5122728d41f7db4dc2b
Author: Nitin Shivpure <nshivpur@codeaurora.org>
Date:   Tue Aug 6 21:29:19 2013 +0530

    Bluetooth: Avoid to advertise PANU service records.

    This is special case where remote device(PC) acts as PANU
    & is trying to connect PANU on DUT instead of NAP. Because
    DUT had advertised PANU service records on SDP. As DUT does
    not support PANU-PANU connection, So connection is dropped
    every time. As per spec, It's not mandatory to advertise PANU
    service records, So PANU service record should not be advertised
    on SDP to solve this issue.

    Change-Id: I1f733467335b5e0ca00899cf4380860d233aab33
    CRs-Fixed: 520804
    (cherry picked from commit 0e0811014cc1dc222de0f18b93023b0ff182cc2c)
    (cherry picked from commit 1332c3c8cfbeaf0bae076383aa3be17daac9a1e5)
    (cherry picked from commit 54e0ef1180640b3333330579657737adb15bdb75)

commit 3d495031f5a927a33c7cf66023082ff2ab0f998a
Author: Nitin Shivpure <nshivpur@codeaurora.org>
Date:   Sat Sep 7 14:19:03 2013 +0530

    Bluetooth: Adding support for 5th PANU connection

    DUT(NAP role) can be connected up to maximum 4 remote devices
    (PANU role) as per the current implementation. Adding support
    for 5th PANU connection, So DUT(NAP role) can be connected up
    to maximum 5 Remote devices(PANU role).

    Change-Id: Ic687c56bded40e5e79099ef3c31d40e10b8531c8
    CRs-Fixed: 463828
    (cherry picked from commit 2ff000c8fb06168e9b440834b2a62c1a6d2f8b0f)
    (cherry picked from commit 6641fb84039a1ef3c438712908f5d8895265538d)
    (cherry picked from commit 99547011cdacdb2294cdcc7ff919dc55d8c089d0)

Change-Id: Ic77fde70447499fed55a1ca059e64c10c8189ece
Bluetooth: Changing vendor ID as QTI for Device ID Profile

As per Specification, Device providers should configure the
vendor ID as the Company Identifier provided by the Bluetooth
SIG. Hence Changing vendor ID as QTI for Device ID Profile.

Change-Id: I852113d2849ea4fd0725396fc92f320101aab0d0
CRs-Fixed: 547495
HID: Add support for Set Idle and Get Idle commands

This patch adds support for sending set idle and get idle commands to
remote HID device, on receiving the function call from upper layers.
Also on reception of get idle time from remote device, upper layers
are infrmed using registered callback.

Change-Id: I14bc2dc349354fd87ef8aba25357514398532e87
CRs-Fixed: 522511
HID: Add support for disconnecting HID based on priority

This patch adds support for disconnecting the incoming HID connected based
on priority of remote HID Device. If user does not want to connect HID
profile for a particular remote device, priority of remote device would be
set to 0. Based on priority of remote device, incoming connection would be
disconnected if priority is 0. Also ifno priority field is present, DEFAULT
priority would be set so that incoming connection can be accepted by DUT
from rmeote device.

Change-Id: I97002a46a16d386a6c178445ac825788d6bf40c9
CRs-Fixed: 532234, 537522, 699731
Bluetooth: Add Get/Set socket option to the Rfcomm socket.

Introduced Get/Set socket option support to the Rfcomm socket.
Currently Rfcomm socket supports get/set modem bits socket
options.For other sockets it will return error.

CRs-Fixed: 557180
Change-Id: Ia1779293b643c22d3f754c7f405646d42eb94963
Bluetooth: Add Obex over L2cap support to the Bluedroid stack

- Provides APIs to the BT-IF layer for connection and data
  management of L2CAP channel for the obex over L2CAP.

- Registers callbacks with core stack layer.

- Process the events from core stack layer,and passes them
  to the BT-IF layer.

Change-id: I17591408f28a852de584a2bd074e39fbb8273ebb
CRs-Fixed: 639499

Bluetooth: Add L2cap socket support in BT-IF layer for OOL

- Provides APIs to the Bluetooth JNI for connection and data
  management of L2CAP channel for the obex over L2CAP.

- Registers callbacks with BTA layer.

- Process the events from BTA layer, and passes them to the
  upper layers.

- SDP registration for OPP 1.2

Change-id: Ie67a87ff6b9c41da8fda2336752f58dd9109d6df
CRs-Fixed: 639499

Bluetooth: Add L2cap socket support in core stack layer for OOL

- Provides APIs to the BTA layer for connection and data management
  of L2CAP channel for the obex over L2CAP.

- Registers callbacks with core L2CAP.

- Process the events from core L2CAP,and passes the relevant events
  to the BTA layer.

Change-id: I1d6185428c9af3d12a94cebcc8234a5b1303680e
CRs-Fixed: 639499

Bluetooth: Set the config params for Obex over L2cap

- Introduce new buffer pool for the Obex over L2cap
  data.

- Set all configuration parameters for ERTM, FCR of
  L2CAP.

CRs-Fixed: 639499
Change-id: If07da8fcecd643ee843293173e020ff8c03afe2e

Bluetooth: Add dynamic memory support for OOL buffer pool

- Add dynamic memory allocation support for Obex over L2CAP
  buffer pool(Pool ID 10).As per this design, it will always
  allocate memory from the Heap and once the data sent by
  the L2CAP, it will deallocate the memory.

- By default this support is disabled, this can be enabled
  for low memory devices.

- Pool count of GKI_BUF10 set to 16.

- Tx window size set to 16.

CRs-Fixed: 660616
Change-id: Ifc71484e3cc9d0b8c4316ce931c53e755c08aefa

Bluetooth: Update PM as idle only when full data is written

- Update the pwer manager about the OOL connection as idle
  only when the data is completely written from the L2CAP
  layer to the HCI.

- Update the Power manager about the device address of server
  connection, so that sniff request be taken correctly.

CRs-Fixed: 652149,660615
Change-id: I6fad7b8729d647d464b346cca24dc9d64c9570c0

Bluetooth: Get proper GKI buff considering header length

- Get proper GKI buffer considering header length plus
  pay load length.

- This change is required for the boundary conditions,
  where payload length meets the buffer length, but
  buffer cann't accomadate the header.

Change-id: I759c5e8442818831d9880d07882530a0a08069d5
CRs-Fixed: 670116,670157

Change-Id: Ie3625bc8f224206f38247f6612707e2d6f71ddd4
Bluetooth: Handle error cases for L2CAP fuzz testing

Handle the following error cases for L2CAP fuzz testing.

- Invalid HCI packet length for L2CAP packet
- Invalid L2CAP payload length for both start and
  continuation packets
- Handled maximum incoming L2CAP packet size

CRs-Fixed: 586808
Change-id: I886e3057135ef1f12235ec09e57f4f9f04464d01

Bluetooth:L2CAP: Handled invalid MTU Size and invalid Hci lengths

 Added condition to check invalid MTU Size in L2cap Process Commands
 Handled invalid Hci lengths also from Codenomicon L2cap Test Suite.

Change-id: I8c503ab77d8fca3728a84c3457d8115e31ee3a13
CRs-Fixed: 623275

BLUETOOTH:SDP:Handled invalid hci length case during SDP

This geriit validates the hci length in start packet during sdp
service search and discards the invalid ACL packets

Change-id: I86f50c18b64cdfff5e38e00b821ea10c1b6ae3c7
CRs-Fixed: 637342

Bluetooth: Handled delayed info rsp from remote during SDP

DUT initiates connection with out waiting for information response
from remote device during SDP.

Change-id: Iee0251f8f81923b1291983b66b31c78e14d21af0
CRs-Fixed: 635697

Bluetooth: GAP: Changing the security to general bonding

Changing the security from non bonding to general bonding
in BTM_SEC_OUT_AUTHENTICATE condition.

Change-id: I65d2ec4466e2bd81df2cc7e2936e05159a8645ed
CRs-Fixed: 676532

Bluetooth: Store local and remote io caps before RNR

Stores the loc_io_caps nad rmt_io_caps when the remote
name request is called, and these will be retrieved
in the function bta_dm_pinname_cback.

CRs-fixed: 535245
Change-id: I4b2156d7101acabb1ded65bd21d49a9c4551f8db

Bluetooth: GAP: Update Security SM state properly on collision

Change the security SM's state to BTM_PAIR_STATE_WAIT_PIN_REQ
on transaction collision.

Change the desired role to master when accepting a connection.
Also avoid sending the disconnect incase of HCI_ERR_PEER_USER.

Change-id: I1d5dfee237d8b2813f234ba7ee69facd7e78112a
CRs-Fixed: 579612

Bluetooth: GAP: Rearrange the pair info for removal from config

Rearrange the PinLength, LinkKey, LinkKeyType in the reverse way
of while adding it to config file. Otherwise, last item is never
deleted, it eventually creates a memory leak until the process
exists.

Config file mechanism expects in a Last in first out pattern.

CRs-Fixed: 680478
Change-id: I0f89ca4c9864342c2d89237c22757406af1afba6

Bluetooth: GAP: Update bonded device Name immediately on NVRAM

Bonded device friendly name not updating incase of battery removal
or adb reboot happens before the actual write onto NVRAM.

Bonded device alias name will be updated onto NVRAM immediately.

Change-Id: I6bb465ce00a7633e694695b8abbfdf31a463bfcf
CRs-Fixed: 654633

Bluetooth:GAP:  Increased max no of SDP records that server can support

Max no of SDP records increased to 25 from 20 as Hid connect fails
with reason SDP_CreateRecord fail, exceed maximum records:20 in
in BTSanity_Bluedroid.

Change-id: I0613f004766815902ac0a12e5e93f77b9d67580c
CRs-Fixed: 660830

Bluetooth:GAP: Remove bonded device info on pairing rejected

Remove bonded device information from the BT-IF layer storage
when authentication failed with reason pairing not allowed from remote.

Change-id: Ic9e5e1ed70d304edd3dbca82a73833753fa0093c
CRs-Fixed: 667904

Bluetooth: GAP: Set DUT role as slave for incoming connection

Change-id: Ic10802a6ebab69cd0681e76b1809dcc544620708
Set DUT role as slave incase of remote initiated connection for
list of carkits and headsets which are blacklisted

CRs-fixed: 688979

Change-Id: Ie7965ff82c54e3621af441bcff80f74927a4321a
Bluetooth : Handling case: close comes before rxthread

Handles the situation where userial_open takes time in
BT_VND_OP_USERIAL_OPEN opening and meanwhile the close
request comes.This way it will lead to crash in second
open since call flow will be like open-->close-->userial
Rx thread created.

CRs-Fixed: 673965
Change-id: I1d3b4b04700a9d0e235702d96f60fc6780fff430

Bluetooth: Adding NULL check while traversing LIST

while traversing the node NULL check should be there
as it accesses and moves to the next in while loop.
If first node itself is NULL then it will crash.
Putting NULL check will skip the while loop and node
will be assigned to it as first node.

CRs-Fixed: 682149
Change-id: I7faa8daf338063fc89dbfdd8c12a0e32b7853ff1

Bluetooth: GAP: NULL pointer check in sdpu_build_attrib_entry

Pointer accessed with out NULL check in sdpu_build_attrib_entry

Change-id: I1dd352a33ff6f86add7d1b1bfdf240d1b7992b83
CRs-Fixed: 685739

Bluetooth: Notify BT APP about alias as the name if present

While scanning notify the Bluetooth APP about the alias name
as the actual device name of snanned device if alias name is
present.

CRs-Fixed: 539420
Change-id: Id8a093b1503eb3f308f466f30c1a4a6f4c250594

Bluetooth: Avoid null pointer exception for invalid channel

- Avoid null pointer exception for invalid l2cap channels
  while running the L2cap fuzz testing.

Change-id: I20e3c16433e16f0b8104ed00a4795aff272bedb9
CRs-Fixed: 673211

Bluetooth: Fix for NULL pointer check

Change-id: I3ba7d91d6b18c8fb29caee176b10f6a6097d8e47
This fix is to avoid NULL pointer dereference for 'p_remote_cmd'
in handle_rc_passthrough_cmd function.

CRs-Fixed: 657785

Change-Id: I0ea9a145fe62467dd52194100e71d1afe9ec818d
Conflicts:
gki/common/gki_time.c
hci/src/userial_mct.c
Bluetooth: Do not go for inquiry in BONDING State

This patch fix a special case where DUT is paired & connected
with only one device, which has capbility to intiate paring as
soon as DUT unpair same remote device. As DUT is paired with
only one device, In this case Once DUT unpair remote device. DUT
goes for inquiry & at same time remote device initiates pairing
if Bludroid stack recieve pairing request before the inquiry
start then DUT should not go for inquiry, As DUT is already in
BONDING state.

CRs-Fixed: 481263

Change-id: I0e1ec0fdb963921629e5c52f495ae2013e679a03

SDP: Fix for SDP query in certification test with Invalid PduSize

Bluedroid stack is only checking parameter length and input data length.
Added an extra logic to handle invalid data after getting last valid data.

Change-id: I47eafb2c24e73b472c31a2fb47e02d48c5e04f6c
CRs-Fixed: 491693

Bluetooth:GAP:Handled LMP Response time out event during SAP connection

Handled LMP Response timeout error case during SAP connection by removing
the remote device from the bonded device list of stack.

Change-id: Ia7e11fe36cd118e27319d8b5f9682b57ef3de8f7
CRs-Fixed: 637567

Bluetooth: GAP: Don't update short name if the device paired

Don't notify the BT APP about the shortened device name which
will be part of EIR response,incase of device is already
paired.

Incase if the alias name present for that device, it
will notify th BT APP alias name as the actual device name.

CRs-Fixed: 576911
Change-id: Ia64e1e90aae8c4e0cc52643ce3bbbb1332fe5b66

Bluetooth: GAP: Update Paging and inquiry busy level seperately

While updating the busy level of Paging or inquiry '10' was
used as BL for paging and inquiry,this leads to ignore the
one of them when both of them are active.

Made unique busy level for paging related events and inquiry
related events, so that each event will be notified.

CRs-Fixed: 580854,570163

Change-id: I7bddcb4901061c450555235717b7d49bab922ae8

Bluetooth: Avoid 2nd time cleanup on Hardware init failure

Avoid 2nd time cleaning up the GKI, BTIF layers on hardware
init failure. Introduced a flag protected with mutex to
avoid cleaning up the GKI, BT-IF layer.

CRs-Fixed: 580436
Change-id: I7afc122a4f36dda17427a1e462cf705bfba80f5b

Bluetooth: GAP: Update name as part of Discovery of services

Update the remote device name to upper layers as part of
discovery of remote device services.

CRs-Fixed: 593306
Change-id: I24d899c1f5ccc81d8b0c4257abae16a7bf5d4682

Bluetooth: GAP: Handle security failure with invalid handle

Change-Id: Ia95d10ae95cfa1750386233ee90f01899061294e
Return NULL incase of invalid handle when finding a device
based on the handle. This will make sure to avoid giving
a invalid entry from the device list.

Also send authentication failure in case of invalid handle.

CRs-Fixed: 592545

Change-Id: I47f911d787af82beb1f4dfe832ef6f8c4895c79a
Conflicts:
btif/src/btif_dm.c
Bluetooth:GAP: Avoid sending the ACL connected event again

Avoid sending the ACL connected event if already sent
for the same ACL connection, otherwise ACL count will be
incremented by one for the same ACL connection which is
not the expected behavior.

CRs-Fixed: 604797
Change-id: I04e272425c317f7e94b6b8919a5432d3da2c8205

Bluetooth: GAP: Increase the security slots for client profiles

Increased the security slots to 70 to accomadate the client
profiles also. With out this, multi client profiles use cases
will fail due to invalid security ID.

Change-id: Ie16440ee6ecf202999dd606ec83c2e90becc13df
CRs-Fixed: 592764

Bluetooth: Ignore the Page timeout err for Remote name Request

Change-Id: I89db95e68d3f533ba89c14c8c46bbf428970a57f
Ignore the Page Timeout error for Remote name request for the
pairing process.

As part pairing process, it will again ask for the remote name
if the first request fails after receiving the remote device
features.

CRs-Fixed: 644986

Change-Id: I9bea0c2ce8526721a84b3766dd49e4acf4ae6d59
Bluetooth: GAP: Add Secure connection support for BT Host

- Implement the secure connection support for Host

- Add support for write/read secure conn Host bit

- Handle the new link key types properly

CRs-Fixed: 661933
Change-Id: Icba6b8499e6e466388c034769152621b48d1ef1f
Bluetooth: Adding support to get remote DI record

Adding support to get remote DI record. The local
device can use the Device ID service record from
the remote device, In order to make best use of the
features on the device identified.

CRs-Fixed: 692532
Change-Id: Ia9b1cd44966425d5332c03167e0eea228e9da07c