Commit Graph

327 Commits

Author SHA1 Message Date
Inga Stotland
818a59aead mesh: Clean up handling config model publication message
This tightens up the Config Server code that handles the processing of
Config Model Publication Set and Config Model Publication Get messages.
2020-02-26 11:20:08 -08:00
Inga Stotland
754b2c387b mesh: Simplify model virtual pub/sub logic
This reorganizes the part of the code that handles model publishing
and subscribitng to virtual labels.
2020-02-26 11:20:08 -08:00
Brian Gix
6a6fe856a9 mesh: rework incoming advertisement filtering
Future versions of Mesh will introduce new advertising packets, which
do not fit in the limited and rigid filtering currently used. This minor
rewrite allows registering and receiving of *any* AD types, including
the filtering on multiple octets of the incoming AD parts.
2020-02-26 11:20:08 -08:00
Inga Stotland
17516034a6 mesh: Fix app payload decryption for virtual labels
This fixes a bug when a virtual label and its size hasn't been passed
to a decryption function: instead of always using NULL pointer for
label and 0 for lable size, use actual virtual label info if decrypting
a payload addressed to a virtual destination.
2020-02-18 15:55:30 -08:00
Inga Stotland
8e100bb8be mesh: Fix keyring app keys directory iteration
This fixes how app key files are accessed when finalizing
Key Refresh procedure. Instead of using open(entry->d_name, ...)
to get file descriptor, use openat(dir_fd, entry->d_name, ...)
since entry->d_name contains a relative app key filename, not an
absolute path.
2020-02-07 09:22:47 -08:00
Inga Stotland
fb811a090b mesh: Allow to finish key refresh when no AppKeys are stored
This handles a case when a Key Refresh procedure is in place with
no application keys stored in the keyring. When KR procedure is
finalized, the check for the presence of AppKeys storage directory
does not return failure if the directory does not exist.

Also, remove duplicate include.
2020-02-07 09:19:14 -08:00
Jakub Witowski
2f9ec7f887 mesh: remove unused node_set_device_key()
This patch removes node_set_device_key() function,
because it is unused.
2020-01-31 10:22:16 -08:00
Jakub Witowski
845541f052 mesh: use static node_comp instead of the pointer
There is no need to use the pointer to the node_comp data.
This pach uses static node_comp instead.
2020-01-31 10:22:16 -08:00
Brian Gix
da429de905 mesh: Re-arrange replay protection check and add
Re-arranged for efficiency. Replay Protection was set up as an atomic
check-and-add operation. Now we check the message early so we can
discard it without taking further action, and only add it to the RPL
once fully verified that it was authorized and addressed to us.
2020-01-31 10:15:08 -08:00
Brian Gix
8457e6a3ad mesh: Add NVM storage of Replay Protection
Mesh specification requires that Replay Protection be preserved
across node restarts.  This adds that storage in
<node_uuid>/rpl/<iv_index>/<src>

Realtime access remains in an l_queue structure, and stored as
messages are processed.
2020-01-30 11:03:47 -08:00
Brian Gix
17e97efc3f mesh: Apply Replay Protection to all incoming packets
Replay Protection was only being applied against Application Keys,
but messages with Device Keys are just as vulnerable, and need to be
checked as well.
2020-01-30 11:03:47 -08:00
Brian Gix
162bda4899 mesh: Clean-up unneeded Sequence Number increments
Scrub of Sequence Number handling of OB messages to account for in-node
delivery of segmented messages, so that each discrete message has a
unique sequence number for the RPL.
2020-01-30 11:03:47 -08:00
Brian Gix
243a46b6ca mesh: Move Replay Protection to mesh/net.c
The specification calls for a flatter Replay Protection List that
applies to all processed messages, regardless of which credentials
were used to secure them. So storage and checking is now centralized
in mesh/net.c
2020-01-30 11:03:47 -08:00
Brian Gix
525d1ec340 mesh: Relocate tree deletion to util.c/h 2020-01-30 11:03:47 -08:00
Prathyusha N
87137b1d1a mesh: Handle publickey exchange phase for initiator
In Public Key OOB case, when provisioner receives public key via
OOB, provisioner has to send it's public key to remote node and
and then proceed for authentication.

Handle invalid keys case.
2020-01-25 08:25:37 -08:00
Shaunak Soman
b8af883daf mesh: Fix provisioning agent method call failure
Provisioning agent interface methods PublicKey, PrivateKey and
Cancel do not accept any parameters. So, while invoking them
explicitly set the parameters to "".
2020-01-23 07:38:23 -08:00
Brian Gix
c0b61227ac mesh: Offload loopback packets to l_idle_onshot()
Any packet that may be handled internally by the daemon must be sent in
it's own idle_oneshot context, to prevent multiple nodes from handling
and responding in the same context, eventually corrupting memory.

This addresses the following crash:
Program terminated with signal SIGSEGV, Segmentation fault.
 0  tcache_get (tc_idx=0) at malloc.c:2951
     2951   tcache->entries[tc_idx] = e->next;
(gdb) bt
 0  tcache_get (tc_idx=0) at malloc.c:2951
 1  __GI___libc_malloc (bytes=bytes@entry=16) at malloc.c:3058
 2  0x0000564cff9bc1de in l_malloc (size=size@entry=16) at ell/util.c:62
 3  0x0000564cff9bd46b in l_queue_push_tail (queue=0x564d000c9710, data=data@entry=0x564d000d0d60) at ell/queue.c:136
 4  0x0000564cff9beabd in idle_add (callback=callback@entry=0x564cff9be4e0 <oneshot_callback>, user_data=user_data@entry=0x564d000d4700,
    flags=flags@entry=268435456, destroy=destroy@entry=0x564cff9be4c0 <idle_destroy>) at ell/main.c:292
 5  0x0000564cff9be5f7 in l_idle_oneshot (callback=callback@entry=0x564cff998bc0 <tx_worker>, user_data=user_data@entry=0x564d000d83f0,
    destroy=destroy@entry=0x0) at ell/idle.c:144
 6  0x0000564cff998326 in send_tx (io=<optimized out>, info=0x7ffd035503f4, data=<optimized out>, len=<optimized out>)
    at mesh/mesh-io-generic.c:637
 7  0x0000564cff99675a in send_network_beacon (key=0x564d000cfee0) at mesh/net-keys.c:355
 8  snb_timeout (timeout=0x564d000dd730, user_data=0x564d000cfee0) at mesh/net-keys.c:364
 9  0x0000564cff9bdca2 in timeout_callback (fd=<optimized out>, events=<optimized out>, user_data=0x564d000dd730) at ell/timeout.c:81
 10 timeout_callback (fd=<optimized out>, events=<optimized out>, user_data=0x564d000dd730) at ell/timeout.c:70
 11 0x0000564cff9bedcd in l_main_iterate (timeout=<optimized out>) at ell/main.c:473
 12 0x0000564cff9bee7c in l_main_run () at ell/main.c:520
 13 l_main_run () at ell/main.c:502
 14 0x0000564cff9bf08c in l_main_run_with_signal (callback=<optimized out>, user_data=0x0) at ell/main.c:642
 15 0x0000564cff994b64 in main (argc=<optimized out>, argv=0x7ffd03550668) at mesh/main.c:268
2020-01-17 23:06:57 -08:00
Inga Stotland
7af962a04a mesh: Fix opcode for OP_VEND_MODEL_APP_GET
This changes the value of OP_VEND_MODEL_APP_GET to 0x804D (it was
incorrectly set to 0x804C)
2020-01-17 23:06:57 -08:00
Jakub Witowski
6a889a28f1 mesh: Sequence number related fixes 2020-01-16 08:45:31 -08:00
Michał Lowas-Rzechonek
b31eee8907 mesh: Rename --index to --io, support additional io types.
This allows specifying io type and options when invoking the daemon.

When no "-i" is passed, meshd still runs with MESH_IO_TYPE_GENERIC and
tries to attach to the first available HCI interface.

Options "-i <n>" and "-i hci<n>" are just shortcuts for
"--io=generic:<n>" and "--io=generic:hci<n>", respectively.
2020-01-16 08:45:31 -08:00
Jakub Witowski
c281c3cd90 mesh: Add sequence nr getter code 2020-01-14 10:55:54 -08:00
Inga Stotland
6fe78e8746 mesh: Correctly generate NetKey list
When responding with NetKey List Status, packed NetKey indices into
3 octets per pair. If number of NetKeys is odd, append the last key
index as a 2-octet value.
2020-01-14 06:32:23 -08:00
Michał Lowas-Rzechonek
559410f33a mesh: Fix exiting IV_UPD_STATE when receiving first SNB
First valid SNB received from the network should cause the node to
switch into IV_UPD_NORMAL state.

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

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

Also, simplify the node_app_key_delete() argument list.
2020-01-14 06:32:23 -08:00
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