Commit Graph

25194 Commits

Author SHA1 Message Date
Jakub Witowski
f6ac2a872b mesh: Add sequence nr getter to the doc 2020-01-14 10:55:54 -08:00
Inga Stotland
6fe78e8746 mesh: Correctly generate NetKey list
When responding with NetKey List Status, packed NetKey indices into
3 octets per pair. If number of NetKeys is odd, append the last key
index as a 2-octet value.
2020-01-14 06:32:23 -08:00
Inga Stotland
812ac8197e tools/mesh: Remove node's appkeys when deleting a netkey
When a netkey is deleted from a remote node, all the appkeys bound
to this netkey are expected to be deleted as well.
This fixes app_key queue manipulation to avoid issues caused by modifying
the queue while iterating over it: instead of iteration over all the
entries, find a first bound key, delete it, find next... and so on,
until there are no bound keys left in the app_keys queue.
2020-01-14 06:32:23 -08:00
Inga Stotland
07eaf8d2c0 tools/mesh: Fix check condition for model ID
Use the value of VENDOR_ID_MASK to set/check vendor model
and SIG model IDs
2020-01-14 06:32:23 -08:00
Inga Stotland
dd985d771f tools/mesh: add commands for AppKey Get and NetKey Get
This implements commands to send AppKey Get and NetKey Get messages and
to process AppKey List and NetKey List reponses
2020-01-14 06:32:23 -08:00
Michał Lowas-Rzechonek
559410f33a mesh: Fix exiting IV_UPD_STATE when receiving first SNB
First valid SNB received from the network should cause the node to
switch into IV_UPD_NORMAL state.

Otherwise, it will never try to enter IV Update procedure when sequence
number approaches the IV_UPDATE_SEQ_TRIGGER, because that's only allowed
in IV_UPD_NORMAL.
2020-01-14 06:32:23 -08:00
Michał Lowas-Rzechonek
038b0b11e1 mesh: Allow apps to receive DevKey messages from external nodes
After introducing "remote" flag for DevKeyMessageReceived in
c8cd5b04cc, we can now allow applications
to received DevKey messages from external addresses as well as from
local ones.

This enables applications to properly implement models using DevKey
security, by accepting only requests with "remote" flag set to false.
2020-01-14 06:32:23 -08:00
Inga Stotland
e2b6608934 mesh: Fix wholesale deletion of appkeys bound to a netkey
When a netkey is deleted all the appkeys bound to this key has
to be deleted as well. This fixes app_key queue manipulation to
avoid issues caused by modifying the queue while iterating over it:
instead of iteration over all the entries, find a first bound key,
delete it, find next... and so on, until there are no bound keys
left in the app_keys queue.
2020-01-14 06:32:23 -08:00
Inga Stotland
6baade2306 mesh: Fix logic in AppKey deletion
When deleting an AppKey from a node, call mesh_config_app_key_del()
only from appkey level (i.e., keep it contained in appkey.c and
remove the duplicate call in node.c)

Also, simplify the node_app_key_delete() argument list.
2020-01-14 06:32:23 -08:00
Haochen Tong
8ce47e7175 avctp: Fix EINVAL on uinput creation
The struct uinput_dev variable is on stack, so clear its content to
avoid accidentally writing garbage values to kernel. This fixes "Can't
create uinput device: Invalid argument (22)" in some cases.
2020-01-13 17:30:53 -08:00
Brian Gix
ad7db1fa1f mesh: Implement provisioning loop-back
This allows one App using the mesh daemon to provision another.
2020-01-13 09:15:15 -08:00
howardchung
b4270d79e1 audio/a2dp - fix crash during recovering process
The crash with stack trace:

(libc-2.27.so -raise.c:51 )      		raise
(libc-2.27.so -abort.c:79 )      		abort
(libc-2.27.so -libc_fatal.c:181 )        	__libc_message
(libc-2.27.so -malloc.c:5350 )   		malloc_printerr
(libc-2.27.so -malloc.c:4157 )   		_int_free
(libglib-2.0.so.0.5200.3 -gslist.c:878 )        g_slist_free_full
(bluetoothd -a2dp.c:165 )       		setup_unref
(bluetoothd -a2dp.c:2184 )      		a2dp_cancel
(bluetoothd -sink.c:317 )       		sink_unregister
(bluetoothd -service.c:176 )    		service_remove
(bluetoothd -device.c:4678 )    		device_remove
(bluetoothd -adapter.c:6573 )   		adapter_remove
(bluetoothd -adapter.c:8832 )   		index_removed
(bluetoothd -queue.c:220 )      		queue_foreach
(bluetoothd -mgmt.c:304 )       		can_read_data
(bluetoothd -io-glib.c:170 )    		watch_callback
(libglib-2.0.so.0.5200.3 -gmain.c:3234 )        g_main_context_dispatch
(libglib-2.0.so.0.5200.3 -gmain.c:3972 )        g_main_context_iterate
(libglib-2.0.so.0.5200.3 -gmain.c:4168 )        g_main_loop_run
(bluetoothd -main.c:798 )       		main
(libc-2.27.so -libc-start.c:308 )        	__libc_start_main
(bluetoothd + 0x0000b089 )      		_start
(bluetoothd + 0x0000b05f )      		_init

triggered when 'usb disconnect' happened during AVDTP_SET_CONFIGURATION
request is sent but haven't received the response.
In this situation, the recovering process goes into sink.c:sink_free and
then a2dp.c:a2dp_cancel, avdtp.c:cancel_request, avdtp.c:connection_lost,
avdtp.c:release_stream.

During recovering, the reference count of setup and avdtp decrease more
than it increase, which ends up causing the crash.

The reference count of setup decreases one more time since
a2dp.c:setconf_cfm(called by cfm->set_configuration in
avdtp.c:cancel_request) was called in the 'error mode', which didn't
reference the setup, but in a2dp.c:abort_cfm(called by cfm->abort in
avdtp.c:release_stream), the reference count decreased by 1.

In this case, abort_cfm shouldn't be called as we already know
setconf_cfm didn't send any request. Setting avdtp_sep_state to
AVDTP_STATE_ABORTING should avoid this issue.

The reference count of avdtp decrease one more time since
both sink.c:sink_free and sink.c:sink_set_state(called from
avdtp.c:connection_lost -> avdtp.c:avdtp_set_state) unreference avdtp
for the session. The changes in sink.c should avoid the issue.
2020-01-10 15:50:35 -08:00
Szymon Janc
7a3c319306 AUTHORS: mention Szymon's contributions 2020-01-09 11:37:28 +01:00
Szymon Czapracki
edbcf61d7c monitor: Decode LE CTE Request Failed event 2020-01-09 11:36:05 +01:00
Szymon Czapracki
ec77812442 monitor: Decode LE Set Default Periodic Adv Sync Transfer Params. command
< HCI Command: LE Set Default Periodic Advertisng Sync Transfer Parameters (0x08|0x005d) plen 6
        Mode: Enabled with report events disabled (0x01)
        Skip: 0x00
        Sync timeout: 0 msec (0x0000)
        Sync CTE type: 0x0000
> HCI Event: Command Status (0x0f) plen 4
      LE Set Default Periodic Advertisng Sync Transfer Parameters (0x08|0x005d) ncmd 1
        Status: Unknown HCI Command (0x01)
2020-01-09 11:36:05 +01:00
Szymon Czapracki
e0eaaa45d8 monitor: Decode LE Set Periodic Adv Sync Transfer Parameterers command
< HCI Command: LE Periodic Advertising Sync Transfer Parameters (0x08|0x005c) plen 8
        Connection handle: 1
        Mode: Disabled (0x00)
        Skip: 0x00
        Sync timeout: 0 msec (0x0000)
        Sync CTE type: 0x0000
> HCI Event: Command Status (0x0f) plen 4
      LE Periodic Advertising Sync Transfer Parameters (0x08|0x005c) ncmd 1
        Status: Unknown HCI Command (0x01)
2020-01-09 11:36:05 +01:00
Szymon Czapracki
9e9ad8ec1c monitor: Decode LE Periodic Advertising Set Info Transfer command
< HCI Command: LE Periodic Advertising Set Info Transfer (0x08|0x005b) plen 5
       Connection handle: 1
       Service data: 0x0000
       Advertising handle: 0
> HCI Event: Command Status (0x0f) plen 4
     LE Periodic Advertising Set Info Transfer (0x08|0x005b) ncmd 1
       Status: Unknown HCI Command (0x01)
2020-01-09 11:36:05 +01:00
Szymon Czapracki
b73d4bb9e3 monitor: Decode LE Periodic Advertising Sync Transfer command
< HCI Command: LE Periodic Advertising Sync Transfer (0x08|0x005a) plen 6
        Connection handle: 1
        Service data: 0x0001
        Sync handle: 1
> HCI Event: Command Status (0x0f) plen 4
      LE Periodic Advertising Sync Transfer (0x08|0x005a) ncmd 1
        Status: Unknown HCI Command (0x01)
2020-01-09 11:36:05 +01:00
Szymon Czapracki
5a97b877f2 monitor: Decode LE Set Periodic Advertising Receive Enable command
< HCI Command: LE Periodic Advertising Receive Enable (0x08|0x0059) plen 3
        Sync handle: 0
        Reporting: Enabled (0x01)
> HCI Event: Command Status (0x0f) plen 4
      LE Periodic Advertising Receive Enable (0x08|0x0059) ncmd 1
        Status: Unknown HCI Command (0x01)
2020-01-09 11:36:05 +01:00
Szymon Czapracki
228c945a93 monitor: Decode LE Periodic Advertising Sync Transfer Received Event 2020-01-09 11:36:05 +01:00
Szymon Czapracki
f135411989 monitor: Update periodic sync commands.
Change fields in periodic_adv_(create/term)_sync_cmd, according to their
description with 5.1 specification.

< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044) plen 14
        Options: 0x0001
        Use Periodic Advertiser List
        Reporting initially enabled
        SID: 0x00
        Adv address type: Public (0x00)
        Adv address: 00:00:00:00:00:00 (OUI 00-00-00)
        Skip: 0x0000
        Sync timeout: 0 msec (0x0000)
        Sync CTE type: 0x0000
> HCI Event: Command Status (0x0f) plen 4
      LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
        Status: Unknown HCI Command (0x01)
2020-01-09 11:36:05 +01:00
Michał Lowas-Rzechonek
f314075531 mesh: Fix BeaconFlags property type
This property is an uint8, not a boolean.
2020-01-08 14:02:36 -08:00
Rafał Gajda
a7ba7ae31a mesh: Remove local_iv_index and local_ivu aliases 2020-01-08 13:55:21 -08:00
Rafał Gajda
d3093475b5 mesh: Fix IV recovery
This patch fixes saving IV received in SNB to storage.

Previously after creating new node with IV 0 (or loading node with
IV > 0 but after long inactivity) first received SNB should update IV
(and reset sequence number to 0 if necessary).

The bug would prevent new IV being saved in storage which resulted in
sequence number being set to 0 on first SNB received after every daemon
reset but IV never being updated.
2020-01-08 13:55:21 -08:00
Michał Lowas-Rzechonek
1169eb4434 mesh: Remove misleading DEFAULT_CRPL from node.c 2020-01-08 09:07:15 -08:00
Michał Lowas-Rzechonek
7ff2bb9efe mesh: Fix node reset
Instead of stopping the daemon, just remove the node.
2020-01-08 09:07:15 -08:00
Inga Stotland
59d5f21e6c mesh: Style fix
This fixes style issues: spaces -> tabs, alignment.
2020-01-06 07:29:34 -08:00
Anurag Biradar
9e79b13932 meshctl: Fix meshctl crash
list entry was not updated properly during flushing of packets

<call stack>
flush_pkt_list (list=0x638b40 <net+64>) at tools/mesh-gatt/net.c:1199
net_session_close (data_in=<optimized out>) at tools/mesh-gatt/net.c:1979
disconnect_device (cb=cb@entry=0x0, user_data=user_data@entry=0x0)
  at tools/meshctl.c:791
cmd_start_prov (argc=<optimized out>, argv=0x6a9fb0)
  at tools/meshctl.c:1789
2020-01-06 07:29:34 -08:00
Anurag Biradar
fe8b3bda77 meshctl: Fix infinite sock read
When a stream socket peer has performed an orderly shutdown,
then return value will be 0.
2020-01-06 07:29:34 -08:00
Luiz Augusto von Dentz
9f9d1bc9ae agent: Detect when ongoing request is already in progress
This detects when a agent request is already pending for the same device
which could happen when there are 2 or more adapters in the system and
they are trying to pair with each other.
2019-12-27 10:35:55 -08:00
Prathyusha N
99fa144721 mesh: Start link establishment timer of 60 sec
5.3.2 of Mesh Profile Bluetooth specification:
To open a link, the provisioner shall start the link establishment
timer, set to 60 seconds, and then shall start sending Link Open
messages.

On timeout, close indication will be sent. Provisioner cancels the
Link Establishment timer, when the link is open i.e. in pb_adv_tx().
2019-12-27 08:55:25 -08:00
Inga Stotland
11d7fe8535 mesh: Base config json code on newer version of json-c
This removes a roundabout logic that was required to delete
a json entry from a json array using libjsonc utilities.
A new API function, json_object_array_del_idx(), implemented in
json-c version 0.13 simplifies array entry removal to one call.

Also, add requirement to configure.ac for json-c version >= 0.13
2019-12-24 10:38:34 -08:00
Brian Gix
ffdd4f5817 mesh: Recognize SNBs in SecondsSinceLastHeard
Timestamp is taken on each OTA beacon reception, and considered in the
SecondsSinceLastHeard property.
2019-12-24 10:38:34 -08:00
Brian Gix
bdfae8a570 mesh: Deliver newly composed SNBs to local nodes 2019-12-24 10:38:34 -08:00
Inga Stotland
2903ffb285 TODO: Update mesh section 2019-12-20 09:01:49 -08:00
Michał Lowas-Rzechonek
b9a4d9410b mesh: Fix getting managed objects from ObjectManager
D-Bus spec mandates that GetManagedObjects method of
org.freedesktop.DBus.ObjectManager interface returns *children* only:

https://dbus.freedesktop.org/doc/dbus-specification.html
> All returned object paths are children of the object path implementing
> this interface, i.e. their object paths start with the ObjectManager's
> object path plus '/'

Both test scripts and ELL abuse this by returning application interfaces
via ObjectManager attached to the same path, but other D-Bus
implementations do not, making Attach() fail because mandatory
interfaces cannot be found.

This patch fixes the issue by scanning hierarchy returned by
GetManagedObjects for object implementing org.bluez.mesh.Application1
interface and keeping that as node's app_path.
2019-12-18 07:46:16 -08:00
Inga Stotland
4a1bea28b1 mesh: Add mesh-main.conf file with general mesh configuration
This adds key file with default settings for the mesh daemon.
The following settings are included:

    Beacon:          Default setting for to indicate whether
                     secure network beaconing is enabled for a
                     node whose Beacon state hasn't been configured
                     by a configuration client, i.e., this setting
                     apllies to a newly provisioned, created or
                     imported node.

    Relay:           Default setting for supporting relay

    Friendship:      Default setting for supporting Friendship

    CRPL:            Default depth of replay protection list.

    FriendQueueSize: Default size of friend queue: the number
                     of messages that each Friend node can store
                     for the Low Power node.

    ProvTimeout:     Provisioning timeout in seconds.
2019-12-16 14:52:36 -08:00
Aurelien Jarno
cf0a39476e tools/mesh-cfgclient: add friend get/set commands
Add friend-get and friend-set commands as per Mesh Profile 4.3.2.55,
4.3.2.56 and 4.3.2.57.
2019-12-16 14:49:03 -08:00
Aurelien Jarno
d49839d00b tools/mesh-cfgclient: add network transmit get/set commands
Add network-transmit-get and network-transmit-set commands as per
Mesh Profile 4.3.2.69, 4.3.2.70 and 4.3.2.71.
2019-12-16 14:49:03 -08:00
Guillem Jover
56f7a456cc shared/mainloop: Use connect() instead of bind() for sd_notify
We are the client, so we should be using connect(2) instead of bind(2),
otherwise when using non-abstract Unix sockets we will get an error that
the address is already in use.

This breaks the notify support in dpkg's start-stop-daemon.
2019-12-16 11:08:58 -08:00
Brian Gix
6a83d14670 mesh: Cleanup unused LPN code
The daemon does not support the LPN role, and this is unreferenced code.
2019-12-16 08:18:35 -08:00
Brian Gix
9955657fa2 mesh: Refactor Secure Network Beaconing
The daemon handles multiple nodes, that may or may not be on the same
mesh network.  While each node my be seperately configured to beacon or
not beacon, there is nothing gained (except redundent traffic) for each
node to beacon seperately.  Beaconing is therefore centralized with the
Network Key the SNB represents, with each *received* beacon delivered
to each node. But for SNBs generated, we keep a count of how many nodes
want beacons sent for a specific key. If 1 or more, we beacon, if 0
nodes want the beacon sent, then we do not beacon.
2019-12-16 08:18:20 -08:00
Inga Stotland
3ed6e9f90c mesh: Add more checks for element properties
This adds consistency checks for mandatory properties on
org.bluez.mesh.Element1 interface:
    - disallow duplicate models on the same element
    - disallow elements with duplicate indices
    - disallow configuration server model on any element but primary
2019-12-15 09:36:10 -08:00
Inga Stotland
3228ce1472 mesh: Remove redundant code in mesh IO mgmt
This removes unnecessary housekeeping for hci controllers
2019-12-15 09:33:37 -08:00
Inga Stotland
ce2f88bd2c mesh: Initialize net modes based on node configuration
This correctly initializes net settings related to node features
based on node configuration: either defaults in the case of
a newly node created/provisioned/imported node or the configured
values read from stored existing node.
2019-12-10 09:57:11 -08:00
Inga Stotland
e289b30b58 mesh: Clean up node.c
This change makes the node initialization a bit easier to follow.
Replace if-else with switch when processing request type, descriptive
function names, more predictable code flow.
2019-12-10 09:57:11 -08:00
Inga Stotland
3ee0672f52 mesh: Delete unused function
This removes node_parse_composition() implementation as it is not used
anywhere in the rest of the code base.
2019-12-10 09:57:11 -08:00
Inga Stotland
9f108507ca tools/mesh-cfgclient: Fix appkey/netkey commands
This fixes the checks for the presence of AppKeys and Netkeys.
2019-12-10 09:48:57 -08:00
Inga Stotland
70a324d864 tools/mesh-cfgclient: Disallow sending a non-existing key
Prior to sending either NetKeyAdd or AppKeyAdd message to a
remote node, check if the key exists locally.
2019-12-10 09:29:02 -08:00
Syam Sidhardhan
a64d370949 client: Fix memory leak 2019-12-08 06:08:46 +02:00