Commit Graph

24277 Commits

Author SHA1 Message Date
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
Luiz Augusto von Dentz
ac04719e41 shared/shell: Allow executing submenu commands
This makes it possible to execute submenu commands directly from the
main menu by using the format <submenu>.<command>:

[bluetooth]# advertise.uuids 0x1820
[bluetooth]# advertise.name blah
[bluetooth]# advertise on
Advertising object registered
UUID: Internet Protocol Support(0x1820)
Tx Power: off
LocalName: blah
Apperance: off
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
0c2900e54e shared/shell: Disable readline while in noninteractive mode
User shall not be able to interact with the shell while in
noninteractive mode.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
deae158e2b shared/shell: Disable bt_shell_prompt_input in noninteractive mode
Only the input given as argument shall be processed, all the rest shall
be ignored.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
f718b35b1b shared/shell: Fix not handling sort options
getopt_long index is only valid for long options.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
9cafbbb181 shared/shell: Do not quit immediatelly on noninteractive mode
The command handler shall be able to tell when it is done by calling
bt_shell_noninteractive_quit.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
f40565d5a9 shared/shell: Fix timeout parameter
Fix help message and add proper optstr modifier so both -t/--timeout
work properly.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
799a9eb388 shared/shell: Fix not reseting optind
Not reseting optind may crash the tool if getopt and variants are
called a second time.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
23b257aa47 shared/shell: Add bt_shell_{noninteractive_}quit
The functions can be used to tell the shell to stop running.
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
457a4f7d52 shared/mainloop-glib: Fix calling g_main_loop_quit with NULL
This produces warnings such as:

(process:5122): GLib-CRITICAL **: g_main_loop_quit: assertion 'loop != NULL' failed
2018-02-28 16:17:13 +02:00
Luiz Augusto von Dentz
27d5e62420 sharead/mainloop-glib: Fix mainloop_exit*
These function shall cause the mainloop to quit.
2018-02-28 16:17:13 +02:00
Szymon Janc
31f0c4e9c1 shared/btp: Fix return type in btp_send
This function returns bool.
2018-02-26 13:54:03 +01:00
Szymon Janc
06eb3d8045 shared/btp: Allow to call btp_send without valid btp
This allows to unconditionally call btp_send from code that generates
events eg when mapping those from D-Bus events.
2018-02-26 13:54:03 +01:00
Steve Brown
48a2c3db1c mesh: node: Correct minor errors
Correct length computation in node_parse_composition()
Correct return value in node_set_model()
  An existing node is not an error
2018-02-25 20:32:14 +02:00
Steve Brown
444af714a2 mesh: prov-db: Correct json database parsing
"composition": {
        "cid": "0002",
        "pid": "0010",
        "vid": "0001",
        "crpl": "000a",
        "features": {
            "relay": false,
            "proxy": true,
            "friend": false,
            "lowPower": false
        },
        "elements": [
            {
                "elementIndex": 0,
                "location": "0001",
                "models": ["0000", "0001", "1001"]
            }
        ]
    },
2018-02-25 20:32:12 +02:00
Luiz Augusto von Dentz
703229adb7 shared/shell: Use mainloop wrappers instead of GLIB directly
This will allow the shell to be used by the likes of btmgmt.
2018-02-22 11:52:16 +02:00
Luiz Augusto von Dentz
4653ff97a3 shared/util: Add strdelimit and strsuffix 2018-02-22 11:52:16 +02:00
Luiz Augusto von Dentz
a287cb4229 shared/mainloop: Add GLIB wrapper
This adds wrappers function to interface with GLIB mainloop so
applications can use mainloop functions no matter what is the underline
implementation.

Note: Most functions are not actually implemented on purpose since both
io and timeout functions already exists for GLIB covering the same
functionality.
2018-02-22 11:52:16 +02:00
Luiz Augusto von Dentz
fd656b1ce3 client: Don't auto register agent on non-interactive mode
There is no use to register an agent when on non-interactive mode.
2018-02-22 11:52:16 +02:00
Luiz Augusto von Dentz
21e4ed93e3 shared/shell: Set NON_INTERACTIVE env
This sets NON_INTERACTIVE environment variable which applications can
then use to query under what mode they are running.
2018-02-22 11:52:15 +02:00
Luiz Augusto von Dentz
982c73e118 tools/obexctl: Only enable attach input when connected 2018-02-22 11:52:15 +02:00
Luiz Augusto von Dentz
6962320860 tools/bluetooth-player: Only enable attach input when connected 2018-02-22 11:52:15 +02:00
Luiz Augusto von Dentz
0985a5943a shared/shell: Add non-interactive mode
This detects if any command was given as parameter, execute it and
exit disabling all other outputs:

bluetoothctl list
Controller 00:1B:DC:07:31:88 Vudentz's T460s #1 [default]
Controller B8:8A:60:D8:17:D7 BlueZ-1

It is also possible to run interactive command with use of timeout
option:

bluetoothctl --timeout=10 advertise on
Agent registered
[CHG] Controller 00:1B:DC:07:31:88 SupportedInstances: 0x04
[CHG] Controller 00:1B:DC:07:31:88 ActiveInstances: 0x01
Advertising object registered
Tx Power: off
Name: off
Apperance: off
2018-02-22 11:52:15 +02:00
Szymon Janc
c3f7b6733c adapter: Add ConnectDevice method
This allows to connect device without doing general discovery. This is
needed for some of qualification tests where there is no general
discovery upfront and we need to do connection to device with provided
address.

Another usecase is for scenario where scanning happen on one controller
but connection handling on another.

New device object is announced only if physical connection was
successful. On success this method returns path to created device
object. After ConnectProfile return bluetoothd continue with
services discovery and profile connection.

This patch implements bare minimum properties needed for connection -
address and address type. If needed eg. for non-NFC based OOB it could
be extended with more options.
2018-02-21 15:05:52 +01:00
Szymon Janc
19cb7b8c8a shared/shell: Fix history display with no saved prompt
Prompt needs to be restored always since default prompt is provided.
This fix issues with history line being clobbered by offset of prompt
length.

[bluetooth]# connect 9C:5C:F9:AB:C5:82
Attempting to connect to 9C:5C:F9:AB:C5:82
[bluetooth]# disconnect 9C:5C:F9:AB:C5:82
Attempting to disconnect from 9C:5C:F9:AB:C5:82
Failed to connect: org.bluez.Error.Failed
Successful disconnected
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 5C:E0:C5:34:AE:1C Discoverable: yes
[bluetooth]# disconnect discoverable on

after pressing up-down
[bluetooth]# disconnect dis5C:F9:AB:C5:82
2018-02-21 08:59:52 +01:00
Luiz Augusto von Dentz
8b21a74f2e adapter: Fix crash when discovering
If client exits while start discovery command is pending it may produce
the following crash:

Invalid read of size 8
   at 0x49036E: start_discovery_complete (adapter.c:1428)
   by 0x4D4957: request_complete (mgmt.c:261)
   by 0x4D5BD4: can_read_data (mgmt.c:353)
   by 0x4E717A: watch_callback (io-glib.c:170)
   by 0x50CEB76: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.5400.3)
   by 0x50CEF1F: ??? (in /usr/lib64/libglib-2.0.so.0.5400.3)
   by 0x50CF231: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.5400.3)
   by 0x40CEC0: main (main.c:770)
 Address 0x0 is not stack'd, malloc'd or (recently) free'd
2018-02-20 16:43:07 +02:00
Luiz Augusto von Dentz
1bf0336942 shared/io: Don't process HUP cond before others
When a HUP happens there maybe data left to be processed so the
disconnect handler shall be called last.
2018-02-20 16:43:07 +02:00
Luiz Augusto von Dentz
bc3f2cff83 device: Fix probing service twice
If there is already a service for a given profile there is no point in
probing it again.
2018-02-20 16:43:07 +02:00
Szymon Janc
0d57a236bf adapter: Fix not clearing connectable setting on power off
When kernel control of connectable is used daemon doesn't enable
connectable setting unless discoverable. Both settings are permanent
over power toggle unless discoverable timeout was set. In that case
discoverable flag is cleared by kernel on power off. This leads to
connectable flag being left enabled when toggling power on discoverable
adapter with timeout set.

This has some implications on system behaviour:
 - accepting connection from unknown devices
 - not being able to advertise as broadcaster

Since kernel doens't know the reason for enabling connectable flag (and
thus if disable if on power off) this needs to be handled in bluetoothd.
2018-02-19 19:15:02 +02:00
ERAMOTO Masaya
9c90fc508d client: Add clear command for advertise
Adds the clear command to advertise-related commands to clear individual
fields or whole of advertise configuration.
2018-02-19 12:21:11 +02:00
ERAMOTO Masaya
4d04b9f573 client: Introduce ad_disable_{uuids,service,manufacturer} 2018-02-19 12:21:11 +02:00
ERAMOTO Masaya
f0fccd6f4d client: Introduce data_clear() calling ->clear() 2018-02-19 12:21:11 +02:00
ERAMOTO Masaya
0540ff6339 client: Improve help messages for advertise 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
3e900572b6 adapter: Fix initializing GATT server for BR/EDR only controllers
Controller that do not support LE bearer shall not use GATT server for
anything.
2018-02-16 20:02:41 +02:00
Steve Brown
287cd9b515 mesh: meshctl: Add subscriptions to node structure and json database
sub-add 0101 c000 1000

              {
                "modelId":"1000",
                "bind":[
                  1
                ],
                "subscribe":[
                  "c000"
                ]
              },
2018-02-16 12:38:20 +02:00
ERAMOTO Masaya
c361096818 obexd: Fix null response name
Prints out "<unknown>" string if there is no response name as below:

  obexd[8117]: obexd/src/obex.c:cmd_connect()
  obexd[8117]: CONNECT(0x0), (null)(0xffffffff)
2018-02-14 12:50:31 +02:00
Matt Schulte
2fa53e0fb6 advertising: only parse adv from adv interfaces
client_proxy_added is called for every interface on an object passed in
to the dbus RegisterAdvertisement method. This can cause a NULL
dereference to occur and a failure status in the reply on dbus
RegisterAdvertisement method calls. The fix is to return early from
client_proxy_added if the proxy interface is not
org.bluez.LEAdvertisement1. If this early return is not there, two
different error paths could occur.

1) client_proxy_added is first called with the
org.bluez.LEAdvertisement1 interface and then with another interface.
The second call will fail the parse_advertisement call and possibly
cause a NULL dereference on the dbus_message_unref if
add_client_complete has already occurred.

2) client_proxy_added is first called with an unknown interface and then
org.bluez.LEAdvertisement1. The first call will cause
parse_advertisement to fail and a failure to be replied to the client
calling RegisterAdvertisement. The advertisement may be successfully
registered on the second client_proxy_added call but a NULL dereference
will occur on the call to dbus_message_new_method_return in
add_client_complete.
2018-02-13 14:21:55 +02:00
Steve Brown
0412f3843b mesh: meshctl: Conform command and function names
Also improve readability of commands descriptions
2018-02-13 14:05:50 +02:00
Steve Brown
7f33e5cc09 mesh: meshctl: Cleanup status messaging
Remove redundant status tests
  mesh_status_str() also decodes MESH_STATUS_SUCCESS
Regularize text in status messages
Add helper function to print model id
2018-02-13 14:05:48 +02:00
Steve Brown
3cb9770549 mesh: meshctl: Add heartbeat get subscribe and publish
[config: Target = 0100]# hb-pub-get

Set heartbeat for node 0100 status: Success
Destination:	c000
Count:		00
Period:		00
TTL:		ff
Features:	0000
Net_Idx:	0000

[config: Target = 0100]# hb-sub-get

Heartbeat subscription status for node 0100 status: Success
Source:		0100
Destination:	0100
Period:		00
Count:		00
Min Hops:	7f
Max Hops:	00
2018-02-13 14:05:43 +02:00
Grzegorz Kolodziejczyk
1b5ece8797 shared/btp: Change struct member order for device found as in btp
This patch changes member order in device found struct definition to be
compatible with btp specification.
2018-02-13 09:12:29 +01:00
Grzegorz Kolodziejczyk
30faa9965a tools/btpclient: Fix ad property manufacturer data name
This patch fixes wrong naming of advertising instance data property.
2018-02-13 09:12:29 +01:00
Konstantin Zhukov
d13f579a36 shared/gatt-db: Fix declaration attributes permission
According to Bluetooth Core specification v4.2 (Vol. 3, part G,
section 3.1), service declararion attributes should have only READ
permission. The same obligation has charateristic declaration and
include service declaration attributes.

Without this permission connected clients could corrupt GATT database
by writing to declaration attributes. After thatm service discovery
fails in other clients.
2018-02-12 13:43:34 +02:00
ERAMOTO Masaya
5d2baeb644 tools/obexctl: Fix display of size on completion
Outputs zero as the transferred size on completion of transfer as below:

  [CHG] Transfer /org/bluez/obex/server/session3/transfer2 Transferred: 5339965 (@32KB/s 00:01)
  [CHG] Transfer /org/bluez/obex/server/session3/transfer2 Transferred: 5372726 (@32KB/s 00:00)
  [CHG] Transfer /org/bluez/obex/server/session3/transfer2 Transferred: 0 (@18446744073704178KB/s 00:00)
  [CHG] Transfer /org/bluez/obex/server/session3/transfer2 Status: complete
2018-02-12 13:36:11 +02:00
ERAMOTO Masaya
3c2d4613be tools/obexctl: Fix retrieving non-existent iterator
If transfer is completed with one time file transfer,
transfer_property_changed() is called with the iter argument, which is
NULL, as below:

  #0  transfer_property_changed (proxy=<optimized out>, name=<optimized out>, iter=0x0, user_data=0x5555557b9060) at tools/obexctl.c:1896
  #1  0x000055555556e3cf in properties_changed (conn=<optimized out>, msg=<optimized out>, user_data=0x5555557c8300) at gdbus/client.c:433
  #2  0x000055555556c830 in signal_filter (connection=0x5555557c65a0, message=0x5555557ccea0, user_data=0x5555557cdbf0) at gdbus/watch.c:407
  #3  0x000055555556c291 in message_filter (connection=0x5555557c65a0, message=0x5555557ccea0, user_data=<optimized out>) at gdbus/watch.c:557
  #4  0x00007ffff7888661 in dbus_connection_dispatch () from /lib/x86_64-linux-gnu/libdbus-1.so.3
  #5  0x000055555556b010 in message_dispatch (data=0x5555557c65a0) at gdbus/mainloop.c:72
  #6  0x00007ffff7b0be25 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  #7  0x00007ffff7b0c1f0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  #8  0x00007ffff7b0c502 in g_main_loop_run () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  #9  0x0000555555577594 in bt_shell_run () at src/shared/shell.c:833
  #10 0x000055555556516d in main (argc=<optimized out>, argv=<optimized out>) at tools/obexctl.c:2116
2018-02-12 13:36:10 +02:00
ERAMOTO Masaya
bb16051518 obexd: Emit Size property of transfer after open()
Emits the Size property of transfer after calling ->open() because it
may update the size information.
2018-02-12 13:36:09 +02:00
ERAMOTO Masaya
3e9617fcd8 obexd: Use emitting function wrapped for transfer
Also replaces emit_transfer_progress() with the new wrapper function
because the total/transferred arguments have not been used since commit
a5c2b6e8 ("obexd: Align client and server spec of org.bluez.obex.Transfer1")
and g_dbus_emit_property_changed_full() checks if the path argument is
NULL.
2018-02-12 13:35:33 +02:00