Commit Graph

24134 Commits

Author SHA1 Message Date
Andy Duan
76255f732d hciattach: fix the delay timer for bcm43xx firmware download
From the log in .bcm43xx_load_firmware():
        /* Wait 50ms to let the firmware placed in download mode */
        nanosleep(&tm_mode, NULL);

But timespec tm_mode is real is 50us. Correct the delayed timer count.
2017-07-20 20:21:57 +02:00
Luiz Augusto von Dentz
3349c9cb5d gatt: Don't return to AcquireNotify until it has completed
Wait until bt_gatt_client_register_notify to reply since the client may
need to synchronize the IO.
2017-07-18 13:50:42 +03:00
Luiz Augusto von Dentz
e4dae82fb7 core/advertisement: Add specifc error if max instance is reached
Returning generic error may confuse the application using
RegisterAdvertisement:

https://bugs.chromium.org/p/chromium/issues/detail?id=741056#c4
2017-07-17 15:34:47 +03:00
Marcel Holtmann
46f47fc8a1 Release 5.46 2017-07-14 11:06:54 +02:00
Marcel Holtmann
b8887cf03a autopair: Use unsigned int for passcode string 2017-07-13 20:50:59 -07:00
Szymon Janc
3a140aa35b sap: Remove support for STE U8500 platform
This code didn't received updates for few years. It is not installed
(build only) since BlueZ 5 release. And STE U8500 platform is long
dead.
2017-07-13 10:43:40 +02:00
Luiz Augusto von Dentz
1c358b9274 client: Fix error when AcquireNotify fails
It should print "Failed to AcquireNotify".
2017-07-12 11:09:18 +03:00
Luiz Augusto von Dentz
7b027896d4 audio: Add missing fall through declaration 2017-07-12 10:38:51 +03:00
Marcel Holtmann
0446d4a9c3 sap: Add missing fall through declaration 2017-07-11 11:32:26 -07:00
Marcel Holtmann
9a35bd6d42 audio: Add missing break statements 2017-07-11 11:32:14 -07:00
Marcel Holtmann
b8653aa78e audio: Add missing fall through declaration 2017-07-11 11:31:57 -07:00
Marcel Holtmann
f55b3a7ee9 network: Add missing fall through declaration 2017-07-11 11:31:37 -07:00
Marcel Holtmann
f9923bd2b4 shared: Add missing fall through declaration 2017-07-11 11:31:12 -07:00
Marcel Holtmann
1862586e8c obexd: Add missing fall through declaration 2017-07-11 11:30:55 -07:00
Marcel Holtmann
ca7544fd53 unit: Add missing break statement 2017-07-11 11:30:28 -07:00
Marcel Holtmann
e2ae29f483 tools: Add missing break statements 2017-07-11 11:30:05 -07:00
Marcel Holtmann
6a1cfef9e5 tools: Fix uninitialized memory array 2017-07-11 11:29:33 -07:00
Marcel Holtmann
376c3433c0 tools: Fix wrong string buffer sizes 2017-07-11 11:29:11 -07:00
Marcel Holtmann
cf17fba722 tools: Add missing fall through declaration 2017-07-11 11:28:48 -07:00
Marcel Holtmann
608dffe9ca autopair: Fix PIN string buffer size 2017-07-11 11:27:47 -07:00
Marcel Holtmann
1d2cbb8acb android: Add missing fall through declaration 2017-07-11 11:27:15 -07:00
Marcel Holtmann
9c249a035d client: Add missing fall through declaration 2017-07-11 11:26:42 -07:00
Luiz Augusto von Dentz
35803206af device: Fix crash freeing device
Calling gatt_db_register with NULL pointers makes no sense since it does
nothing when the callbacks are NULL so the callback are still reachable
causing invalid memory to accessed:

Invalid read of size 8
   at 0x50EAFDC: g_slist_find_custom (in /usr/lib64/libglib-2.0.so.0.5000.3)
   by 0x46CDA1: gatt_service_removed (device.c:3563)
   by 0x4896F8: queue_foreach (queue.c:220)
   by 0x4951FB: notify_service_changed (gatt-db.c:268)
   by 0x4951FB: gatt_db_service_destroy (gatt-db.c:279)
   by 0x4898F5: queue_remove_all (queue.c:336)
   by 0x4952E2: gatt_db_clear_range (gatt-db.c:461)
   by 0x48F32B: discovery_op_unref (gatt-client.c:447)
   by 0x4979AA: bt_gatt_request_unref (gatt-helpers.c:594)
   by 0x490489: bt_gatt_client_cancel_all (gatt-client.c:2083)
   by 0x4904D8: bt_gatt_client_free (gatt-client.c:1752)
   by 0x46CF70: gatt_client_cleanup (device.c:561)
   by 0x46D01A: attio_cleanup (device.c:586)
 Address 0x86cb940 is 0 bytes inside a block of size 16 free'd
   at 0x4C2ED4A: free (vg_replace_malloc.c:530)
   by 0x50D16CD: g_free (in /usr/lib64/libglib-2.0.so.0.5000.3)
   by 0x50EA743: g_slice_free_chain_with_offset (in /usr/lib64/libglib-2.0.so.0.5000.3)
   by 0x46D18C: device_free (device.c:638)
   by 0x485B05: remove_interface (object.c:667)
   by 0x485FF9: g_dbus_unregister_interface (object.c:1391)
   by 0x45EFA9: btd_adapter_remove_device (adapter.c:1200)
   by 0x45FBC3: dev_disconnected (adapter.c:6800)
   by 0x48A1A5: request_complete (mgmt.c:261)
   by 0x48AC0B: can_read_data (mgmt.c:353)
   by 0x496954: watch_callback (io-glib.c:170)
   by 0x50CBE51: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.5000.3)
2017-07-07 13:03:14 +03:00
Luiz Augusto von Dentz
006213cf4d device: Fix crashing when connecting ATT over BR/EDR
When remote connects ATT over BR/EDR the code will attempt to resolve
its attributes, but in the meantime a SDP session may be active to
resolve the services exposed over SDP which can cause a crash since ATT
may end up freeing the request causing the following trace:

bluetoothd[31069]: attrib/gattrib.c:g_attrib_unref() 0x73aae0: g_attrib_unref=0
bluetoothd[31069]: src/device.c:connect_profiles()
/org/bluez/hci0/dev_F4_5F_69_01_3D_69 (all), client :1.868
bluetoothd[31069]: src/device.c:connect_profiles() Resolving services for
/org/bluez/hci0/dev_F4_5F_69_01_3D_69
bluetoothd[31069]: src/adapter.c:connected_callback() hci0 device
F4:5F:69:01:3D:69 connected eir_len 13
bluetoothd[31069]: src/gatt-database.c:connect_cb() New incoming BR/EDR ATT
connection
bluetoothd[31069]: attrib/gattrib.c:g_attrib_ref() 0x73d280: g_attrib_ref=1
bluetoothd[31069]: src/device.c:load_gatt_db() Restoring F4:5F:69:01:3D:69 gatt
database from file
bluetoothd[31069]: No cache for F4:5F:69:01:3D:69
bluetoothd[31069]: src/gatt-client.c:btd_gatt_client_connected() Device
connected.
bluetoothd[31069]: src/device.c:gatt_debug() Primary service discovery failed.
ATT ECODE: 0x0a
bluetoothd[31069]: src/device.c:gatt_client_ready_cb() status: success, error:
0
bluetoothd[31069]: src/gatt-client.c:btd_gatt_client_ready() GATT client ready
bluetoothd[31069]: src/gatt-client.c:create_services() Exporting objects for
GATT services: F4:5F:69:01:3D:69
bluetoothd[31069]: src/device.c:device_svc_resolved()
/org/bluez/hci0/dev_F4_5F_69_01_3D_69 err 0
bluetoothd[31069]: src/device.c:connect_profiles()
/org/bluez/hci0/dev_F4_5F_69_01_3D_69 (all), client :1.868

Program received signal SIGSEGV, Segmentation fault.
0x000000000048eb8d in browse_cb ()
2017-07-07 11:12:08 +03:00
Syam Sidhardhan
563ac6f020 shared/gatt-server: Remove unwanted pointer validation
Here the memory address pointed by the variable op is always valid.
2017-07-07 10:46:09 +03:00
Luiz Augusto von Dentz
2412559979 device: Ensure browse request is reset to NULL when freed
This makes the code simpler as browse_request_free always reset the
device pointer to NULL when freeing its data.
2017-07-07 10:15:10 +03:00
ERAMOTO Masaya
e0eeef1030 client: Fix memory leak due to the option to register an agent
When bluetoothctl runs with the command line option "-a <capability>", it
does not free the variable auto_register_agent registering the initial
agent and allocates new memory for it.

This frees the allocated memory before allocating new memory.
(The related commit id is 6db3470c2ea161b4b808ad1fc80dfd7e014fd359.)
2017-07-07 10:01:42 +03:00
Anurag Biradar
ded317e9c2 src/device: Fix bluetoothd crash
DUT was trying to connect with carkit and due to some reason connection
got aborted. SDP search got error and browse request was freed but
device->browse is still pointing to freed memory. During clean up
bluez removes all device and while removing it find reference to
browse_req and it tries to free again which leads to the crash.

Assign NULL to device browse_req before freeing the browse_req.

Log:

bluetooth: src/service.c:change_state() 0xb700a650: device XX:XX:XX:XX:XX:XX
           profile a2dp-sink state changed: connecting -> disconnected (-11)
bluetooth: src/device.c:device_profile_connected()
			a2dp-sink Resource temporarily unavailable (11)
bluetooth: src/device.c:device_profile_connected() returning response to :1.300
bluetooth: src/device.c:device_browse_sdp()
bluetooth: src/device.c:browse_request_free()

--Browse req is freed but device->browse is still pointing to freed memory --

While turning OFF freeing each devices:
bluetoothd[2024]: src/adapter.c:adapter_remove()
		Removing adapter /org/bluez/hci0
bluetoothd[2024]: src/device.c:device_remove()
		Removing device /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX
bluetoothd[2024]: src/device.c:browse_request_cancel()

(gdb)
0  0xb6f981ae in queue_remove_if (queue=0xb7007d70,
     function=0xb6f9a319 <match_disconn_id>, user_data=0xb7001ae0)
     at src/shared/queue.c:289
1  0xb6f9a87a in bt_att_unregister_disconnect (att=<optimized out>,
     id=<optimized out>) at src/shared/att.c:1161
2  0xb6f81bf6 in attio_cleanup (device=0xb6d4d810) at src/device.c:742
3  0xb6f81c3c in browse_request_cancel (req=0xb6fe3038) at src/device.c:777
4  0xb6f87066 in device_remove (device=0xb700ac00, remove_stored=0)
     at src/device.c:5238
5  0xb6f6b80c in adapter_remove (adapter=adapter@entry=0xb6fff2f0)
     at src/adapter.c:7822
6  0xb6f79068 in adapter_cleanup () at src/adapter.c:11707
2017-07-07 10:01:42 +03:00
Syam Sidhardhan
fd3868ebc7 obexd: Fix memory leak in phonebook-dummy
g_build_filename() returns a newly-allocated string
that must be freed with g_free().
2017-07-07 10:01:42 +03:00
Luiz Augusto von Dentz
c89618370d client: Add release-notify command
This adds release-notify command which closes an existing fd unlocking
the attribute:

[Test peripheral:/service001f/char0020]# release-notify
[CHG] Attribute /org/bluez/hci1/dev_69_16_5B_9A_06_CD/service001f/char0020 NotifyAcquired: no
2017-07-05 14:27:40 +03:00
Luiz Augusto von Dentz
706f9cb68f client: Add acquire-notify command
This adds acquire-notify command which uses D-Bus AcquireNotify method
to acquire a file descriptor to read notifications locking the attribute:

[Test peripheral:/service001f/char0020]# acquire-notify
[CHG] Attribute /org/bluez/hci1/dev_56_A0_AA_D0_12_FF/service001f/char0020 NotifyAcquired: yes
AcquireNotify success: fd 7 MTU 65

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x0022
          Data: 0200

[CHG] /org/bluez/hci1/dev_56_A0_AA_D0_12_FF/service001f/char0020 Notification:
  00

> ACL Data RX: Handle 3585 flags 0x02 dlen 8
      ATT: Handle Value Indication (0x1d) len 3
        Handle: 0x0021
          Data: 00
2017-07-05 14:27:38 +03:00
Luiz Augusto von Dentz
23ca5047e8 gatt: Add implementation of NotifyAcquired
This property indicate if any client has acquire notify thus locking the
access to StartNotify.
2017-07-05 14:27:37 +03:00
Luiz Augusto von Dentz
1dba18681a gatt: Add implementation of AcquireNotify
This implements AcquireNotify creating a pipe and passing the read fd
to the application requesting it, at same time subscribe for
notifications:

bluetoothd[7279]: src/gatt-client.c:notify_client_ref() owner :1.461
bluetoothd[7279]: src/gatt-client.c:characteristic_create_pipe() AcquireNotify: sender :1.461 io 0x8a60540
2017-07-05 14:27:36 +03:00
Luiz Augusto von Dentz
25360fe34f client: Add release-write command
This adds release-write command which closes an existing fd unlocking
the attribute:

[Test peripheral:/service001f/char0020]# release-write
[CHG] Attribute /org/bluez/hci1/dev_00_1B_DC_07_31_88/service001f/char0020 WriteAcquired: no
2017-07-05 14:26:01 +03:00
Luiz Augusto von Dentz
b41cf317ac client: Add acquire-write command
This adds acquire-write command which uses D-Bus AcquireWrite methods
to acquire a file descriptor to write to locking the attribute:

[Test peripheral:/service001f/char0020]# acquire-write
[CHG] Attribute /org/bluez/hci1/dev_00_1B_DC_07_31_88/service001f/char0020 WriteAcquired: yes
AcquireWrite success: fd 7 MTU 65
[Test peripheral:/service001f/char0020]# write 00
Attempting to write fd 7

< ACL Data TX: Handle 3585 flags 0x00 dlen 8
      ATT: Write Command (0x52) len 3
        Handle: 0x0021
          Data: 00
2017-07-05 14:26:01 +03:00
Luiz Augusto von Dentz
9aedde4049 gatt: Add implementation of WriteAcquired
This property indicate if any client has acquire write thus locking the
access to WriteValue.
2017-07-05 14:26:00 +03:00
Luiz Augusto von Dentz
c6d9a1bbbe gatt: Add implementation of AcquireWrite
This implements AcquireWrite creating a pipe and passing the write fd
to the application requesting it:

bluetoothd[29915]: src/gatt-client.c:characteristic_create_pipe() AcquireWrite: sender :1.378 io 0x89cdfe0

The fd is monitored and in case the client decides close it, or exit/crash,
the daemon detects the HUP and cleanup properly:

bluetoothd[29915]: src/gatt-client.c:characteristic_pipe_hup() /org/bluez/hci1/dev_00_1B_DC_07_31_88/service001f/char0020: io 0x89cdfe0
2017-07-05 14:25:49 +03:00
Luiz Augusto von Dentz
0f3f40bab5 shared/gatt-client: Allow multiple ready callbacks
This makes the ready callbacks much more convenient to track when the
client is ready since its is now possible to notify more than on client
at the same time.
2017-07-04 12:30:05 +03:00
Luiz Augusto von Dentz
f59f3dedb2 doc/gatt-api: Add AcquireWrite and AcquireNotify
This enables write and notify exclusive access via file descriptors in
case the characteristic is actually trying to emulate a byte stream
transfer or have a protocol on top of GATT.
2017-07-04 12:29:57 +03:00
Luiz Augusto von Dentz
44bf4d2dba client: Add unregister-descriptor command
This adds unregister-descriptor which can be used to unregister
descriptors registered with register-descriptor:

unregister-descriptor /org/bluez/app/service0xf48150/chrc0xf49a40/desc0xf4d350
[DEL] Descriptor
	/org/bluez/app/service0xf48150/chrc0xf49a40/desc0xf4d350
	8260c653-1a54-426b-9e36-e84c238bc669
	Vendor specific
2017-06-30 12:33:24 +03:00
Luiz Augusto von Dentz
7e41dd2d75 client: Add register-descriptor command
This adds register-descriptor which can be used to register
descriptors to a characteristic registered with register-characteristic:

register-descriptor 8260c653-1a54-426b-9e36-e84c238bc669 read,write
[NEW] Descriptor
	/org/bluez/app/service0x902610/chrc0x91d690/desc0x9095a0
	8260c653-1a54-426b-9e36-e84c238bc669
	Vendor specific
[/org/bluez/app/service0x902610/chrc0x91d690/desc0x9095a0] Enter value: 00
2017-06-30 12:33:23 +03:00
Luiz Augusto von Dentz
5dbe747450 client: Add unregister-characteristic command
This adds unregister-characteristic which can be used to unregister
characteristics registered with register-characteristic:

unregister-characteristic /org/bluez/app/service0xc80150/chrc0xc99960
[DEL] Characteristic
	/org/bluez/app/service0xc80150/chrc0xc99960
	00002a06-0000-1000-8000-00805f9b34fb
	Alert Level
2017-06-30 12:33:22 +03:00
Luiz Augusto von Dentz
68fa26fb80 client: Add register-characteristic command
This adds register-characteristic which can be used to register
characteristic to a service registered with register-service:

register-characteristic 00002a06-0000-1000-8000-00805f9b34fb write-without-response
[NEW] Characteristic
	/org/bluez/app/service0x1122150/chrc0x113fa40
	00002a06-0000-1000-8000-00805f9b34fb
	Alert Level
2017-06-30 12:33:22 +03:00
Luiz Augusto von Dentz
bd35ab6bd4 client: Add unregister-service command
This adds unregister-service which can be used to unregister an
application service registered with register-service:

register-service 00001820-0000-1000-8000-00805f9b34fb
[NEW] Primary Service
	/org/bluez/app/service0x92a150
	00001820-0000-1000-8000-00805f9b34fb
	Internet Protocol Support
[bluetooth]# unregister-service /org/bluez/app/service0x92a150
[DEL] Primary Service
	/org/bluez/app/service0x92a150
	00001820-0000-1000-8000-00805f9b34fb
	Internet Protocol Support
2017-06-30 12:22:43 +03:00
Luiz Augusto von Dentz
0f47058a6e client: Add register-service command
This adds register-service command which can be used to add GATT services
to the application:

[bluetooth]# register-service 00001820-0000-1000-8000-00805f9b34fb
[NEW] Primary Service
	/org/bluez/app/service0x8c2610
	00001820-0000-1000-8000-00805f9b34fb
	Internet Protocol Support
[/org/bluez/app/service0x8c2610] Primary (yes/no): yes
[bluetooth]# register-application
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 0000112d-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 00001820-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 00:1B:DC:07:31:88 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb

Note: register-application still has to be called at the end to register
with bluetoothd as everything is done with ObjectManager.
2017-06-30 12:16:29 +03:00
Luiz Augusto von Dentz
21ec1b5105 client: Add generic way to request input from user
This adds rl_prompt_input which can be used by different parts to ask
user input.
2017-06-30 12:12:43 +03:00
Luiz Augusto von Dentz
8dc3d02184 client: Allow register-application without any UUID
This means that GattProfile1 should not be registered but there could still
be services that needs registered with bluetoothd.
2017-06-26 12:42:18 +03:00
Marcel Holtmann
7e19bfdbb6 monitor: Add missing UUID and EIR definitions 2017-06-22 23:48:28 +02:00
Matias Karhumaa
3467bb836d obexd: Fix null pointer dereference.
By sending OPP Put request before CONNECT we were able to cause
SIGSEGV in obexd. Crash was caused by null pointer dereference.
Crash was found using Synopsys Defensics Obex Server test suite.

This was fixed by calling os->service->connect if CONNECT was not
done before.
2017-06-22 14:21:17 +03:00
ERAMOTO Masaya
de4786090f client: Output a long message by two lines
This outputs the help message by two lines as follows if the string of
a command and a argument is long.

  set-alias <alias>          Set device alias
  select-attribute <attribute/UUID>
                             Select attribute
  attribute-info [attribute/UUID]
                             Select attribute
  read                       Read attribute value
2017-06-19 14:47:04 +03:00