Commit Graph

384 Commits

Author SHA1 Message Date
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
Michał Lowas-Rzechonek
37bbe30c92 mesh: Align appkey_packet_decrypt with dev and virt variants.
Move appkey_packet_decrypt to mesh/model, rename it to
app_packet_decrypt, make it private and change arguments to be aligned
with other decryption functions.

Also, simplify the implementation using an inline loop, removing the
need of mod_decrypt struct.
2019-10-03 13:10:16 -07:00
Michał Lowas-Rzechonek
45beec16bd mesh: Normalize Access Key AID and Index naming in models
After 8f0839a1c4, mesh/crypto uses _aid
suffix for keys' AID property, so let's change the wording in mesh/model
as well.
2019-10-03 13:10:16 -07:00
Michał Lowas-Rzechonek
79fd24af14 mesh: Remove unused defines 2019-10-03 13:10:16 -07:00
Brian Gix
c75605726e mesh: Fix Key Ring permissions for local nodes
We do *not* automatically create populated key rings for imported or
joined nodes, but we also do not *forbid* any node from adding a key
in it's possesion to the local key ring.

There are two (known) use cases for Import()

1. Node previously existed on a different physical piece of hardware,
and is being migrated to this daemon.

2. Node was newly provisioned Out-Of-Band, and this is the net result
of the provisioning.

In *neither* case is it a given that the Node should be able to
provision another node (the effect of adding the Net Key to the key
ring). In neither case is it a given that the Node should be able to
modify it's own Config Server states (the effect of adding it's
Device Key to the key ring).
2019-10-01 10:42:02 -07:00
Brian Gix
0cdcff2f90 mesh: Explicit Remote/Local Device key usage
When sending or receiving Device Key (privileged) mesh messages, the
remote vs local device key must be specified. This allows Apps to
specify Key Ring stored device keys, and sanity checks that the correct
key exists before allowing the transmission. Loopback messages to local
servers *must* use keys from the Key Ring to indicate privilege has been
granted.
2019-10-01 10:41:52 -07:00
Inga Stotland
550dc90dfc mesh: Make mesh-config API more consistent
This changes the prototypes for mesh_config_model_binding_add() and
mesh_config_model_binding_del() to take the element's address as input
parameter instead of the element's index. The change aligns the API
with other functions that handle storage of model states.
2019-10-01 09:51:54 -07:00
Brian Gix
afe196816a mesh: Automate AppKey update on KR phase 2-->3-->0
Designed so that if an unexpcted abort() occurs, the bound NetKey remains
in state 2 or 3.  If successful, the NetKey is set to Phase 0, and all
bound AppKeys are in their correct state.
2019-09-10 09:32:40 -07:00
Inga Stotland
7a5bccba53 mesh: Handle messages sent to a fixed group address
This handles the case when an inbound message is addressed to
a fixed group, i.e., all-proxies, all-friends, all-relays and
all-nodes. The message is delivered to a primary element only,
and, with the exception of all-nodes case, if the corresponding
feature is enabled on the node.
2019-09-08 07:14:30 -07:00
Brian Gix
f62350b702 mesh: test AEAD at startup to check kernel support
One time test at startup to ensure either kernel version v4.9 or later,
*or* that required AES-CCM support has been back-ported. If support not
there, daemon will run without providing D-Bus service or attaching to
controllers (prevents systemd thrashing).
2019-09-01 08:34:00 -07:00
Inga Stotland
354d75d0ea mesh: Add closedir() of config directory after opendir()
This adds missing closedir() call to accompany opendir() in
mesh_config_load_nodes().
Also, fixes confusing mix of variable names.
2019-08-29 13:37:11 -07:00
Michał Lowas-Rzechonek
50f5827544 mesh: Show error message when io initialization fails 2019-08-28 09:43:17 -07:00
Michał Lowas-Rzechonek
3d7d12ee99 mesh: Add org.bluez.mesh.Node1.Addresses property
To enable applications to talk to the local node's internal models, it's
useful to know its unicast addresses. They are known after CreateNetwork
and Import, but after Join, the allocated address is only known to the
provisioner.

This patch enables read only access to list of allocated unicast
addresses.
2019-08-28 09:31:15 -07:00
Michał Lowas-Rzechonek
f370e72981 mesh: Implement properties on org.bluez.mesh.Node1 interface 2019-08-28 09:31:15 -07:00
Michał Lowas-Rzechonek
a29d610d25 mesh: Fix handling of Config Relay Set message 2019-08-16 08:24:45 -07:00
Inga Stotland
fb5c57bccb mesh: Move commonly used constants into mesh-defs.h
This consolidates definitions of commonly used constant values
into a single header file. The constant values are based on mesh
specification, plus a few internal utility constants (masks, etc.)

Also, removes redundant redefinition maximum message length.
2019-08-12 12:49:34 -04:00
Rafał Gajda
b94453eb2d mesh: Remove double initialisation and fix typo in log 2019-08-12 12:49:34 -04:00
Rafał Gajda
e71112ad71 mesh: Fix model publication get 2019-08-12 12:49:34 -04:00
Michał Lowas-Rzechonek
bdd0e6c521 mesh: Move sequence number overcommit to mesh-config-json
This confines sequence overcommit logic in mesh-config-json, as other
storages might use a different mechanism to ensure reliability.

Also, refactored logic to calculate overcommit value to avoid division
by zero when messages are sent too fast.
2019-08-08 15:17:37 -04:00
Inga Stotland
7de0eb5686 mesh: Fix double free of a pointer in mesh-io-generic
This fixes a crash in bluetooth-meshd due to freeing the same pointer
twice. The fix is to initialize the address of freed TX buffer to NULL.
2019-08-08 14:55:05 -04:00
Michał Lowas-Rzechonek
e4cec5a943 mesh: Fix storing network retransmission in config 2019-08-06 12:49:10 -04:00
Michał Lowas-Rzechonek
37cf5ad50e mesh: Implement Import() D-Bus API of org.bluez.mesh.Network1 interface
This method allows local nodes to be imported from an external
provisioning database, enabling applications to create mesh nodes
without using provisioning procedure.

The procedure is similar to provisioning procedure, but all data
exchange happens over D-Bus.
2019-08-01 13:26:42 -07:00
Jakub Witowski
d68a2253f6 mesh: Extract read_* functions in mesh-config-json
This is a small improvement of read_node function readability.
2019-08-01 13:26:42 -07:00
Michał Lowas-Rzechonek
b53bca542e mesh: Check that config server is present in primary element
This verifies that Config Server model is supported by element #0, and
is not supported by any other element.
2019-07-26 09:08:58 -07:00
Michał Lowas-Rzechonek
38608db686 mesh: Check that element indexes are consecutive 2019-07-26 09:08:58 -07:00
Michał Lowas-Rzechonek
5ed8cec71c mesh: Keep element and model lists sorted and unique
This keeps composition data unchanged even if elements or models are
registered in a different order.
2019-07-26 09:08:58 -07:00
Michał Lowas-Rzechonek
07e16e8aa6 mesh: Validate application by comparing composition data
Instead of validating application by enumerating D-Bus objects, create a
temporary node instance and check if composition data generated for the
temporary matches the node loaded from storage.

This allows node validation logic (primary element, mandatory models etc)
to be confined in node_generate_comp() function.

This also streamlines code implementing Attach(), Join() and
CreateNetwork() calls.
2019-07-26 09:08:58 -07:00
Michał Lowas-Rzechonek
7cd089ea6b mesh: Convert void pointers to anonymous unions in managed_obj_request 2019-07-26 09:08:58 -07:00
Inga Stotland
efcf88bff0 mesh: Fix storage init of Friend and LPN features
This fixes a typo in mesh-config-json.c when Friend feature
was initialized twice and LPN was not initialized at all.
2019-07-26 09:08:58 -07:00
Michał Lowas-Rzechonek
79bf51dbb5 mesh: Check address range passed to ImportRemoteNode
+changed "not authorized" error to "invalid args" when managing device
key for local address range
2019-07-19 12:25:53 -07:00
Brian Gix
060b3439f0 mesh: Propagate Net Index up Rx message chain
When a model receives a message, it is required by the spec
to respond using the same credentials. When an App Key is used,
this is trivial because App keys are bound to Net keys, so only
the App Index is required.  Messages received on a Device key
however, need the Net Index preserved from original message for
re-use during the response.
2019-07-18 09:49:21 -07:00
Brian Gix
8f0839a1c4 mesh: Normalize Access Key AID naming convention 2019-07-18 09:49:21 -07:00
Brian Gix
51d9bb20db mesh: Add bound Net Index lookup for App Keys
This patch also normalizes the naming convention in favor of key_aid
when referring to the calculated AID of the used Access Layer key.
2019-07-18 09:49:21 -07:00
Inga Stotland
faa7894b7b mesh: Allow sending on org.bluez.mesh.Provisioner1
This adds a new interface permission to bluetooth-mesh.conf:
<allow send_interface="org.bluez.mesh.Provisioner1"/>
2019-07-18 09:47:14 -07:00
Inga Stotland
d9ef18ff68 mesh: Init keyring storage directory on node Attach()
This adds initialization of keyring storage directory when
a mesh node is attached successfully.
2019-07-18 09:46:59 -07:00
Inga Stotland
3937a002a7 mesh: Rename mesh_config_srv_init() to cfgmod_server_init()
This renames mesh_config_srv_init() to cfgmod_server_init() to avoid
confusion with mesh_config_..> API and to reflect that the call pertains
to configuration server model.
2019-07-15 14:48:04 -07:00
Inga Stotland
2881bc1433 mesh: Create or re-use a node storage directory for keyring
This adds APIs to set a directory for storing node's key ring info.
The directory is named MESH_STORAGE_DIR/<node uuid>. This directory
may contain additional node info plus node configuration, if node
configuration storage follows the same layout (as it does when
JSON based config file format is used).
2019-07-15 14:48:04 -07:00
Inga Stotland
7cafe5fd7c mesh: Manage node config directory in mesh-config
This completely removes storage.c file. Instead, the handling
of mesh node configuration storage is done completely in
mesh-config layer by calling the following API functions:
bool mesh_config_load_nodes(const char *cfg_dir,
                            mesh_config_node_func_t cb,
                            void *user_data)

void mesh_config_release(struct mesh_config *cfg)
void mesh_config_destroy(struct mesh_config *cfg)

bool mesh_config_save(struct mesh_config *cfg, bool no_wait,
                      mesh_config_status_func_t cb, void *user_data)

struct mesh_config *mesh_config_create(const char *cfg_path,
                                       const uint8_t uuid[16],
                                       struct mesh_config_node *node)
2019-07-15 14:48:04 -07:00
Inga Stotland
d575246290 mesh: Use mesh_config APIs to store node configuration
This eliminates storage_set...() routines as an intermediate
layer between mesh_config layer and the rest of the daemon when
storing updated node configuration values.
For the JSON based implementation, each call to mesh_config_write...()
routines results in writing to the node configuration file.
2019-07-15 14:48:04 -07:00
Inga Stotland
c4bf0626fb mesh: Replace storage_save_config with mesh_config_save_config
This moves writing out of node configuration from storage.c down to
mesh-config-<format-specific>.c to allow for more generic storage layout.

New generalized API in mesh-config.h:
mesh_config_save_config(struct mesh_config *cfg, bool no_wait,
				mesh_config_status_func_t cb, void *user_data)

replaces the old one in storage.h:
storage_save_config(struct mesh_node *node, bool no_wait,
					mesh_status_func_t cb, void *user_data)

Currently, only JSON format is supported for storing node configuration:
mesh_config_save_config is implemented in mesh-config-json.c
2019-07-15 14:48:04 -07:00
Inga Stotland
d8b2bef41b mesh: Confine dependency on json-c to mesh-config-json.c
This removes dependency on json-s/json.h header from everywhere
in the code except for mesh-config-json.c. The details about
node configuration storage format are obfuscated: a pointer
to an opaque mesh_config structure is stored with mesh_node and is
passed around to mae all the storage related operations.
2019-07-15 14:47:36 -07:00
Inga Stotland
d1a76eb3f4 mesh: Move load from storage functionality into node.c
This moves the initialization of a mesh node from stored
configuration from storage.c to node.c
2019-07-15 14:44:38 -07:00
Inga Stotland
78668a02d6 mesh: Change mesh_db prefix to mesh_config
This changes the naming the API declarations in mesh-config.h:
mesh_db_... ->mesh_config_...
2019-07-15 14:44:38 -07:00
Inga Stotland
0c698b33a7 mesh: Rename mesh-db.c to mesh-config-json.c
This moves mesh-db.h to mesh-config.h and mesh-db.c to mesh-config-json.c.
mesh-config.h declares common APIs for storing mesh node configuration.
mesh-config-json.c defines the APIs for JSOn specific storage.
This allows for future parallel implementation a different (not JSON-based)
mechanism of storing node configuration.
2019-07-15 14:44:38 -07:00
Inga Stotland
76700ab92b mesh: Move network config setup from storage.c to node.c
This commit moves initialization of configuration parameters
for node->net when the local node state is restored from stored
configuration. Old location: storage.c, new locaiton node.c.
2019-07-15 14:44:38 -07:00
Brian Gix
2e46771050 mesh: Convert provisioning pkts to packed structs
Provisioning packets are defined in the specification
as packed big endian structures. Instead of specifying
an octet array, we now use struct matching the spec.
2019-07-14 08:32:18 -07:00
Brian Gix
20585d786b mesh: Implement DBus Provisioning methods
This implements the Interface and Methods for:
UnprovisionedScan()
UnprovisionedScanCancel()
AddNode()
2019-07-14 08:32:18 -07:00
Brian Gix
f7856093f9 mesh: Fix implementation of Provisioner Initiator
This has had testing of baseline functionality that includes
OOB authentication type "3c" from BT Mesh v1.0 specification
2019-07-14 08:32:18 -07:00
Brian Gix
76a7c41708 mesh: Expose resources needed by Management1 interface 2019-07-14 08:32:18 -07:00
Brian Gix
5f6dd3ff26 mesh: Expose mapping function for D-Bus errors 2019-07-14 08:32:18 -07:00
Brian Gix
ce29951980 mesh: Add special Beacon handler for Provisioning
Provisioning uses the same AD type for Provisioning that
is also used by the Secure Network Beacon, but their
usage is distinct from each other.  This change allows
us to enable/disable Unprovisioned Device Beacon capture
without disrupting SNB handling.
2019-07-14 08:32:18 -07:00
Brian Gix
fea558460f mesh: Fix support for Provisioner Initiator 2019-07-14 08:32:18 -07:00
Inga Stotland
cf7d8a2332 mesh: Fix segmentation fault when removing a node
This fixes a segmentation fault introduced by earlier changes.
Segmentation fault was used by accessing a queu that has been
destroyed, but the corresponding pointer hasn't been set to NULL.
2019-07-04 10:54:09 -07:00
Michał Lowas-Rzechonek
4e60dc5efe mesh: Handle messages encrypted with a remote device key
This adds ability to receive messages encrypted using known remote
device key. Such a key must be added to the node's keyring using
ImportRemoteNode() method of org.bluez.mesh.Management1 interface.

Decrypted messages are then forwarded to the application using
DevKeyMessageReceived() D-Bus API.

Also, messages originating from a local node and encrypted using local
device key are forwarde to the application as well, if they weren't
handled by internal model. This allows e.g. receiving status messages
from a local Config Server in the application.
2019-07-04 10:18:59 -07:00
Michał Lowas-Rzechonek
9e11b3eef4 mesh: Implement DevKeySend() method on Node interface
This patch implements D-Bus DevKeySend() method of org.bluez.mesh.Node1
interface, allowing the application to send messages encrypted using
a known remote device key.

At the moment the call ignores net_index argument and sends messages
using the primary subnet.

Also, it's no longer possible to use 'magic' key_index value 0x7fff
(denoting local device key) when calling regular Send(). Applications
should use DevKeySend() instead.
2019-07-04 10:18:52 -07:00
Michał Lowas-Rzechonek
9dfc56d7d4 mesh: Split APP_IDX_DEV into APP_IDX_DEV_LOCAL and APP_IDX_DEV_REMOTE
This is needed to distinguish incoming messages encrypted using a device
key: if the key is local, the message can be forwarded to internal
models. If the key is a known remote one, it will be forwarded to the
application via DevKeyMessageReceived() API.
2019-07-04 10:18:44 -07:00
Michał Lowas-Rzechonek
e3c5b38f09 mesh: Cleanup D-Bus method returns with empty result 2019-07-04 10:18:36 -07:00
Inga Stotland
70ffc81605 mesh: Use l_dbus_message...() APIs in more consistent fashion
This removes checks for the return values of l_dbus_message...()
calls in the few places where we can rely on ell to handle error
cases gracefully.
2019-07-04 10:08:49 -07:00
Inga Stotland
5f896b4795 mesh: Remove redundant initialization
This fixes a case where a variable was initialized twice.
2019-07-04 10:08:49 -07:00
Michał 'Khorne' Lowas-Rzechonek
5764d8bfdb mesh: Fix stack overflow in get_element_properties
D-Bus type 'q' denotes uint16, not uint8.
2019-07-03 17:03:23 -07:00
Inga Stotland
e0fd407fb9 mesh: Fix clean up of node's DBUS assosiated resources
This consolidates multiple places where node's object paths,
interfaces, etc. are de-allocated, into one routine:
free_node_dbus_resources().
This also addresses memory leaks assosiated with inconsistent freeing
of object path strings.
2019-07-03 17:03:23 -07:00
Inga Stotland
af06aebcc7 mesh: Fix checks when restoring internal model state
This fixes incorrect conditional checks in restore_model_state()
which could lead to dereferencing a NULL pointer.

Wrong: if (l_queue_isempty(mod->bindings) || !mod->cbs->bind) ...
Fixed: if (!l_queue_isempty(mod->bindings) && cbs->bind) ...
2019-07-03 17:03:23 -07:00
Brian Gix
3df89f700a mesh: Fix memory leak on dbus message creation 2019-07-03 09:40:51 -07:00
Jakub Witowski
cee1218397 mesh: Allow to set-up the CRPL with application
This adds an optional CRPL property to org.bluez.mesh.Application1
interface, allowing to indicate the depth of reply protection list.
2019-07-02 10:38:19 -07:00
Michał Lowas-Rzechonek
341456b547 mesh: Register D-Bus management interface
When application Attach()es itself, start exposing both Node1 and
Management1 D-Bus interfaces.
2019-07-01 12:38:33 -07:00
Jakub Witowski
97f68772e6 mesh: Clear nodes queue on get_managed_objects_cb() fails
Currently when the get_managed_objects_cb() fails it frees
the node resources but the node still remains on the "nodes" queue.

This implementation calls node_remove() instead of
free_node_resources()."
2019-07-01 09:17:43 -07:00
Inga Stotland
5a37a85fbc mesh: Fix and clean up model publication code
This adds proper checks for model publication removal:
the publication is not virtual and the publication address is set to zero,
i.e., UNASSIGNED_ADDRESS.
Also removes double memory allocation for model publication and
miscellaneous redundancies.
2019-07-01 09:17:43 -07:00
Inga Stotland
bb5d00cdc7 mesh: Fix virtual address processing
This tightens up the accounting for locally stored virtual addresses.
Alos, use meaningful variable names to identify components of a
mesh virtual address.
2019-07-01 09:17:43 -07:00
Inga Stotland
3ce332e405 mesh: Clean up model.c and cfg-server.c
This removes a number of redundancies, fixes naming conventions and
style.
2019-07-01 09:17:43 -07:00
Michał Lowas-Rzechonek
c957b8ea6f mesh: Fix D-Bus node path
According to doc/mesh-api.txt, node object should be located at
/org/bluez/mesh/node.
2019-07-01 09:17:43 -07:00
Michał Lowas-Rzechonek
3c143c7158 mesh: Fixed handling of IVI flag in app layer
Since IV Index is used in application nonces, we need to honor IVI flag
not only in network layer crypto, but also in application layer.

This means that if IVI field of incoming packet is different than in
current IV Index, try to decode *both* net and app layers using IV Index
decreased by one.
2019-06-27 10:13:35 -07:00
Inga Stotland
a0ced2910a mesh: Modify check of the node directory name upon removal
This removes check for "mesh" as the parent directory name and, instead,
verifies that the node configuration directory name is the hexadecimal
string representating the node's UUID.
2019-06-26 10:42:01 -07:00
Rafał Gajda
e0b1d64e39 mesh: Fix to duplicated model Ids saved to storage
Mesh daemon internally implements the Config Server SIG model.

When generating node, if the Mesh Element in mesh application
returns modelId 0 among its supported models, it should be skipped,
otherwise it will be duplicated and saved in the storage file.

This patch fixes correctly skipping Config Server model during node
creation.
2019-06-26 10:24:54 -07:00
Michał Lowas-Rzechonek
12b984d1d4 mesh: Move HCI handling to mesh-io-generic
This patch separates 'mesh' module from 'mesh_io', particularly
regarding configuration and initialization.

Main code is no longer aware of MGMT and HCI usage - querying available
HCI interfaces now happens in mesh-io-generic.

MGMT code is now extracted into mesh-mgmt module, which mesh-io-generic
uses to query interfaces.
2019-06-24 09:04:44 -07:00
Inga Stotland
510224f47c mesh: Remove redundant checks when adding a net key
This patch cleans up redundant checks in add_key() and mesh_net_set_key():
no need to check the result of l_queue_push_tail() and no need to check
if subnet is valid after it was successfully created.
2019-06-12 14:36:38 -07:00
Jakub Witowski
231c50a1ff mesh: Fix segmentation fault after adding second netkey via NET_KEY_ADD opcode
Segmentation fault was caused by passing subnet pointer to the
start_network_beacon() which was NULL
2019-06-11 15:26:39 -07:00
Inga Stotland
9c64e35282 mesh: Clean up style
This cleans up some stylistic issues. Plus, don't check the return
value of l_new(): if memory allocation fails, the execution stops.
2019-06-06 12:12:56 -07:00
Inga Stotland
0f5cf35948 mesh: Make "elements" mandatory in node configuration
This patch modifies the behavior of node configuration parsing:
if "elements" property is not present, th configuration file
for this node is regarded as malformed.

Also, clean up style.
2019-06-06 12:12:56 -07:00
Inga Stotland
0f8cf75f62 mesh: Do not daemonize, run in foreground or as service
This removes call to daemon(). "--nodetach" option is retained
to set umask().

Also, adds description for dbus-debug option.
2019-06-06 11:58:31 -07:00
Inga Stotland
5bcce2ce59 build: Add support for systemd bluetooth-mesh service
This adds support for installing systemd bluetooth-mesh service unit
and D-Bus service file that references this systemd unit.
2019-06-06 11:58:22 -07:00
Brian Gix
632e67f8d6 mesh: ELL encrypt dependancy README section added
Due to known AEAD encryption deficiencies in old versions of the
kernel, we have added a section on identifying and back-porting
mesh to otherwise non-supporting platforms.
2019-05-31 16:46:34 -07:00
Brian Gix
dfed483946 mesh: Convert crypto to use ELL wrappers
Use ELL implementations of aead-ccm(aes), ecb(aes) and cmac(aes). These
standard encryption and hashing routines are provided by ELL.
2019-05-31 16:46:34 -07:00
Jakub Witowski
75cd5b382e mesh: Fix long MIC usage in segmented messages
Contrary to the comment, implementation used a 8-byte MIC even if this
generated an additional segment.
2019-05-24 07:52:58 -07:00
Brian Gix
2565283cbb mesh: Implement remote dev key methods for keyring
Implements following org.bluez.mesh.Management1 methods:
ImportRemoteNode()
DeleteRemoteNode()

These methods are used to maintain Device Key keyring storage.
2019-05-24 07:52:58 -07:00
Brian Gix
4d95426caa mesh: Implement Key Refresh Phasing in keyring
Implements following org.bluez.mesh.Management1 methods:
CompleteAppKeyUpdate()
SetKeyPhase()

These methods are used to maintain Key Refresh settings
in the keyring storage.
2019-05-24 07:52:58 -07:00
Brian Gix
77950fd427 mesh: Implement App Key keyring storage handling
Implements following org.bluez.mesh.Management1 methods:
CreateAppKey()
ImportAppKey()
UpdateAppKey()
DeleteAppKey()

These methods are used to maintain App Key keyring storage.
2019-05-24 07:52:58 -07:00
Brian Gix
84610cd7cb mesh: Implement Net Key keyring storage handling
Implements following org.bluez.mesh.Management1 methods:
CreateSubnet()
ImportSubnet()
UpdateSubnet()
DeleteSubnet()

These methods are used to maintain Net Key keyring storage.
2019-05-24 07:52:58 -07:00
Brian Gix
638622af5f mesh: Centralize definition of PRIMARY_NET_IDX 2019-05-24 07:52:58 -07:00
Inga Stotland
6df5c5e379 mesh: Remove unnecessary includes from .c files 2019-05-17 13:14:40 -07:00
Inga Stotland
af3f7f1b09 mesh: Update copyright dates 2019-05-17 13:14:40 -07:00
Brian Gix
3242dd3db9 mesh: Save generated Net and Dev keys in KeyRing
When creating a network from scratch, we need to save all
keys that are created into the KeyRing for use by Config
Client application.
2019-05-15 09:36:42 -07:00
Brian Gix
8b179cbd1d mesh: Fix file open error checking and permissions 2019-05-15 09:36:42 -07:00
Inga Stotland
f66e29d566 mesh: Add skeleton for org.bluez.mesh.Management1 interface
This adds bare-bones imlementation of methods on org.bluez.mesh.Management1
interface.
2019-05-15 09:12:38 -07:00
Inga Stotland
0af87c6c6c mesh: Add check for org.bluez.mesh.Provisioner1 interface
This adds check for the presence of org.bluez.mesh.Provisioner1
interface when collecting information about mesh application
that is received in callback of GetManagedObjects() method.
Set "provisioner" flag in the node structure to trueto indicate
that the node may act aa a provisioner.
2019-05-15 09:12:38 -07:00
Brian Gix
3545edb6a4 mesh: Add key storage
This implements internal key storage add/delete/fetch for the three
basic key types managed in Mesh: Network, Application and Device.

This key storage is separate from keys assigned to nodes within the
mesh, and are used to support Configuration Client functionality.
2019-05-13 12:12:20 -07:00
Brian Gix
ce3031a6b2 mesh: Reconfigure node storage tree
Add a tree structure to a nodes data storage, in order to safely handle
Replay Protection list, Refactor local Sequence Numbers, and add Key
storage for Config Client nodes.
2019-05-13 12:12:20 -07:00
Inga Stotland
97b8bbc47e mesh: Add CreateNetwork method() implementation
This implements CreateNetwork() method on org.bluez.mesh.Network1
interface. Invoking this method generates a self-provisioned
local node associated with a brand new mesh network. This new
network is bare bones: only one network key is defined. The new node
assumes the role of mesh network manager and will be able to use
soon to be implemented methods of org.bluez.mesh.Management1 interface
to provision remote nodes into its network and to add/update/remove
network and application keys.
2019-05-10 07:39:57 -07:00
Michał Lowas-Rzechonek
64670a4a31 mesh: Use node uuids as storage directory names
Instead of keeping track of unique 16bit node identifiers, reuse their
UUIDs to create both storage directories and dbus objects.

Because of that:
 - UUID is no longer stored in the JSON file, it's inferred from the
   directory name instead
 - Join(), CreateNetwork() and ImportLocalNode() APIs return an error if
   given UUID already registered within the daemon
2019-05-08 11:31:18 -07:00
Inga Stotland
d6dce2bd37 mesh: Unify processing of GetManagedObjects result
This combines processing of results obtained from GetManagedObjects
request for both Attach() and Join() methods
2019-05-02 08:47:39 -07:00
Inga Stotland
0639e17741 mesh: Consolidate processing of mesh element properties
Consolidate functions to parse and process properties of mesh
element objects. Also, add validation of element composition
when processing Attach() method.
2019-05-02 08:47:39 -07:00
Inga Stotland
65844fe23f mesh: Clean up processing of Attach() method
This changes the prototype for the callback function of
Attach() method call: remove unused node_path argument and make the
callback more generalized and re-usable for other method calls.
2019-05-02 08:47:39 -07:00
Inga Stotland
d76a4cd489 mesh: Remove Node interface if node owner disconnects
This unregisters Node interface associated with a specific node
application when this application disconnects from D-Bus.
2019-05-02 08:47:39 -07:00
Inga Stotland
4dbe6f78c6 mesh: Fix the cleanup of failed Join call
This fixes the accidental swap of conditional checks: on failure,
remove agent info if agent is registered and remove temporary node,
if one has been created.
2019-04-22 16:44:04 -07:00
Inga Stotland
1e5e98c3b3 mesh: Fix structure memeber initialization
This fixes incorrectly reversed assignment of "friend" value in
convert_node_to_storage()
2019-04-22 16:44:04 -07:00
Inga Stotland
ecf001daa1 mesh: Allow only one app attachment per node
If a node is already attached to an application process,
disallow another appication to attach to the same node.
This means that an Attach() method called with the token
identifying a node that is already in use, returns an error
org.bluez.mesh.Error.AlreadyExists
2019-04-22 16:44:04 -07:00
Inga Stotland
0cf59dd120 mesh: Fix network information cleanup
This fixes issues caused by accessing invalidated entries of nets
queue that were left around when removing network info in
mesh_net_detach()
2019-04-19 08:33:27 -07:00
Brian Gix
4d3c4fd64d mesh: Fix decryption when on more than one Network
Multiple networks use different IV Index's, so we should only use
decryption cache after successful decoding.
2019-04-16 10:00:35 -07:00
Brian Gix
c051df3cf9 mesh: Create and store random token per node
Fix issue with device key being used as a token. Token now seperate, and
with a portable representation in the node database.
2019-04-09 09:58:22 -07:00
Brian Gix
3ad9090181 mesh: Store node state variables prior to response
Remotely set node state variables need to be saved to the file system
or other NVM prior to returning success status.
2019-03-26 08:59:30 -07:00
Brian Gix
b1adefb032 mesh: Fix json-c calling conventions
Fix issue assuming that failed calls to json_object_object_get_ex() will
always NULL the out parameter. Re-coded to always check the returned
boolean for success or failure.
2019-03-26 08:59:30 -07:00
Inga Stotland
b9b070ff30 mesh: Fix adding model app key binding
This fixes the situation when a new app key binding is being
added to a model and the list of bindings does not exist yet.
If the list does not exist, it is created and the binding is
added to it.

Also, remove unnecessary memory alloc check when model subscriptions
are added.
2019-03-22 09:34:53 -07:00
Inga Stotland
b57dd2de74 mesh: Correctly initialize node's vendor models
This fixes vendor model initialization based on node properties
collected during Join() method call.
2019-03-21 14:04:42 -07:00
Stotland, Inga
70fab12bf2 mesh: Fix bug with adding more than one app key
Fixed problem where if the appKeys array already exists, that
new add key requests were rejected.
2019-03-11 14:57:39 -07:00
Inga Stotland
076f20fe34 mesh: Store model publication settings in config file
This adds functionality to enable storing model publication
parameters in node configuration file.

Also, fix calculations of model publication period.
2019-03-11 14:50:03 -07:00
Inga Stotland
fd77b3199a mesh: Save model subscription updates to config file
This adds functionality in Config Server model to save changes in
node configuration file when model subscriptions are added, deleted or
overwritten.
2019-03-11 14:50:03 -07:00
Inga Stotland
2da78fd479 mesh: Add json config functions to save pub/sub updates
This adds functions to save updates to model subscriptions and
publication in JSON format.
2019-03-11 14:50:03 -07:00
Inga Stotland
a00dd4ea79 mesh: Set node ID for a newly provisioned node
When a new node is created after successful provisioning, a 4-digit
hex node id needs to be generated and preserved.
2019-03-11 14:50:03 -07:00
Brian Gix
f5f4267027 mesh: Enable local loopback
Implements mechanism to allow direct messaging between local
nodes without requiring an external relay node.
2019-03-11 14:50:03 -07:00
Inga Stotland
2ada1c13f6 mesh: Fix array processing in Send, Publish, Join
Use correct parameters when calling l_dbus_message_iter_get_fixed_array().
Also, check the return value and the length of the processed array and
return an error if the checks fail.
2019-03-07 12:58:09 -08:00