Aurelien Jarno [Mon, 11 Nov 2019 19:54:06 +0000 (20:54 +0100)]
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.
Change-Id: I3473d43c2ca9a7de79faa93c6d0c6953377d0f31
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Wed, 27 Nov 2019 21:39:39 +0000 (13:39 -0800)]
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).
Change-Id: Ia50bba5f000eb9bd30e5a7d54045a22d2978428a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Wed, 27 Nov 2019 21:39:38 +0000 (13:39 -0800)]
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.
Change-Id: Ib1d237e5aeef927a20343be2877a98bd3a36ed14
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Aurelien Jarno [Mon, 11 Nov 2019 20:20:09 +0000 (21:20 +0100)]
tools/mesh-cfgclient: add unbind command
This reuses the existing cmd_bind for both opcodes. cmds[] already has
code to handle it.
Change-Id: I7152d6170b73c6438caf72692564c87c08e8bcfe
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Aurelien Jarno [Mon, 11 Nov 2019 14:10:46 +0000 (15:10 +0100)]
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.
Change-Id: I29a5d4a6a8aee3c906c0f544c8b30f8a3c8e1f29
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sat, 9 Nov 2019 00:07:00 +0000 (16:07 -0800)]
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).
Change-Id: I8048b820a8e7f29e5e3d9c3001e6d19111af7733
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Aurelien Jarno [Thu, 7 Nov 2019 12:16:40 +0000 (13:16 +0100)]
tools/mesh-cfgclient: fix binaries and config name in README
This patch fixes the mesh-cfgclient README file:
- The configuration directory is meshcfg not mesh-cfgcli
- The home directory is looked up using $HOME not using /home/$USER
- The binary is called mesh-cfgclient, not mesh-config
- The -c option takes a config file path, not the directory where the
config file is stored.
Change-Id: I44b259458876d4d954346b57d43e5f77af3af018
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:29 +0000 (11:57 -0700)]
tools/mesh-cfgclient: Add README file
Change-Id: Ie3f292a17cbf2af897b079a8b08abd474ae16cab
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:28 +0000 (11:57 -0700)]
tools/mesh: add initial support for config storage
This adds support for storing the state of a mesh network.
The configuration is written out in JSON format. The initial
configuration file is generated automatically upon the
successful completion of "create" command form the main menu.
Change-Id: I2a8731d44110a83d6a620c6c6b28930fad599f38
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:27 +0000 (11:57 -0700)]
tools/mesh-cfgclient: Command line option for config
This adds "-c" option to specify full path to configuration file.
If the path is not provided, the application will attempt to open
in the following order:
1) $XDG_CONFIG_HOME/meshcfg/config_db.json
2) $HOME/meshcfg/config_db.json
if the file does not exist, it will be generated for a newly created
network, i.e., upon successful completion of "create" command.
Change-Id: Ica273fe3803a09ab8d54434dbbcb586c0620f16a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:26 +0000 (11:57 -0700)]
tools/mesh-cfgclient: Add timeout for expected response
This adds a pending request queue for the issued commands awaiting
response from a remote config server. The tool forces "single-issue"
of a config command, i.e. only one command that has a specified return
type is allowed to be outstanding per a remote node address.
That is, if AppKeyAdd command to a node is pending response, the tool
disallows sending another AppKeyAdd, AppKeyUpdate or AppKeyDelete to
the same address until response timeout expires (notification will
be displayed).
The default response timeout is set to 2 seconds and is configurable
by "timeout" command.
Change-Id: I4611df3e02faf1a5310faec16cd714f7cde5d013
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:25 +0000 (11:57 -0700)]
tools/mesh-cfgclient: Add config menu key commands
This adds implementation for config client commands to add/update
NetKeys and AppKeys on a remote node.
Change-Id: I22eec3e0bcce0e6f1a2ccc4cd32970049279b8fa
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:24 +0000 (11:57 -0700)]
tools/mesh-cfgclient: Commands for Management iface methods
This adds complete list of commenads that excercise calls to
org.bluez.mesh.Manager1 methods:
"appkey-create": CreateAppKey()
"appkey-import": ImportAppKey()
"appkey-update": UpdateAppKey()
"appkey-delete": DeleteAppKey()
"subnet-create": CreateSubnet()
"subnet-import": SubnetImport()
"subnet-update": SubnetUpdate()
"subnet-delete": SubnetDelete()
"subnet-set-phase": SetKeyPhase()
"node-import": ImportRemoteNode()
"node-delete": DeleteRemoteNode()
Change-Id: I814e21afb5e4362b5512bbb865e0c7c1181d2802
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:23 +0000 (11:57 -0700)]
tools/mesh: move remote node processing to a separate file
This confines the functionality related to remote node
housekeeping into a separate file remote.c
Change-Id: I45230ddfff9b63c4c48a622559b039df11282f2a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Anupam Roy [Tue, 17 Dec 2019 20:17:37 +0000 (01:47 +0530)]
mesh: Enable mesh-cfgclient build
Change-Id: Ie826322bfdac767c6ac4bb81a21ce71024ea1424
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:22 +0000 (11:57 -0700)]
tools: Add mesh-cfgclient tool
This adds a tool that allows to create mesh networks
opreating over advertising (PB-ADV) provisioning bearer.
The main commands are:
create - Create new mesh network with one initial node
discover-unprovisioned - Look for devices to provision
list-unprovisioned - List unprovisioned devices
provision - Initiate provisioning
list-nodes - List remote mesh nodes
Change-Id: I04a3b16038933e374e6447818952e9d7f55e7475
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:21 +0000 (11:57 -0700)]
tools/mesh: Move meshctl specific files to mesh-gatt
Change-Id: I856ab403aefe0058dc5543d8812fd37751a57e75
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 1 Nov 2019 18:57:20 +0000 (11:57 -0700)]
tools/mesh: Remove extra dependencies from agent.c
This removes dependency on glib and mesh/util.c.
Also, fixes few style glitches.
Change-Id: I74b63e7b293a34ed35e210cbc0e5dd2170b138a7
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Wed, 30 Oct 2019 06:27:49 +0000 (23:27 -0700)]
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.
Change-Id: Ibf46b6e27df02ce2a62a84f2f68c4e7639a0889f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Anupam Roy [Tue, 17 Dec 2019 19:05:15 +0000 (00:35 +0530)]
mesh: Add ELL source and headers
Change-Id: I6600cf2244463c1e8371574ddeabaccb8bb9b3ef
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Marcel Holtmann [Thu, 31 Oct 2019 06:33:48 +0000 (07:33 +0100)]
mesh: Adjust for changed l_dbus_object_manager_enable parameters
Change-Id: I4921c56e642c16e2c1ef3f6a60ab8238e262419a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Anupam Roy [Tue, 17 Dec 2019 18:05:20 +0000 (23:35 +0530)]
mesh: Add ELL changes
This patch refers following upstream patch from
ELL project.
=======================================================
commit
2088ddd7437f4ae544917f7634967746b36c3c5d
Author: Denis Kenzior <denkenz@gmail.com>
Date: Mon Oct 28 13:25:05 2019 -0500
dbus: Add ability to put ObjectManager on any path
========================================================
Change-Id: Ieacea5c8e1f898d9bc123c582feb9f09f9b36bf6
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 20 Oct 2019 21:29:49 +0000 (14:29 -0700)]
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
Change-Id: Iaefe05c061f6c62d9fdc9835457e3ff75d84de1a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 17 Oct 2019 21:55:00 +0000 (14:55 -0700)]
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)
Change-Id: I31ebf4f126f02f7b16e10c718214e21abd9523af
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Mon, 14 Oct 2019 21:47:58 +0000 (14:47 -0700)]
mesh: Add provisioner confirmation
This adds codes to send a confirmationfrom provisioner's side
after receiving a callback from a provisioning agent.
Change-Id: Ibb0293d9736e8cb2b735cacce89d389831415bbd
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Luiz Augusto von Dentz [Wed, 16 Oct 2019 08:57:23 +0000 (11:57 +0300)]
unit: Make mesh tests conditional
Mesh code can be disabled with use of --disable-mesh.
Change-Id: Ie268fab60a5199d730561c95ba9fd9e2d87280b3
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 10 Oct 2019 22:58:52 +0000 (15:58 -0700)]
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.
Change-Id: Ia447518da6800f42b2c316406a4d48879a05a4de
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Fri, 11 Oct 2019 17:31:29 +0000 (10:31 -0700)]
unit: Fix valgrind errors in test-mesh-crypto
Two HEAP errors, and one error caused by missing checksum data.
Change-Id: I383a43b5f7669b8e7efb3dd0c7bd1142f916c46a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Tue, 12 Nov 2019 14:54:25 +0000 (15:54 +0100)]
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));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Change-Id: I0fb908ee59ae2db2dcd682c342dd94107419ab89
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 3 Oct 2019 20:44:05 +0000 (13:44 -0700)]
unit: Add Mesh Crypto tests from Mesh Profile Spec
This unit test will be grown over time to include tests formed from the
sample data in the Bluetooth Mesh Profile specification (Currently at
version v1.0.1).
Currently it includes test cases for the following sets of sample data:
Sections 8.1.1-6
Sections 8.2.1-6
Sections 8.3.1-11
Section 8.4.3
Section 8.6.2
Change-Id: I70b90d83e997b2c711433a2a131a4cc6ef3bca3f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Tue, 1 Oct 2019 18:51:08 +0000 (11:51 -0700)]
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.
Change-Id: Ib564cf87d4f09f0713b40a37bf91bff2219a30d1
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 3 Oct 2019 20:07:47 +0000 (13:07 -0700)]
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.
Change-Id: I0eb810553d8947a9cbeaf4469104ba69f31579e8
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 3 Oct 2019 20:07:46 +0000 (13:07 -0700)]
mesh: Normalize Access Key AID and Index naming in models
After
8f0839a1c46300ceb1b129d17a3bff446ff79d08, mesh/crypto uses _aid
suffix for keys' AID property, so let's change the wording in mesh/model
as well.
Change-Id: Ia4cb39f7b0b4cabb62ef097288ef7d6734476c8b
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 3 Oct 2019 20:07:45 +0000 (13:07 -0700)]
mesh: Remove unused defines
Change-Id: Ide8c43fde71bd649a8624b2139860e98bc26d91f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 26 Sep 2019 18:14:44 +0000 (11:14 -0700)]
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).
Change-Id: Ida5adbedbb6757a36a7f0b8c803fe66e4c7d4cf0
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 26 Sep 2019 18:14:43 +0000 (11:14 -0700)]
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.
Change-Id: I9c26c6b18f2ea419af568b4402acf8156a561dd2
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 26 Sep 2019 18:14:42 +0000 (11:14 -0700)]
mesh: Add remote boolean to DevKey transactions
DevKey operations require authorization on the part of the applications
making the requests. Messages to state changing Servers should use
device keys from the remote (destination) to demonstrate authorization.
Change-Id: Ie586b3aa33386e170ef9f3d638fe664179aeadf3
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Tue, 1 Oct 2019 16:27:28 +0000 (09:27 -0700)]
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.
Change-Id: I032e0b52da2073a1823e743ffd2c5404bfeda722
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Fri, 6 Sep 2019 16:24:34 +0000 (09:24 -0700)]
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.
Change-Id: Id08b48eca43f0f46f72ab1397e2444d74e7d97ae
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sat, 7 Sep 2019 06:07:59 +0000 (23:07 -0700)]
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.
Change-Id: Ibdc2df9d180b902ce4089d2fd16f2f5d0dfbabb0
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Fri, 30 Aug 2019 19:15:27 +0000 (12:15 -0700)]
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).
Change-Id: Id54fe45cf7c1c3c1ce52a91d8f515dbd2e868a09
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 29 Aug 2019 20:22:45 +0000 (13:22 -0700)]
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.
Change-Id: Ic945073e2076cb7ad19ee8b5923abeae5e00b9aa
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Tue, 20 Aug 2019 07:58:52 +0000 (09:58 +0200)]
mesh: Show error message when io initialization fails
Change-Id: I589800ccb7c4f5028ff3c57a6b6b8caab33a1180
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Wed, 28 Aug 2019 07:52:30 +0000 (09:52 +0200)]
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.
Change-Id: Icb20348a445bb4ea450292f6605a4a29ebadd574
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Wed, 28 Aug 2019 07:52:29 +0000 (09:52 +0200)]
mesh: Implement properties on org.bluez.mesh.Node1 interface
Change-Id: I548b038d2f9016af0cf224e949940de768667e03
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 16 Aug 2019 07:36:27 +0000 (09:36 +0200)]
mesh: Fix handling of Config Relay Set message
Change-Id: I226b1a406802b6569fb6e0e48b4050f172e2ed67
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Mon, 12 Aug 2019 06:25:58 +0000 (23:25 -0700)]
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.
Change-Id: Ie6c8d26b72f7ff80078a9f96119f37508d1fdc72
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Rafał Gajda [Mon, 12 Aug 2019 12:06:56 +0000 (14:06 +0200)]
mesh: Remove double initialisation and fix typo in log
Change-Id: I7d9414cb5fec8754b27dbc0eaefc9296094010a9
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Rafał Gajda [Mon, 12 Aug 2019 12:08:25 +0000 (14:08 +0200)]
mesh: Fix model publication get
Change-Id: I9537a38dbaa60fab422bf06be59f03d831c9cf99
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Wed, 7 Aug 2019 09:58:31 +0000 (11:58 +0200)]
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.
Change-Id: Iee73274ff7c5578f1dd07619d0a08e63cb0751f8
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Wed, 7 Aug 2019 20:06:36 +0000 (13:06 -0700)]
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.
Change-Id: I73ba5d09493b888f12b11569bdf0d0deebbf9a28
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Mon, 5 Aug 2019 07:54:58 +0000 (09:54 +0200)]
mesh: Fix storing network retransmission in config
Change-Id: I20a87d75ccbbefecfa5030a712cd949296f9227e
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Wed, 31 Jul 2019 07:16:47 +0000 (09:16 +0200)]
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.
Change-Id: I1beaaefe1b07466130a961aac66fd373799c027d
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Wed, 31 Jul 2019 07:16:46 +0000 (09:16 +0200)]
mesh: Add documentation for Import() D-Bus API
This replaces previously specified ImportLocalNode() call
Change-Id: I1b0da2fdf68d45cef355aed9976130be55cb5c31
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Jakub Witowski [Wed, 31 Jul 2019 07:16:45 +0000 (09:16 +0200)]
mesh: Extract read_* functions in mesh-config-json
This is a small improvement of read_node function readability.
Change-Id: I9c9194b66c95462f776724fe47fcccbfa3d673c6
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 26 Jul 2019 06:36:06 +0000 (08:36 +0200)]
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.
Change-Id: I797fa781a64c7f99754e8c609aee5ccb5a20f9a9
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 26 Jul 2019 06:36:05 +0000 (08:36 +0200)]
mesh: Check that element indexes are consecutive
Change-Id: I57cbf929ce5e2af1a1ba15ce1a78b668d30382fb
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 26 Jul 2019 06:36:04 +0000 (08:36 +0200)]
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.
Change-Id: Ic918001bc152e92ba6f08274159d81b9a65b20b1
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 26 Jul 2019 06:36:03 +0000 (08:36 +0200)]
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.
Change-Id: I82c634a32a89c446937a7d58ff4f9a73da339aa3
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 26 Jul 2019 06:36:02 +0000 (08:36 +0200)]
mesh: Convert void pointers to anonymous unions in managed_obj_request
Change-Id: I245a62465bac7f093524bb041a2e034d9bdfad0a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 25 Jul 2019 18:31:45 +0000 (11:31 -0700)]
test/test-mesh: Initialize required properties
This initialized required "Models" and "VendorModels" properties
wheher the actual models exist or not, according to the mesh-api.txt.
In case when an element does not contain either SIG defined models or
vendor defineed models, the corresponding properties should contain
empty arrays.
Change-Id: Ica2e4bab99f6da827997832a29afe4f2079c0561
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 25 Jul 2019 18:26:12 +0000 (11:26 -0700)]
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.
Change-Id: I69b79713e31667210a515821635c2acfef003739
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Fri, 26 Jul 2019 02:03:10 +0000 (19:03 -0700)]
doc/mesh-api: Restore properties in mesh node hierarchy
This restores Features, Beacon, BeaconFlags, IvIndex and
SecondsSinceLAst heard properties under the
org.bluez.mesh.Node1 interface.
Change-Id: I27dd9dd8544c973825848ac089c38663585e94b1
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 19 Jul 2019 12:15:59 +0000 (14:15 +0200)]
mesh: Check address range passed to ImportRemoteNode
+changed "not authorized" error to "invalid args" when managing device
key for local address range
Change-Id: I17f83a7b0eed3321d67cb4394204d2978e4b05d8
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Tue, 16 Jul 2019 22:56:44 +0000 (15:56 -0700)]
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.
Change-Id: Ib8497b393f38e761253652364661db626801ea79
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Tue, 16 Jul 2019 22:56:43 +0000 (15:56 -0700)]
mesh: Normalize Access Key AID naming convention
Change-Id: I9e72835c2aac5864f7d35781d97790796c1e751d
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Tue, 16 Jul 2019 22:56:42 +0000 (15:56 -0700)]
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.
Change-Id: I49f973d9f2bcdd03b8558da2fa7e30b4510c2dc1
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 18 Jul 2019 03:54:18 +0000 (20:54 -0700)]
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"/>
Change-Id: I9285c0ba2580510bdfd6914e85d9dea0d7990460
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 18 Jul 2019 04:01:26 +0000 (21:01 -0700)]
mesh: Init keyring storage directory on node Attach()
This adds initialization of keyring storage directory when
a mesh node is attached successfully.
Change-Id: I50889c558595bbda544971ffb7973732905bab97
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:20 +0000 (16:23 -0700)]
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.
Change-Id: I6b63f3dd4eac6091b020f828bbe18f659351933f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:19 +0000 (16:23 -0700)]
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).
Change-Id: I7e85b5742dd44e33e7c64e87468ec78b8a7ffd00
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:18 +0000 (16:23 -0700)]
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)
Change-Id: I72124397b14d3a1fa4e8bedd9a23733ce8fd1249
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:17 +0000 (16:23 -0700)]
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.
Change-Id: Ia42ed3d2f5a49efa2665fea15384ea06389dc49d
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:16 +0000 (16:23 -0700)]
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
Change-Id: I6ecb77332911bdb6a6ae18feedb8cae40b2832ff
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:15 +0000 (16:23 -0700)]
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.
Change-Id: I9acad57fdaad8844c48e629e6de80ed0595404b3
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:14 +0000 (16:23 -0700)]
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
Change-Id: Id2af576c57b75c4d91fc34a1fa78169d421d10ad
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:13 +0000 (16:23 -0700)]
mesh: Change mesh_db prefix to mesh_config
This changes the naming the API declarations in mesh-config.h:
mesh_db_... ->mesh_config_...
Change-Id: I397ca6192d596de66c8de2cfe469758aaa4ffb4f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:12 +0000 (16:23 -0700)]
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.
Change-Id: Iffde923efc7597cdb34a86e322b9baa901a6ee02
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Sun, 14 Jul 2019 23:23:11 +0000 (16:23 -0700)]
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.
Change-Id: I7e9577f6da3e6418eacdf2e97a95250ee1cb4357
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:52 +0000 (15:59 -0700)]
test: This extends the mesh tool to exercise Provisioning methods
Note: This script is *not* a suitable tool for expanding into
a Mesh Provisioner. It is only intended to demonstrate the arguments
and methods required.
Change-Id: Ifacbf894c5e50621e5d35958a97efc7f487777ab
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:51 +0000 (15:59 -0700)]
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.
Change-Id: Ib7e0457a2d39f6c0a09b66208c98e1ecf2b7bbde
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:50 +0000 (15:59 -0700)]
mesh: Implement DBus Provisioning methods
This implements the Interface and Methods for:
UnprovisionedScan()
UnprovisionedScanCancel()
AddNode()
Change-Id: Id9b08cecbd7bcc27fe077271719d494a4d6765b4
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:49 +0000 (15:59 -0700)]
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
Change-Id: Ia5c6b90a28d39871cedbf652c9533f761670c892
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:48 +0000 (15:59 -0700)]
mesh: Expose resources needed by Management1 interface
Change-Id: I34c48666cad7fd717536582bedd44503a9b738e6
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:47 +0000 (15:59 -0700)]
mesh: Expose mapping function for D-Bus errors
Change-Id: Ifd701c0fb651108cc3d7185271f0415e38dcd10c
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:46 +0000 (15:59 -0700)]
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.
Change-Id: I008db68f0e371ca6c843a3dd27357318973ccb8e
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Thu, 11 Jul 2019 22:59:45 +0000 (15:59 -0700)]
mesh: Fix support for Provisioner Initiator
Change-Id: Ibc02f8edb7ec8da10de89b7f0b0c2e0063dee5f4
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 4 Jul 2019 17:36:06 +0000 (10:36 -0700)]
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.
Change-Id: I97d395e354ed8b21b9ec55d2eea924d7b1db9175
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 4 Jul 2019 12:33:38 +0000 (14:33 +0200)]
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.
Change-Id: I2fcf957dcf652d5c5cd5ae799344692a4f9c69cf
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 4 Jul 2019 12:33:37 +0000 (14:33 +0200)]
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.
Change-Id: I37c13c2c050b03880f23d6b8d149e998a7cff1f3
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 4 Jul 2019 12:33:36 +0000 (14:33 +0200)]
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.
Change-Id: I4cd92b881b29e24d3579e6db22f866cb0b3a2fa9
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Thu, 4 Jul 2019 12:33:35 +0000 (14:33 +0200)]
mesh: Cleanup D-Bus method returns with empty result
Change-Id: I891ea4f6d3587383152b5a29d63db098b9c024dc
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 4 Jul 2019 07:40:40 +0000 (00:40 -0700)]
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.
Change-Id: Ib34c50366b0a93456bb4f891cc750777089e4147
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Thu, 4 Jul 2019 07:15:16 +0000 (00:15 -0700)]
mesh: Remove redundant initialization
This fixes a case where a variable was initialized twice.
Change-Id: I14b10105095304d93c25d067ad435fceed79835f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał 'Khorne' Lowas-Rzechonek [Wed, 3 Jul 2019 19:08:33 +0000 (21:08 +0200)]
mesh: Fix stack overflow in get_element_properties
D-Bus type 'q' denotes uint16, not uint8.
Change-Id: Ia9c8f9bb2d6f60f46d180ae583771685593be7f5
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Wed, 3 Jul 2019 23:02:44 +0000 (16:02 -0700)]
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.
Change-Id: If11ec87748384b43dd7f6b7ef06d88439cf0323c
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Inga Stotland [Wed, 3 Jul 2019 20:53:41 +0000 (13:53 -0700)]
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.
Change-Id: I65631b3cd22c9e5f5e43aa62e093c227182749b8
Wrong: if (l_queue_isempty(mod->bindings) || !mod->cbs->bind) ...
Fixed: if (!l_queue_isempty(mod->bindings) && cbs->bind) ...
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Brian Gix [Wed, 3 Jul 2019 16:34:03 +0000 (09:34 -0700)]
mesh: Fix memory leak on dbus message creation
Change-Id: I82a29b20859c1310ff17acf8e181de822b9a4952
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Jakub Witowski [Tue, 2 Jul 2019 12:31:41 +0000 (14:31 +0200)]
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.
Change-Id: I838ecb7f4f5396d46a67fe20ca87c8944331eb82
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
Michał Lowas-Rzechonek [Fri, 28 Jun 2019 08:27:34 +0000 (10:27 +0200)]
mesh: Register D-Bus management interface
When application Attach()es itself, start exposing both Node1 and
Management1 D-Bus interfaces.
Change-Id: I2a94441cce59cee62e219ee40b07d6f3124290df
Signed-off-by: Anupam Roy <anupam.r@samsung.com>