Commit Graph

68 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Jakub Witowski
6a889a28f1 mesh: Sequence number related fixes 2020-01-16 08:45:31 -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
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
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
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
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
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
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
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
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
Michał Lowas-Rzechonek
f370e72981 mesh: Implement properties on org.bluez.mesh.Node1 interface 2019-08-28 09:31:15 -07: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
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
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
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
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
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
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
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
Brian Gix
9e6da22ed8 mesh: Fix for file naming convention 2019-02-21 16:21:30 -08:00
Marcel Holtmann
a0fc007256 mesh: Use l_malloc instead of l_new with a cast 2019-02-16 08:23:43 +01:00
Inga Stotland
8d8066d88a mesh: Save newly added or updated net key to config file
This separates mesh_db_net_key_add() into distinct functions:
mesh_db_net_key_add() and mesh_db_net_key_update() which will be called
based on whether a network key was newly added or updated.
2019-02-12 15:30:53 -08:00
Inga Stotland
9fe6a99f08 mesh: Save key refresh phase state to node config file
This adds implementation for saving the key refresh phase to
a node configuration file in JSON format. When the key refresh
procedure is finished, the old network keys are remove from the
configuration file.
2019-02-12 15:30:53 -08:00