Commit Graph

268 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
b22859e3cc client/print: Add decoding for UUID properties
This adds proper decoding for UUID properties with usage of
bt_uuidstr_to_str so it can print the 'friendly' name as bellow:

bluetoothctl# transport.show /org/bluez/hci0/dev_94_DB_56_F7_F2_88/sep4/fd0
Transport /org/bluez/hci0/dev_94_DB_56_F7_F2_88/sep4/fd0
	UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
...
2024-09-18 15:26:18 -04:00
Bastien Nocera
ae6dab1076 client: Respect --timeout when bluetoothd isn't running
Exit after <timeout> seconds if bluetoothd isn't available. This
functionality is useful for non-interactive uses of bluetoothctl.
2024-09-17 10:17:42 -04:00
Luiz Augusto von Dentz
41f943630d client: Print a warning when setting discoverable without a timeout
This makes command discoverable to print a warning if
discoverable-timeout is not set(0):

[bluetooth]# discoverable-timeout 0
[bluetooth]# Changing discoverable-timeout 0 succeeded
[bluetooth]# [CHG] Controller 4C:49:6C:44:F5:E7 DiscoverableTimeout: 0x00000000 (0)
[bluetooth]# discoverable on
Warning: setting discoverable while discoverable-timeout not set(0) is not recommended
2024-09-12 16:43:18 -04:00
Iulia Tanasescu
a3f9970f7a client: Add assistant submenu
This adds the initial implementation for the assistant menu in
bluetoothctl, to detect and print MediaAssistant objects.

The current BAP Broadcast Assistant implementation can be tested
by running bluetoothctl, connecting to a BASS Server, scanning
a Broadcast Source that is streaming a number of BISes with
audio capabilities matching the capabilities of the peer device,
and noticing the MediaAssistant objects being created:

client/bluetoothctl
[bluetooth]# [CHG] Controller 00:60:37:31:7E:3F Pairable: yes
[bluetooth]# AdvertisementMonitor path registered
[bluetooth]# scan on
[bluetooth]# [NEW] Device 00:60:37:94:A6:A3 00-60-37-94-A6-A3
[bluetooth]# connect 00:60:37:94:A6:A3
Attempting to connect to 00:60:37:94:A6:A3
[CHG] Device 00:60:37:94:A6:A3 Connected: yes
[00-60-37-94-A6-A3]# Connection successful
[00-60-37-94-A6-A3]# [NEW] Device 15:65:78:B6:52:F6 15-65-78-B6-52-F6
[00-60-37-94-A6-A3]# [NEW] Assistant
       /org/bluez/hci0/src_15_65_78_B6_52_F6/dev_00_60_37_94_A6_A3/bis1
[00-60-37-94-A6-A3]# [NEW] Assistant
       /org/bluez/hci0/src_15_65_78_B6_52_F6/dev_00_60_37_94_A6_A3/bis2
[00-60-37-94-A6-A3]# scan off
[00-60-37-94-A6-A3]# Diovery stopped
[00-60-37-94-A6-A3]# disconnect
Attempting to disconnect from 00:60:37:94:A6:A3
[00-60-37-94-A6-A3]# Successful disconnected
[CHG] Device 00:60:37:94:A6:A3 Connected: no
[bluetooth]# [DEL] Assistant
       /org/bluez/hci0/src_15_65_78_B6_52_F6/dev_00_60_37_94_A6_A3/bis1
[bluetooth]# [DEL] Assistant
       /org/bluez/hci0/src_15_65_78_B6_52_F6/dev_00_60_37_94_A6_A3/bis2
2024-07-18 14:22:44 -04:00
Bastien Nocera
ab325450b0 client/main: Fix mismatched free
Error: ALLOC_FREE_MISMATCH (CWE-762): [#def37]
client/main.c:2108:2: alloc: Allocation of memory which must be freed using "g_free".
client/main.c:2108:2: assign: Assigning: "desc" = "g_strdup_printf("\x1b[0;94m[%s]\x1b[0m# ", attr)".
client/main.c:2111:2: free: Calling "free" frees "desc" using "free" but it should have been freed using "g_free".
2109|
2110|		bt_shell_set_prompt(desc);
2111|->		free(desc);
2112|   }
2113|
2024-05-10 11:27:36 -04:00
Bastien Nocera
f3f762b77b client/main: Fix array access
Error: CPPCHECK_WARNING (CWE-788): [#def36]
client/main.c:833: error[ctuArrayIndex]: Array index out of bounds; 'argv' buffer size is 0 and it is accessed at offset 1.
831|	const char **opt;
832|
833|->	if (!strcmp(argv[1], "help")) {
834|		for (opt = arg_table; opt && *opt; opt++)
835|			bt_shell_printf("%s\n", *opt);
2024-05-10 11:27:29 -04:00
Naga Bhavani Akella
78af547e94 clinet: Fix unregister-includes command
unregister-includes command takes two parameters service uuid and
included service uuid, since the space between them is missing,
the menu option is not working.
When two uuids separated with space is given, it is throwing error.
2024-05-06 12:21:01 -04:00
Jonas Dreßler
7ef40617a0 client: Invalidate scan filter on "scan" command
The "scan bredr" and "scan le" commands are broken right now because the
transport filter gets set, but not actually invalidated.

Invalidate the filter with `filter.set = false` so that it actually gets
updated when set_discovery_filter() is called afterwards.
2023-11-13 14:01:16 -05:00
Luiz Augusto von Dentz
f253711c0e client: Print Manufacturer and Version on show command
This enables show to print the Manufaturer and Version information if
available:

bluetoothctl> show
...
	Manufacturer: 0x0002 (2)
	Version: 0x0b (11)
2023-10-04 12:40:04 -07:00
Luiz Augusto von Dentz
35c706f398 client: Add agent auto argument support
This adds "auto" capability which behaves like "on" but instead of
asking user to confirm/autorize it automatically accepts, which is
not secure to be used thus a warning is printed when user selects it.

Usage:

  [bluetoothctl]# agent auto
  Warning: setting auto response is not secure, it bypass user
  confirmation/authorization, it shall only be used for test automation.

  or

  client/bluetoothctl -a auto
2023-08-23 13:49:00 -07:00
Luiz Augusto von Dentz
2b063f47ab client: Add support for mgmt submenu
This moves the functionality of btmgmt into client/mgmt.c so its
commands become available on bluetoothctl via mgmt submenu.
2023-07-14 15:14:02 -07:00
Luiz Augusto von Dentz
070c78c426 client/advertising: Add support for advertise.rsi command
This adds support for advertise.rsi command which can be used to request
the generation of RSI and include it as part of advertising data:

[bluetooth]# advertise.rsi --help
Show/Enable/Disable RSI to be advertised
Usage:
	 rsi [on/off]
[bluetooth]# advertise.rsi
RSI: on
[bluetooth]# advertise on
...
Advertising object registered
Tx Power: off
Name: off
Appearance: off
Discoverable: on
RSI: on
[bluetooth]#
2023-04-05 17:00:00 -07:00
Luiz Augusto von Dentz
815f779aa8 client: Use AdvertisingFlags when available
This prints devices not discoverable in grey so the user are able to
distict when for example set members are actually visible.
2023-03-10 13:41:06 -08:00
Luiz Augusto von Dentz
373bafc34c client: Add support for DeviceSet proxy 2023-03-10 13:41:06 -08:00
Luiz Augusto von Dentz
9a550d43b8 client: Allow gatt.select-attribute to work with local attributes
This allows gatt.select-attribute local to select from the registered
attributes:

[bluetooth]# gatt.select-attribute local /org/bluez/app/service0/chrc0
[/org/bluez/app/service0/chrc0]# gatt.write 0x01
[CHG] Attribute /org/bluez/app/service0/chrc0 (%UUID) written
[/org/bluez/app/service0/chrc0]# gatt.read
01                                               .
[/org/bluez/app/service0/chrc0]# gatt.select-attribute local
 /org/bluez/app/service0/chrc1
[/org/bluez/app/service0/chrc1]# gatt.write 0x01
[CHG] Attribute /org/bluez/app/service0/chrc1 (%UUID) written
[/org/bluez/app/service0/chrc1]# gatt.read
01                                               .
[/org/bluez/app/service0/chrc1]#
2022-12-06 13:01:28 -08:00
Luiz Augusto von Dentz
a4bde19d3b client: Move common print_* functions to its own file
This move common print_* functions to its own file so they can be
properly reused instead of duplicating the code.
2022-12-02 11:20:26 -08:00
Bastien Nocera
48992da64f client: Print the PowerState property 2022-09-01 11:43:41 -07:00
Luiz Augusto von Dentz
d297a5873d client: Add -e/--endpoint option to auto register endpoints
This adds -e/--endpoint option that can be used to auto register
supported endpoints.
2022-08-29 14:36:06 -07:00
Christian Eggers
9b93d95884 client: Add missing return statement in error path
Client will SEGFAULT if default_ctrl==NULL
2022-08-29 13:06:14 -07:00
Luiz Augusto von Dentz
64abbf7cee client: Move admin submenu
This moves admin submenu to admin.c so it is not mixed up with other
submenus code.
2022-08-15 16:28:14 -07:00
Inga Stotland
79fe529d64 client: Fix setting of advertisement interval
This fixes incorrect argument read when using "interval" command
in "advertisement" submenu
2022-05-23 13:47:15 -07:00
Zhengping Jiang
bda2a9e6f9 client: Add filter to devices and show Bonded in info
Use the property name as optional filters to the command "devices" and
show the "Bonded" property for the command "info".

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
2022-05-04 14:56:05 -07:00
Luiz Augusto von Dentz
d204e84c06 client: Add support for player submenu
This moves adds the functionality of bluetooth-player into
bluetoothctl.
2022-03-30 12:54:29 -07:00
Luiz Augusto von Dentz
18af5f4faf client: Add support for scan <le/bredr>
This adds support for entering the transport directly as an scan
argument rather than having to first set it scan.transport.
2022-03-02 16:30:11 -08:00
Miao-chen Chou
f4151f35b2 client: Print error code for connect methods
The following steps were performed.
- Issuing repeated commands to connect the same BLE device.
- Verifying the print in bluetoothctl console

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Howard Chung <howardchung@google.com>
2021-10-04 15:44:56 -07:00
Luiz Augusto von Dentz
1e9ce5ed80 client: Print MTU on attribute-info
This prints the MTU of the characteristic when available.
2021-09-28 16:53:08 -07:00
Archie Pusaka
28a5c47650 client: Inclusive language changes
Use "parent" to describe dbus hierarchy.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2021-09-21 10:51:54 +02:00
Luiz Augusto von Dentz
b84f294cb1 client: Add support for printing ExperimentalFeatures property
Thid adds support to show command to print ExperimentalFeatures property:

[bluetooth]# show
Controller ...
	Experimental: BlueZ Experimental LL p.. (15c0a148-c273-11ea-b3de-0242ac130004)
2021-09-08 14:12:58 -07:00
Yun-Hao Chung
bb0714be21 client: add AffectedByPolicy property
This prints property AffectedByPolicy in device info if
org.bluez.AdminPolicyStatus1 exists.

This also rename find_battery_by_path to find_proxies_by_path to reuse
the function.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-08-11 11:18:22 -07:00
Yun-Hao Chung
4f3adc7bef client: add admin submenu and allow command
This creates a menu - admin and add a commands to bluetoothctl
- allow [clear/uuid1 uuid2 ...]

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-08-11 11:18:22 -07:00
Luiz Augusto von Dentz
4e7780d0eb client/advertising: Add support for setting min/max intervals
This adds support for setting MinInterval/MaxInterval.
2021-05-13 13:26:13 -07:00
Daniel Winkler
0b8e166fd8 client: Add adv SupportedFeatures to bluetoothctl
This change adds SupportedFeatures to be shown in "show" option of
bluetoothctl. It was tested with and without kernel support for features
to verify that they are shown or not shown correctly.

Change was tested by verifying SupportedFeatures were populated
correctly in bluetoothctl on hatch and kukui chromebooks

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-03-17 11:30:27 -07:00
Archie Pusaka
ad02a4eddb bluetoothctl: advmon rssi support for mgmt
Using the new opcode MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI to
monitor advertisement according to some RSSI criteria.
2021-01-15 11:55:06 -08:00
Daniel Winkler
664c55440b client: Add SupportedCapabilities to bluetoothctl
This patch adds the new "SupportedCapabilities" property to the
bluetoothctl "show" view.

The change is tested by verifying bluetoothctl shows the desired
properties.
2020-10-29 17:45:40 -07:00
Tedd Ho-Jeong An
f22f166d6e client: Add SPDX License Identifier
This patch adds SPDX License Identifier and removes the license text.

-------------------------------------
       License            COUNT
-------------------------------------
 GPL-2.0-or-later     :      11

License: GPL-2.0-or-later
   client/adv_monitor.c
   client/adv_monitor.h
   client/advertising.h
   client/display.c
   client/main.c
   client/display.h
   client/agent.h
   client/gatt.c
   client/agent.c
   client/advertising.c
   client/gatt.h
2020-09-21 16:19:33 -07:00
Howard Chung
566db0ed69 client: Implement more interfaces of ADV monitor in bluetoothctl
This patch creates a submenu in bluetoothctl and implements several
commands.

new commands:
[bluetooth]# menu monitor
[bluetooth]# add-or-pattern 1 2 ab0011
Advertisement Monitor 0 added
[bluetooth]# add-or-pattern-rssi -80, ,5 1 2 aa 3 4 ff
Advertisement Monitor 1 added
[bluetooth]# get-pattern all
Advertisement Monitor 0
	path: /org/bluez/adv_monitor_app/0
	type: or_patterns
	pattern 1:
		start position: 1
		AD data type: 2
		content: ab0011
Advertisement Monitor 1
	path: /org/bluez/adv_monitor_app/1
	type: or_patterns
	rssi:
		high threshold: -50
		high threshold timer: 5
		low threshold: -80
		low threshold timer: 5
	pattern 1:
		start position: 1
		AD data type: 2
		content: aa
	pattern 2:
		start position: 3
		AD data type: 4
		content: ff
[bluetooth]# get-supported-info
Supported Features:
Supported Moniter Types: or_patterns
[bluetooth]# remove-pattern 0
Monitor 0 deleted
2020-09-16 09:38:03 -07:00
Howard Chung
664e10ff7e client: Implement basic interface of ADV monitor in bluetoothctl
This patch implements some basic functions for ADV monitor in
bluetoothctl

[bluetooth]# show
...
Advertisement Monitor Features:
	SupportedMonitorTypes: or_patterns
2020-09-16 09:37:42 -07:00
Miao-chen Chou
4d0336ea40 client: Add cancel-pairing command
This adds cancel-pairing command which can be used to cancel the ongoing
pairing.
2020-08-21 10:50:04 -07:00
Alain Michaud
615d82331d client: Add support for the Roles property.
This adds support for reading the Roles property through bluetootctl's
show option.

[bluetooth]# show
...
Roles: central
Roles: peripheral
Roles: central-peripheral
2020-07-07 10:49:34 -07:00
Abhishek Pandit-Subedi
d4c2c8a473 client: Display wake allowed property with info
Display whether the device is configured as wake allowed when queried
with cmd_info.
2020-07-07 10:46:48 -07:00
Sonny Sasaka
841b7ebe0f client: Add battery percentage to info command
This adds the Battery Percentage to the info command based on
org.bluez.Battery1 API. Example usage:

[bluetooth]# info XX:XX:XX:XX:XX:XX
Device XX:XX:XX:XX:XX:XX (random)
        Name: ...
        Alias: ...
        ...
        Modalias: ...
        Battery Percentage: 0x64 (100)
2020-07-02 16:22:10 -07:00
Luiz Augusto von Dentz
4ec7da4037 client: Add scan.pattern command
This uses the new Pattern filter:

[bluetooth]# scan.pattern Living
[bluetooth]# scan on
SetDiscoveryFilter success
Discovery started
[CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
[NEW] Device XX:XX:XX:XX:XX:XX Living Room TV
2020-02-19 16:25:04 -08:00
Syam Sidhardhan
a64d370949 client: Fix memory leak 2019-12-08 06:08:46 +02:00
Ronan Pigott
d45b4ac3ec client/main: add help option for available args
This option exists to facilitate external completion of commands that
have specially defined arguments. It effectively adds two new commands
to bluetoothctl with the following output:

$ bluetoothctl agent help
on
off
DisplayOnly
DisplayYesNo
KeyboardDisplay
KeyboardOnly
NoInputNoOutput

$ bluetoothctl advertise help
on
off
peripheral
broadcast

Shell completion scripts can then parse this output to provide
completions for those commands.
2019-09-06 10:57:10 +03:00
Luiz Augusto von Dentz
d705d726c6 client: Print AdvertisingManager properties on command 'show'
This outputs the AdvertisingManager properties command 'show':

bluetoothctl> show
...
Advertising Features:
	ActiveInstances: 0x00
	SupportedInstances: 0x05
	SupportedIncludes: tx-power
	SupportedIncludes: appearance
	SupportedIncludes: local-name
2019-02-21 14:08:57 +02:00
Luiz Augusto von Dentz
bd0808bf01 client: Add advertise.secondary command
This adds advertose.secondary command which can be used to set a
secondary channel to advertise.
2019-02-21 14:08:52 +02:00
Luiz Augusto von Dentz
183d47c176 client: Add gatt.clone command
This adds clone command to gatt submenu which can be use to clone
services as follow:

Clone all services from the connected device:
> gatt.clone

Clone a given service
> gatt.select-attribute <attribute/uuid>
> gatt.clone

In either case there is a prompt to confirm since this may add a lot of
service the user must confim before proceding.

Then finally:

> gatt.register-application
2019-02-13 17:09:13 +02:00
Luiz Augusto von Dentz
db15160d5c client: Add type to write command
This enables setting the write type as optional third parameter:

write <data=xx xx ...> [offset] [type]

The type can be used to force a specific procedure to be used, for
example to force reliable writes one can enter:

> write 00 0 reliable
2019-02-11 11:29:21 +02:00
Luiz Augusto von Dentz
d5cb29ce5a client: Enable list-attributes to print local attributes
This enable passing "local" to list-attributes to print the attributes
registered locally:

> list-attributes local
Primary Service (Handle 0x0400)
	/org/bluez/app/service0x74ccb0
	0x1820
	Internet Protocol Support
2019-01-31 14:10:54 +02:00
Luiz Augusto von Dentz
918f6f932b client: Enable setting attribute handles
This emulates application setting their attribute handles.
2019-01-31 14:10:51 +02:00