Commit Graph

364 Commits

Author SHA1 Message Date
Brian Gix
0e8ed1f261 mesh: Fix double-free
This fixes a double-free error when destroying the NVM storage of a mesh node.
Cleanly handle two distinct scenarios:

1. When the node is being deleted at runtime.  This causes release of
   both dynamic memory and NVM storage.

2. During shutdown, we release dynamic memory only.
2020-05-20 15:16:55 -07:00
Inga Stotland
2cd067b8b7 mesh: Fix segfault caused by re-enabling of HCI controller
This fixes the crash that occurs when a controller used by bluetooth-meshd
is removed and then added back again.

Also, correctly restart scanning when the controller is re-enabled.

Backtrace:
0x00005618e754d040 in ?? ()
0x00005618e6e12d9a in io_ready_callback () at mesh/mesh.c:174
0x00005618e6e3d2c8 in l_queue_foreach () at ell/queue.c:441
0x00005618e6e37927 in request_complete () at src/shared/mgmt.c:261
2020-05-17 08:12:20 -07:00
Brian Gix
d18cb97bb5 mesh: Fix valgrind memory leak warnings
These warnings are caused by not completely freeing memory allocations
at shutdown, and are not serious, but they make valgrind output cleaner.
2020-05-15 18:25:30 -07:00
Brian Gix
cc0719ceae mesh: Fix valgrind memory leaks
These memory leaks are ones that will compound over time with node
creation and deletion.
2020-05-15 18:24:18 -07:00
Inga Stotland
a51871bd73 mesh: Remove redundant call to save node configuration
This removes a redundant call to save node configuration in
add_local_node(): there is a number of unconditional calls to
mesh_config_write_<some_node_Setting>() within this function
which would result in the node configuration being saved implicitly.
2020-05-14 09:12:56 -07:00
Inga Stotland
8a38226212 mesh: Allow updating CID, PID, VID & CRPL on node attach
This allows to update settings of the following composition fields
when an existing node (application) attaches to the daemon:
Company ID (CID), Product ID (PID), Versioin ID (VID),
CRPL (replay protection depth)
2020-05-14 09:12:56 -07:00
Inga Stotland
b91f6f0be3 mesh: Avoid saving duplicate fields in node config
This modifies miscellaneous utility functions in mesh-config-json.c:
when writing a new value to a node configuration file, delete
the existing field containing an old value first.
2020-05-14 09:12:56 -07:00
Inga Stotland
82b2d4cf5e mesh: On node attach, verify element/model composition only
When attaching an existing node, verify only the "elements" part
of device composition, i.e., skip verification of CID/PID/VID, CRPL
and features.
2020-05-09 06:45:28 -07:00
Inga Stotland
48cef391a4 mesh: Fix publication setup for vendor models
This fixes model ID generation when processing Config Pub Set
message. Also, cleanup some debug prints.
2020-04-30 10:09:05 -07:00
Inga Stotland
cbad3121d5 mesh: Fix adding virtual subscription to a vendor model
This fixes a case when a configuration server receives a virtual
subscription add/overwrite command targeting a vendor model.
Correctly set "vendor" argument before trying to save the updated
subscrition to configuration file.
2020-04-30 10:09:05 -07:00
Brian Gix
ef0970a723 mesh: Fix GCC 10.0 warnings 2020-04-18 08:21:03 -07:00
Brian Gix
8a73c868b7 mesh: Add Time-outs to critical dbus send-with-replies
JoinComplete() dbus method calls are the only time that node tokens are
delivered to client Applications, so if the call fails for any reason
(including time-outs) the daemon has a way to clean-up the stale unused
node data.
2020-04-14 08:45:47 -07:00
Przemysław Fierek
a4ead01159 mesh: Change API to deliver tokens via JoinComplete
This patch changes Import and CreateNetwork API to deliver tokens via
the JoinComplete method call.  When application doesn't raise any error
during handling JoinComplete then it is assumed that the token has been
saved, otherwise when application replies with an error message then the
node is removed.
2020-04-14 08:45:47 -07:00
Przemysław Fierek
d5cc4ffd55 mesh: Fix invalid app_path on 'Join'
This patch fixes invalid app_path on 'Join' method call - the daemon
tried to use the value of app_root API argument, while it should use
path discovered by scanning result of GetManagedObjects() call.
2020-04-10 06:06:30 -07:00
Rafał Gajda
60423fed39 mesh: Ignore beacons with IVU if IV already updated
When daemon receives beacon with IV=n+1, IVU=False it will
start sending messages with new IV and set sequence to 0.
However if daemon receives another beacon with IV=n+1, IVU=True it
will go back to sending messages with old IV=n (IVU set to True).
Because sequence number has been reset those messages will be dropped
by replay protection and node will lose communication.

Once IV is updated daemon should not go back to using the old value.

This patch adds beacon rejection if IV has already been updated.
2020-04-08 10:08:31 -07:00
Michał Lowas-Rzechonek
59aae8b1cc mesh: Remove redundant code from mesh/crypto
- Remove application_encrypt/application_decrypt
- Make mesh_crypto_privacy_counter private, add mesh_crypto_pecb
- Make *_nonce functions private and align their implementation to be
  more consistent
- Refactor network_encrypt/network_decrypt to use *_nonce functions and
  rename them to packet_encrypt/packet_decrypt
- Refactor packet_encode/packet_decode
2020-04-07 09:52:44 -07:00
Inga Stotland
55d06e0cd5 mesh: Fix segfault related to idle config write
If node configuration is completely removed from the system,
remove all pending writes to the configuration file.

Fixes the segfault below:

mesh/cfgmod-server.c:node_reset() Node Reset
mesh/mesh-config-json.c:mesh_config_destroy() Delete node config /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c
mesh/util.c:del_fobject() RM /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/rpl/00000000/0001
mesh/util.c:del_fobject() RMDIR /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/rpl/00000000
mesh/util.c:del_fobject() RMDIR /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/rpl
mesh/util.c:del_fobject() RM /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/node.json.bak
mesh/util.c:del_fobject() RM /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c/node.json
mesh/util.c:del_fobject() RMDIR /var/lib/bluetooth/mesh/02040d0a060e0a08090b0103070f050c
Segmentation fault

Program terminated with signal SIGSEGV, Segmentation fault.

  0x0000563a35df2ed0 in ?? ()
  0x00007fd6b131689f in json_object_to_json_string_length (jso=jso@entry=0x563a35dd8d30, flags=flags@entry=2,
2020-04-01 18:27:14 -07:00
Inga Stotland
4e42f2edde mesh: Move SEQ_MASK define in mesh-defs.h 2020-04-01 18:27:14 -07:00
Brian Gix
3eaf2f114d mesh: Clear prov capabilities structure before reading
Capabilities need to be zero'd before realtime reading fresh values,
because they are mostly bitmasks, which are set when capabilities are
detected, and never otherwise cleared.
2020-04-01 12:06:15 -07:00
Michał Lowas-Rzechonek
1695ec1e0c mesh: Honor provisioner's capabilities
This patch makes the daemon select authentication method based from
capabilities supported by both provisioned node and provisioner
application.
2020-04-01 12:06:14 -07:00
Michał Lowas-Rzechonek
f333ce2d95 mesh: Refresh provisioner's capabilities
As provisioner's capabilities might change during application lifetime
(e.g. no network link to download OOB key), let's query the agent again
after application calls AddNode().
2020-04-01 12:06:14 -07:00
Michał Lowas-Rzechonek
037d452415 mesh: Clean up naming of provisioning callbacks 2020-04-01 12:06:14 -07:00
Michał Lowas-Rzechonek
4b2d782fb6 mesh: Remove unused 'server' argument 2020-04-01 12:06:14 -07:00
Przemysław Fierek
84a9b6ce4b mesh: Add net key index to sar structure
This patch adds net key index to struct mesh_sar. This fixes problem with
using invalid network key to encrypt application messages.
2020-03-31 16:27:56 -07:00
Przemysław Fierek
c55b358d01 mesh: Remove unused functions: 'mesh_net_sub_list_add' and 'mesh_net_sub_list_del' 2020-03-31 10:20:04 -07:00
Przemysław Fierek
1813d813c9 mesh: Remove unused argument from 'mesh_net_transport_send' function 2020-03-31 10:18:57 -07:00
Inga Stotland
4100dede01 mesh: Update UnprovisionedScan, AddNode & ScanResult
The following methods are modified to allow for future development:

Interface org.bluez.mesh.Management1:

Old: void UnprovisionedScan(uint16 seconds)
New: void UnprovisionedScan(dict options)

    The options parameter is a dictionary with the following keys defined:
    uint16 Seconds
                Specifies number of seconds for scanning to be active.
                If set to 0 or if this key is not present, then the
                scanning will continue until UnprovisionedScanCancel()
                or AddNode() methods are called.
    other keys TBD

Old: void AddNode(array{byte}[16] uuid)
New: void AddNode(array{byte}[16] uuid, dict options)

    The options parameter is currently an empty dictionary

Interface org.bluez.mesh.Provisioner1

Old: void ScanResult(int16 rssi, array{byte} data)
New: void ScanResult(int16 rssi, array{byte} data, dict options)

    The options parameter is currently an empty dictionary
2020-03-30 15:03:56 -07:00
Michał Lowas-Rzechonek
5379e024fc mesh: Fix model publication status after set
This patch fixes usage of send_pub_status() when handling publication
set message - mod_id was swapped with pub_addr, resulting in malformed
message being sent back to the Config Client.
2020-03-26 10:00:33 -07:00
Prathyusha N
424f88e7b8 mesh: Handle close for Acceptor
Provision complete callback is handled in provision failure case.
If link closed received abruptly with reason success, triggered
provision complete callback. Removed session timeout and session
free as they are handled in pb_adv_unreg.
2020-03-25 10:31:14 -07:00
Brian Gix
936122a230 mesh: Whitespace correction 2020-03-25 09:55:49 -07:00
Prathyusha N
ac940a70ce mesh: Send input complete for input OOB Authentication
Send input complete when user completes input operation.
2020-03-25 09:50:05 -07:00
Prathyusha N
8ef71fca7f mesh: Handle invalid public keys
Check for invalid public keys received and send provision failed.
2020-03-25 09:43:50 -07:00
Prathyusha N
9b4d8f1dc1 mesh: Handle netkey delete when netkey is not in netkeylist
4.4.1.2.9 of Mesh Profile Bluetooth specification:
When an element receives a Config NetKey Delete message that
identifies a NetKey that is not in the NetKey List, it
responds with Success, because the result of deleting the
key that does not exist in the NetKey List will be the same
as if the key was deleted from the NetKey List.
2020-03-25 09:42:30 -07:00
Brian Gix
97e24f9182 mesh: Fix Replay Protection Cache
There was a bug identified in the RPL storage, such that the real-time
queue was being filled by incorrect unicast addresses. (Thx ccsanden).
2020-03-23 14:37:04 -07:00
Brian Gix
e8c870c63b mesh: Allow short messages to be segmented
For added reliability, it is legal to send short messages as "single
segment" segmented messages, which require transport layer
acknowledgement. This feature is intended for heavy usage in the future
so I am adding it now.

Further, to support this functionality, an additional queue has been
added to allow multiple SAR messages to the same DST to be queued and
sent serially.
2020-03-20 11:51:18 -07:00
Inga Stotland
5885eab5bd mesh: Fix processing of Config Node Reset message
This fixes a condition when a node continues processing messages
after it has been reset by a remote configuration client.
Upon receiving Config Node Reset message, node removal happens after
a grace interval to allow sending of Config Node Reset Status reply.
2020-03-18 09:20:28 -07:00
Inga Stotland
ff41bce83d mesh: Remove unused parameters from internal rx functions
This removes unused ttl parameter from mesh_model_rx(). The TTL value
is not processed at the access layer, so there is no need to pass it
to a model.
Also, remove "uint32_t dst" parameter from the typedef of
mesh_model_recv_cb: providing a just destination address is sufficient
for internally implemented models (currently, it's only Config Server)
2020-03-05 08:01:28 -08:00
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