Commit Graph

58 Commits

Author SHA1 Message Date
Prathibha Madugonde
b2371f9f11 Fix discoverable property not emitted on updating value to false
client/advertising.c:
Allowing discoverable property to list in the parsing
function when discoverable is off.

Test steps:
From DUT, bluetoothctl go to menu advertise
set discoverable to off and then advertise on.
2024-07-08 11:51:41 -04:00
Luiz Augusto von Dentz
4dea3fb932 client/advertising: Add flag to mark if data is valid
This allows the use of type 0x00 which otherwise could not be selected
since the property would not be exposed even though the data could be
set.
2024-04-19 15:35:10 -04:00
Luiz Augusto von Dentz
4578395b53 client/advetising: Allow use of EA data length
The code was supporting a maximum of 25 bytes (31 - 6) to be entered as
advertising data, but in case of EA is used that allows up to 245 bytes
(251 - 6) to be entered.
2023-07-10 12:24:47 -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
c8836711ad client: Fix advertise.data command
advertise.data when no parameter is given shall print what is set on
ad.data not the ad.manufacturer which is a different field set by
advertise.manufacturer.
2022-10-20 15:55:55 -07:00
Christian Eggers
147cc4cf99 client/advertising: Fix typos: *_exits --> *_exists 2022-08-29 13:06:23 -07:00
Luiz Augusto von Dentz
7f92f75e88 client/advertising: Fixes errors found by scan-build
This fixes the following errors:

client/advertising.c:129:4: warning: Value stored to 'n' is never read
[deadcode.DeadStores]
                        n = sizeof(str) - 1;
                        ^   ~~~~~~~~~~~~~~~
client/advertising.c:1012:25: warning: Dereference of null pointer
(loaded from variable 'min') [core.NullDereference]
        if (ad.min_interval != *min) {
                               ^~~~
2022-06-22 11:16:18 -07:00
Luiz Augusto von Dentz
f287a42cd6 client/advertising: Fix not disabling local-name in Includes
When setting a advertising.name other than on/off it shall also disable
local-name flag from Includes as that would cause an error when parsed
by the daemon.
2021-08-10 14:59:12 -07:00
Luiz Augusto von Dentz
c3159848b9 client: Fix advertise broadcast
When advertising with type broadcast it cannot be discoverable as that
would require setting flags which is not allowed by the spec.
2021-05-14 17:25:52 -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
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
Barry Byford
c24db50c43 client: Fix typo in bluetoothctl 2020-08-31 10:33:48 -07:00
Luiz Augusto von Dentz
397cbeb864 client: Make advertise instances default to discoverable
The more common case is that advertisements are discoverable not the
other way around.
2020-04-07 12:52:23 -07:00
Luiz Augusto von Dentz
b723fafbbe client: Fix crash when setting advertising.discoverable on
DBUS_TYPE_BOOLEAN expect a pointer to dbus_bool_t not bool.
2019-05-10 14:58:09 +03: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
Marcel Holtmann
261948090e build: Move declaration of _GNU_SOURCE back into individual source files 2018-12-06 21:28:18 +01:00
Luiz Augusto von Dentz
806276fe54 client: Add advertise.discoverable-timeout command
This adds advertise.discoverable-timeout command which can be used to
limit the amount of time the advertisement is discoverable:

[bluetooth]# advertise.discoverable on
[bluetooth]# advertise.discoverable-timeout 10
[bluetooth]# advertise on

@ MGMT Command: Add Advertising (0x003e) plen 14
        Instance: 1
        Flags: 0x00000001
          Switch into Connectable mode
        Duration: 0
        Timeout: 0
        Advertising data length: 3
        Flags: 0x02
          LE General Discoverable Mode
        Scan response length: 0
@ MGMT Event: Advertising Added (0x0023) plen 1
        Instance: 1
@ MGMT Event: Command Complete (0x0001) plen 4
      Add Advertising (0x003e) plen 1
        Status: Success (0x00)
        Instance: 1
@ MGMT Command: Add Advertising (0x003e) plen 14
        Instance: 1
        Flags: 0x00000001
          Switch into Connectable mode
        Duration: 0
        Timeout: 0
        Advertising data length: 3
        Flags: 0x00
        Scan response length: 0
2018-05-24 11:09:31 +03:00
Luiz Augusto von Dentz
e8f51b980c client: Print AD Data and Discoverable once registered
This prints both Data and Discoverable if advertise command succeeds:

[bluetooth]# advertise.data 0x26 0x01 0x00
[bluetooth]# advertise.discoverable on
[bluetooth]# advertise on
Advertising object registered
Data Type: 0x26
  01 00                                            ..
Tx Power: off
Name: off
Apperance: off
Discoverable: on
2018-05-24 11:09:30 +03:00
Luiz Augusto von Dentz
4f68e5f1fe client: Add advertise.discoverable command
This adds advertise.discoverable command which can be used to set it
own instance:

[bluetooth]# advertise.discoverable on
[bluetooth]# advertise on

@ MGMT Command: Add Advertising (0x003e) plen 14
        Instance: 1
        Flags: 0x00000001
          Switch into Connectable mode
        Duration: 0
        Timeout: 0
        Advertising data length: 3
        Flags: 0x02
          LE General Discoverable Mode
        Scan response length: 0
< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32
        Length: 3
        Flags: 0x02
          LE General Discoverable Mode
2018-05-24 11:09:30 +03:00
Luiz Augusto von Dentz
8cfef5aa0c client: Fix use of g_free
g_free shall only be used with pointer allocated with g_* functions.
2018-05-21 11:35:06 +03:00
Luiz Augusto von Dentz
72c9b97f5e client: Add support for setting advertising Data property
This adds data command to advertise menu which can be used to set
an arbitrary/profile specific advertising type and data:

[bluetooth]# data 0x26 0x01 0x01 0x00
2018-05-02 12:01:41 +03:00
ERAMOTO Masaya
76d29b9bad client: Fix stay on error handling in non-interactive
Returns the FAILURE status since there is no meaning of stay in
non-interactive mode when executing some commands with an invalid
argument or with no controller. Also returns with the SUCCESS status
when getting a scan filtering value or disconnecting a non-default
device.
2018-03-23 13:19:04 +02:00
Luiz Augusto von Dentz
41465ce57c client: Fix lines going beyond 80 columns 2018-03-01 11:23:09 +02:00
ERAMOTO Masaya
237365998f client: Use g_dbus_dict_append_*() 2018-03-01 10:49:05 +02:00
Luiz Augusto von Dentz
936ad5ef7b client: Quit when done with command
This ensures that the commands don't stay hanging since bt_shell no
longer quits immediatelly after executing a command.
2018-02-28 16:17:13 +02:00
ERAMOTO Masaya
4d04b9f573 client: Introduce ad_disable_{uuids,service,manufacturer} 2018-02-19 12:21:11 +02:00
ERAMOTO Masaya
3df943537a client: Fix data growth if reconfiguring ad service
Since commit 65eff5c2 ("client: Rename set-service to service"), data
are appended in every run of advertise service with data arguments as
below:

  [bluetooth]# service 1 1 2
  [bluetooth]# service
  UUID: SDP(1)
    01 02                                            ..
  [bluetooth]# service 1 1 2 3
  [bluetooth]# service
  UUID: SDP(1)
    01 02 01 02 03                                   .....
2018-02-19 12:21:11 +02:00
ERAMOTO Masaya
7c6d0647ee client: Not output ad service info if no uuid sets 2018-02-19 12:21:11 +02:00
ERAMOTO Masaya
3de5807a53 client: Fix null output for ad service uuid
If getting the advertise service information without setting, outputs
null as UUID as below:

  [bluetooth]# service
  UUID: ((null))
2018-02-19 12:21:11 +02:00
Luiz Augusto von Dentz
0c8e542c4d client: Print advertising details
Print advertising details when active.
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
5c6ef1c396 client: Rename set-timeout to timeout
Make the command return the current value if no parameters:

[bluetooth]# timeout 1
[bluetooth]# timeout
Timeout: 1 sec
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
f309255a99 client: Rename set-duration to duration
Make the command return the current value if no parameters:

[bluetooth]# duration 1
[bluetooth]# duration
Duration: 1 sec
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
aebb7e1973 client: Rename set-appearance to appearance
Make the command return the current value if no parameters:

[bluetooth]# appearance 0x0001
[bluetooth]# appearance
Appearance: Unknown (0x0001)
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
821ad2ecd4 client: Rename set-name to name
Make the command return the current value if no parameters:

[bluetooth]# name blah
[bluetooth]# name
LocalName: blah
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
0c33c99102 client: Rename set-tx-power to tx-power
Make the command return the current value if no parameters:

[bluetooth]# tx-power on
[bluetooth]# tx-power
Tx Power: on
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
045e6b9a10 client: Rename set-manufacturer to manufacturer
Make the command return the current value if no parameters:

[bluetooth]# manufacturer 2 00
[bluetooth]# manufacturer
Manufacturer: 2
  00
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
65eff5c2eb client: Rename set-service to service
Make the command return the current value if no parameters:

[bluetooth]# service 0x1820 00 00 00
[bluetooth]# service
	UUID: Internet Protocol Support (0x1820)
  00 00 00                                         ...
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
6f20dba32d client: Rename set-uuids to uuids
Make the command return the current value if no parameters:

[bluetooth]# uuids 0x1820
[bluetooth]# uuids
UUID: Internet Protocol Support (0x1820
2018-01-19 11:44:09 -02:00
Luiz Augusto von Dentz
8edcc31fa2 shared/shell: Don't remove command from arguments
Maintain the original argc and argv so the callback has a chance to
parse the command if it has to.
2017-12-08 13:06:11 +02:00
Luiz Augusto von Dentz
0fb2aff316 shared/shell: Use wordexp to parse arguments
This ensures the arguments are parsed properly.
2017-11-17 16:00:19 +02:00
Luiz Augusto von Dentz
70b8b754f8 client: Make use of bt_shell
Use bt_shell instead of readline directly.
2017-11-17 16:00:19 +02:00
Luiz Augusto von Dentz
068e0ba214 client: Add set-advertise-{duration, timeout}
This adds the following command which can be used to control the
advertisement intervals:

[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances: 0x04
[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances: 0x01
Advertising object registered
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances: 0x05
[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances: 0x00
2017-11-02 16:03:41 +02:00
ERAMOTO Masaya
8221f8336c client: Clear ad manufacturer/service data when too much data
When data is too much, the data may include values not making sense, so
this patch clears the advertising manufacturer/service data corresponding
to the running command.
2017-11-02 13:18:19 +02:00
ERAMOTO Masaya
d3974659e3 client: Fix clearing advertising service data
Even if running set-advertise-manufacturer with data having an invalid
value, client does not clear the advertising service data and clears the
advertising manufacturer data.
2017-11-02 13:18:19 +02:00
Anupam Roy
bdfe5fcee3 client: Fix segmentation fault while fetching advertising data
While testing advertisement, I encountered Seg fault in client, when bluetoothd
tries to fetch the Adv data set by client. It can happen either while fetching
Manufacturer specific data or Service data. Backtrace is provided below for reference
After fix is applied, advertisement works fine for me. I am sending the following patch
your review. Thank you.

Passing val instead of &val in dbus_message_iter_append_fixed_array
DBUS API causes segmentation fault while fecthing Manufacturer
data or service data set by client.

BT Before Fix:
[bluetooth]# set-advertise-name Test
[bluetooth]# set-advertise-uuids 0x1824
[bluetooth]# set-advertise-manufacturer 0x75 0x02 0x03 0x04
[bluetooth]# advertise on

Program received signal SIGSEGV, Segmentation fault.
in append_array_variant(iter=iter@entry=0x7fffffffd780,
val=val@entry=0x62485a <ad+90>, n_elements=n_elements@entry=3, type=121) at client/advertising.c:178
in dict_append_basic_array(type=121, n_elements=3,
val=0x62485a <ad+90>, key=0x624858 <ad+88>, key_type=113, dict=0x7fffffffd730) at client/advertising.c:205
get_manufacturer_data(property=<optimized out>, iter=0x7fffffffd840,
user_data=<optimized out>) at client/advertising.c:253

After Fix:
[bluetooth]# set-advertise-name Test
[bluetooth]# set-advertise-uuids 0x1824
[bluetooth]# set-advertise-manufacturer 0x75 0x02 0x03 0x04
[bluetooth]# advertise on
[CHG] Controller 00:19:0E:11:55:44 SupportedInstances: 0x04
[CHG] Controller 00:19:0E:11:55:44 ActiveInstances: 0x01
Advertising object registered
[bluetooth]#
2017-10-26 16:55:33 +03:00
ERAMOTO Masaya
fb0ccc9683 client: Prevent to pass invalid ad type to D-Bus 2017-09-25 15:44:02 +03:00
ERAMOTO Masaya
15225b1e0b client: Fix core dump when using set-advertise-name
If repeating to set on/off with set-advertise-name after setting local
name, and then may dump core by double free. This patch uses g_free()
instead of free().
2017-09-25 15:44:02 +03:00
ERAMOTO Masaya
115fd96871 client: Fix memory leak of advertise command
Since advertise command does not free the variable ad.type when repeating
to enable and disable advertising, the following memory leak occurs.

  11 bytes in 1 blocks are definitely lost in loss record 20 of 190
     at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
     by 0x4E89718: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2)
     by 0x4EA24EE: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2)
     by 0x40EBC8: ad_register (advertising.c:343)
     by 0x40A666: cmd_advertise (main.c:2344)
     by 0x40ABA3: rl_handler (main.c:2664)
     by 0x53C16F4: rl_callback_read_char (in /lib/x86_64-linux-gnu/libreadline.so.6.3)
     by 0x405AFC: input_handler (main.c:110)
     by 0x4E84049: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2)
     by 0x4E843EF: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2)
     by 0x4E84711: g_main_loop_run (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.2)
     by 0x4055FE: main (main.c:2865)
2017-09-25 15:44:02 +03:00
Luiz Augusto von Dentz
a41a625b1d client: Emit PropertiesChanged if advertising changes
This allows bluetoothd to detect changes done by the user without
having to rely on advertise command to unregister and register again:

bluetooth]# set-advertise-name blah
[bluetooth]# advertise on

@ MGMT Command: Add Advertising (0x003e) plen 17
        Instance: 1
        Flags: 0x00000003
          Switch into Connectable mode
          Advertise as Discoverable
        Duration: 0
        Timeout: 0
        Advertising data length: 0
        Scan response length: 6
        Name (complete): blah

[bluetooth]# set-advertise-name bleh

@ MGMT Command: Add Advertising (0x003e) plen 17
        Instance: 1
        Flags: 0x00000003
          Switch into Connectable mode
          Advertise as Discoverable
        Duration: 0
        Timeout: 0
        Advertising data length: 0
        Scan response length: 6
        Name (complete): bleh
2017-08-16 13:59:00 +03:00
Luiz Augusto von Dentz
5c3a39e642 client: Enable set-advertise-appearance to set Appearance
This enables set-advertise-appearance to use Appearance property:

[bluetooth]# set-advertise-appearance 128
[bluetooth]# advertise on

@ MGMT Command: Add Advertising (0x003e) plen 15
        Instance: 1
        Flags: 0x00000003
          Switch into Connectable mode
          Advertise as Discoverable
        Duration: 0
        Timeout: 0
        Advertising data length: 4
        Appearance: Computer (0x0080)
        Scan response length: 0
2017-08-10 16:32:09 +03:00