core: Use proper header for S_IRUSR/S_IWUSR

According to open() manual one should include <sys/stat.h>.
This fix build with bionic library:

target thumb C: libbluetoothd <= external/bluetooth/bluez/src/attrib-server.c
external/bluetooth/bluez/src/attrib-server.c: In function 'write_value':
external/bluetooth/bluez/src/attrib-server.c:922:26: error: 'S_IRUSR'
	 undeclared (first use in this function)
external/bluetooth/bluez/src/attrib-server.c:922:26: note: each undeclared
	identifier is reported only once for each function it appears in
external/bluetooth/bluez/src/attrib-server.c:922:36: error: 'S_IWUSR'
	undeclared (first use in this function)
core: Remove unnecessary btd_device reference count in browse_req

The browse request is "owned" by the btd_device structure so it doesn't
make sense to have browse_req keeping an extra reference for the
btd_device.
core: Add debug log for attrib disconnection reason
input: Fix minor coding style issue in HoG code
input: Add debug logs for attio connection status in HoG code
doc/media-api: Update documentation of MediaPlayer1

This adds documentation of properties Type and Subtype
core: Fix default authorize value for external profiles

Previously the value of "authorize" was essentially ignored in the
settings table. This wasn't very noticeable since almost all profiles
use the default true value. Since the default value of "authorize" is
true it cannot be left out from the default settings table entries
(leaving it out would set it implicitly to false).
doc/media-api: Update documentation of MediaFolder1

This adds missing access types to properties NumberOfItems and Name
audio/player: Add Player property to MediaItem1

This proper refer to the player object path which the item belongs to
doc/media-api: Update documentation of MediaItem1

This adds documentation of property Player
tools/bluetooth-player: Make show-item command print Player property

This makes show-item command to print Player property that indicates
which player the item belongs to.
lib: Remove duplicated HSP_HS_UUID definition

There is an identical definition on the same header file (next to
HSP_AG_UUID).
gatttool: Remove unused code

Since commit 6a3a89774c6738df4d5b77636c4ce747b7497ae9 the code
removed here has no sense.
attrib: Avoid passing raw PDU to Exchange MTU callback

By centralizing the PDU parsing and validation internally to GATT API,
the callbacks become simpler.
attrib: Rename gatt_find_info() to gatt_discover_char_desc()

The old name referred to the underlying ATT PDU (Find Information
Request and Find Information Response) and not to the actual GATT
procedure (Discover All Characteristic Descriptors).
attrib: Modify gatt_cb_t signature

The boolean return value will have the same semantics as GLib watches:
returning "true" will keep the GATT procedure going; returning "false"
will interrupt it (either due to an error or because the desired
information was found.)

This "early interruption" of GATT procedures is allowed by the spec and
avoids unnecessary data transfers, specially on large attribute
databases and when using small MTU values.

Other changes are to use standard C types instead of GLib ones (which
are unnecessary here) and move the "status" parameter to the first
position, so it is consistent with other callbacks.
core: Refactor memory allocation for GATT service discovery

Prior to implementing partial primary service discovery, it is necessary
to move allocation of struct included_search, so the list of found
services (search->services) can be created incrementally.

Note that this list is also used later to collect (secondary) included
services and only then the full list of found services is used for
registering new services and detecting added/removed profiles.
core: Do not pass around memory allocated internally by GATT API

Instead, do a "deep copy" of the list of GATT services. While this
generates extra heap allocations, it also allows proper cleanup in case
of ATT or link errors. In other words, memory allocated by GATT API will
be freed by GATT API after callback returns.
attrib: Run callback with the partial result of service discovery

Callbacks should check for status equal to ATT_ECODE_ATTR_NOT_FOUND to
ensure that the service discovery has finished.
core: Only do Find Included Services after receiving all GATT services

Now that the primary service discovery callback is called on partial
discovery (instead of waiting for the entire discovery procedure to
finish), the included services discovery should wait until the full list
of services is found.

This is necessary because the logic for detecting added/removed services
depends on the full list of discovered services.