Commit Graph

384 Commits

Author SHA1 Message Date
Michał Lowas-Rzechonek
d565cc8dda mesh: Fix FPE in overcommit logic.
During overcommit, mesh_config_save is called in asynchronous mode to
avoid blocking Send() calls. This means that update of cfg->write_time
is scheduled via l_idle_oneshot, so if the next Send() gets scheduled
first, the code may see elapsed time of zero.

If this happens, then the overcommit logic was already executed and the
overcommit is pending, so we can just return.
2020-06-02 09:08:33 -07:00
Inga Stotland
ad37211780 mesh: Remove unused functions from net.c
The folllowing functionsa are not being used anywhere in the code and
have been removed:
mesh_net_flush()
mesh_net_prov_caps_get()
mesh_net_priv_key_get()
mesh_net_priv_key_set()
mesh_net_prov_rand()
mesh_net_prov_uni()
mesh_net_id_uuid_set()
mesh_net_test_addr()
mesh_net_test_mode()
mesh_net_uni_range_set()
mesh_net_uni_range_get()
mesh_net_set_window_accuracy()
2020-06-01 10:23:11 -07:00
Inga Stotland
962a759e9d mesh: Clean up style in net.c 2020-06-01 10:23:11 -07:00
Inga Stotland
c0013ccdb1 mesh: Remove debug-only related callback for packet send
This removes callback for sending every single access layer packet
since the callback does nothing but print debug satement. This
functionality is mature enough not to require such heavy debugging.
2020-06-01 10:23:10 -07:00
Inga Stotland
cb3088b598 mesh: Debug output clean up
This changes l_info() to l_debug() for recurring cases and
removes some excessive debug output.
2020-06-01 10:23:10 -07:00
Inga Stotland
c0509b127a mesh: Helper packet print should depend on debug setting
This changes the utility function print_packet() to check if
daemon is running in debug mode.
2020-06-01 10:23:10 -07:00
Brian Gix
ba4289c72e mesh: Destroy PB-ADV queue when provisioning done 2020-05-22 14:07:52 -07:00
Brian Gix
c80f88bdff mesh: Fix leaked message reference 2020-05-22 13:54:39 -07:00
Brian Gix
9084172128 mesh: Fix leaked mesh_net allocation 2020-05-22 13:54:39 -07:00
Brian Gix
29d737730a mesh: Fix using uninitialized bytes
Fixes two problems found with static analysis
2020-05-22 13:54:39 -07:00
Inga Stotland
ebed46f05e mesh: Clean up Join() method
This consolidates various places where a pending response
to Join() is created and makes sure that l_dus_message_unref()
is called correctly.
2020-05-22 13:45:53 -07:00
Inga Stotland
9dd9cba0a2 mesh: Fix memory leak in Create, Import & Attach methods
This ensures that every time l_dbus_message_ref() is used to preserve
a message for a pending method reply, there is a matching call to
l_dbus_message_unref().
2020-05-22 13:45:53 -07:00
Inga Stotland
7a5007178f mesh: Clean up Attach() method call
This consolidates error return form one place: off a callback
with unsuccessful status.
2020-05-22 13:45:53 -07:00
Inga Stotland
1b7d879555 mesh: Clean up Import() method call
This removes unnecessary failing conditions in Import() call and
simplifies iterations through "flags" dictionary.
2020-05-22 13:45:53 -07:00
Inga Stotland
dedc3cb274 mesh: Create a queue of pending requests in mesh_init()
This removes unnnecessary checking for queue existence every time
either Attach(), Create() or Import() methods are called.
2020-05-22 13:45:53 -07:00
Inga Stotland
b0adb615ca mesh: Remove unused function prototypes from node.h 2020-05-22 13:45:53 -07:00
Inga Stotland
7cdc215ff5 mesh: Add finalization of a newly created node
When a new node is created as a result of successful completion
of either Join() or Create() or Import() methods and has been
confirmed via successful token delivery to the application,
clean up node's D-Bus resources (application path, element paths, etc)
that have been gathered during the initial GetMAnagedObjects() call.
Also, remove the agent instance associaed with the new node.

These resources will be re-populated after the Attach() call
verifies the node's integrity.
2020-05-22 13:45:52 -07:00
Inga Stotland
7eca3becce mesh: Remove agent when freeing node's dynamic resources
This adds clean up of node's agent instance when node's dynamic
resources are freed.
2020-05-22 13:45:52 -07:00
Inga Stotland
f5fcab3276 mesh: Free allocated agent in mesh_remove_agent()
This adds previously missing call to free memory allocated
for agent structure.
2020-05-22 13:45:52 -07:00
Inga Stotland
8afaf5e958 mesh: Remove unused structure member
This removes unused "agent" member from join_data structure.
2020-05-22 13:45:52 -07:00
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