Commit Graph

302 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Brian Gix
63b7276460 mesh: Fix memory leak in Join() API call 2019-12-04 09:11:46 -08:00
Brian Gix
681b623c82 mesh: Rearrange PB-ACK for possible session close
In certain circumstances, reception of PB-ADV messages may trigger
session close. This rearrange ACKs new verified messages before
performing call-back to avoid situations where the session no longer
exists after the message has been handled.

This caused static analysis errors during provisioning, which are now
addressed.
2019-12-04 09:11:46 -08:00
Prathyusha N
467d282562 mesh: Fix to send close indication on timeout
If pb_session is freed in timeout, close indication will not be sent.
pb_session is freed in pb_adv_unreg() and hence removed from tx_timeout.
Added acceptor_free() in acp_prov_close() to ensure pb_session is freed.
2019-12-04 09:10:38 -08:00
Prathyusha N
b317a4094f mesh: Fix string of public-oob and static-oob
Fix string typo as per mesh-api.txt
2019-12-03 10:21:22 -08:00
Prathyusha N
980525a762 mesh: Fix invalid transaction number in PROV_INVITE
For initiator, transaction number starts from 0x00 where as for acceptor
transaction number starts from 0x80. Since transaction number is
pre-incremented and sent in every packet, initialize it with 0xFF for
initiator and 0x7F for acceptor.
2019-12-03 10:21:22 -08:00
Aurelien Jarno
73401290cf mesh: fix (re)transmit count & interval steps
The Foundation Model Layer uses little endian ordering. As a
consequence the (re)transmit count and interval steps in the Config
Relay, Config Model Publication and Config Network Transmit messages
use the lower 3 bits for the (re)transmission count and the higher 5
bits for the interval steps.

The figure 4.5 in section 4.3.2.16 of the Mesh Profile Bluetooth
Specification provides a good clarification.

This patch therefore fixes those messages for both the daemon and
configuration client parts.
2019-12-02 12:07:28 -08:00
Brian Gix
f246d31a77 mesh: Friendship clean-up and rewrite
Friendship support re-written such that it can now support multiple
nodes (on multiple mesh networks) as friends to remote Low Power Nodes
(LPNs).  Validated to properly respond to Friend Requests when enabled,
and a hard coded Friend Queue size of 32 (FRND_CACHE_MAX).
2019-11-28 13:49:59 -08:00
Brian Gix
100dfc4501 mesh: clean-up Recieved Message debug output
For each received packet, this change limits outputing the encrypted
version once, and the decrypted version once per applicable local node.
2019-11-28 13:49:59 -08:00
Michał Lowas-Rzechonek
28dbca0e49 mesh: Inform application about model subscriptions 2019-11-26 10:56:44 -08:00
Michał Lowas-Rzechonek
676c91d055 mesh: Provide destination address in MessageReceived API 2019-11-26 10:56:44 -08:00
Brian Gix
ab95c132bc mesh: Ignore Composition features during attach
Node Features are currently all under the control of the mesh daemon,
and should be ignored when attaching.  Eventually all Composition
feature bits will be controlled by a master mesh.conf file, overriding
any local node specific settings.
2019-11-26 08:52:29 -08:00
Rafał Gajda
56d144ca8f mesh: Fix dbus management interface input params
Previously input parameters in "org.bluez.mesh.Management1"
would not register properly, being shifted by one:
     <method name="ImportRemoteNode">
		 <arg name="" type="q" direction="in"/>
		 <arg name="primary" type="y" direction="in"/>
		 <arg name="count" type="ay" direction="in"/>
	 </method>

 This fixes this issue:
	 <method name="ImportRemoteNode">
		 <arg name="primary" type="q" direction="in"/>
		 <arg name="count" type="y" direction="in"/>
		 <arg name="dev_key" type="ay" direction="in"/>
	 </method>
2019-11-20 14:48:16 -08:00
Brian Gix
4853937edd mesh: Fix inOOB and outOOB agent handling on prov initiate
This code fixes the Provisioner Initiator role so that the following
Out-of-Band agent calls are made correctly, and their results handled
properly:

"push", "twist", "blink", "beep", "vibrate", "in-numeric",
"out-numeric", "in-alpha", "out-alpha"
2019-11-19 15:22:18 -08:00
Rafał Gajda
53a81750db mesh: Fix crash after deleting all subscriptions 2019-11-19 15:22:18 -08:00
Aurelien Jarno
8a29b59d98 mesh: fix node default TTL
There is a confusion between the node default TTL (section 4.2.7) and
the publish TTL (section 4.2.2.5):

- The node default TTL can only take values 0x00, and 0x02 to 0x7f. The
  value 0xff is not prohibited.
- The publish TTL can take values 0x00 to 0x7f, as well as 0xff which
  means use the node default TTL.

Currently the default node TTL is set to 0xff (DEFAULT_TTL), and
read_default_ttl() also allows such a value. This patch fixes that to
use 0x7f (TTL_MASK) as the default value instead.

Note that the code handling OP_CONFIG_DEFAULT_TTL_SET correctly use 0x7f
(TTL_MASK) for the upper allowed limit.
2019-11-19 15:22:18 -08:00
Inga Stotland
dcc46d4cee mesh: Fix io inititalization sequence
This introduces a chain of callbacks to indicate whether mesh io
is initialized and mesh network is ready to use.

This fixes the reported situation when the receive callbacks
were setup before the HCI was fully initialized. In other words,
BT_HCI_CMD_LE_SET_SCAN_PARAMETERS was called before BT_HCI_CMD_RESET
and, as the result, the callback issueing BT_HCI_CMD_LE_SET_SCAN_ENABLE
command was not called.
2019-11-15 09:23:16 -08:00
Inga Stotland
d64f6c8855 mesh: Cancel unprovisioned scan on exit or app disconnect
If a provisioner app quits or the daemon is stopped while there's
an active scan for unprovisioned devices in progress, the scan needs
to be explicitly canceled.
2019-11-14 14:10:18 -08:00
Michał Lowas-Rzechonek
6dcea66fc2 mesh: Add missing property interface to node objects 2019-11-13 08:35:31 -08:00
Michał Lowas-Rzechonek
8e5a2f9d98 mesh: Fix ignored return value
This fixes the following build error when compiling in maintainer mode:

mesh/keyring.c: In function ‘finalize’:
mesh/keyring.c:142:8: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
  (void)write(fd, &key, sizeof(key));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-11-13 08:35:31 -08:00
Aurelien Jarno
93eaad5883 mesh: fix sending messages to group addresses
When sending a message to a group address (either virtual or fixed), it
has to be sent OTA even if successfully enqueued to an internal model.
2019-11-12 09:37:23 -08:00
Inga Stotland
5ae38ddb39 mesh: Fix clean up after AddNode method
This fixes the cleanup routine that is called after AddNode method
on org.bluez.mesh.Manager1 interface is complete: do not remove
the agent associated with the Provisioner (owner of Manager interface).
2019-11-12 09:37:23 -08:00
Inga Stotland
05e7b8ffe4 mesh: Add authorization checks for Manager iface methods
This adds a check for org.bluez.mesh.Manager1 interface calls to
validate that a message sender, i.e. thatt the sender is the original
owner of the node object generated on Attach() method call.
If the check fails, org.bluez.mesh.Error.NotAuthorized is returned.
2019-11-04 09:32:18 -08:00
Marcel Holtmann
ba617285b8 mesh: Adjust for changed l_dbus_object_manager_enable parameters 2019-10-31 07:33:48 +01:00
Inga Stotland
bf6f4a28bb mesh: Fix reading/writing key indices
This fixes inconsistency when reading/writing NetKey and AppKey
indices to/from JSON config storage:
	- when writing, convert an integer to hex string
	- when reading, convert hex string to uint16 integer
2019-10-28 09:35:42 -07:00
Jory Pratt
2d249af381 Include limits.h for PATH_MAX 2019-10-21 10:21:17 -07:00
Inga Stotland
4881c2659b mesh: Implement AddAppKey and AddNetKey methods
This adds implementation for the following methods on
org.bluez.mesh.Node1 interface:
void AddNetKey(object element_path, uint16 destination,
		uint16 subnet_index, uint16 net_index, boolean update)
void AddAppKey(object element_path, uint16 destination,
		uint16 app_index, uint16 net_index, boolean update)
2019-10-18 15:56:19 -07:00
Inga Stotland
12f29e685c mesh: Add provisioner confirmation
This adds codes to send a confirmationfrom provisioner's side
after receiving a callback from a provisioning agent.
2019-10-16 12:27:26 -07:00
Brian Gix
9a6ffbbb88 mesh: Secure Beacon - IV_Index/Key Refresh re-write
This is a major rewrite of Secure Network Beacon (SNB) handling
that includes:

* Seperating Key Refresh from IV_Index handling

  This is a clearer handling of the two features. Although both features
  are represented in SNB's, they run independantly.

* Creating a Seperate IV_Index initialization and updating state
  distinct from the current values sent and received in SNBs.

  If a restart occured during an IV Update procedure (96 hours long)
  the IVU bit got lost, and Sequence number resetting was not done
  correctly.

* Assuring that all Nodes handled by daemon receive each incoming
  beacon. SNB handling previously stopped after the first node
  successfuly handled it, although the SNB may be valid for many local
  nodes.
2019-10-14 13:32:26 -07:00
Inga Stotland
d6a0539d1d mesh: Fix segmentation fault on Join() call
This fixes the following segfault:

node_init_cb (node=0x0, agent=0x0) at mesh/mesh.c:359
        reply = dbus_error(join_pending->msg, MESH_ERROR_FAILED,

        user_data=0x5555555be170) at mesh/node.c:1760
        dbus=<optimized out>) at ell/dbus.c:216
        user_data=0x5555555a6e00) at ell/dbus.c:279
        user_data=0x5555555a7ef0) at ell/io.c:126
        at ell/main.c:642
        at mesh/main.c:205

The fault was caused by the premature deletion of preserved state.

This moves setup of disconnect watch for the application calling the Join()
method into the node_init_cb(), after a temporary node has been
successfully created.
2019-10-05 08:53:50 -07:00