summaryrefslogtreecommitdiff
path: root/mesh/net.c
Commit message (Collapse)AuthorAgeFilesLines
* mesh: Switch beaconing net keyBrian Gix2023-01-301-0/+16
| | | | | | When transitioning from Phase 1 to Phase 2 of a network key and we are beaconing, we need to halt the beaconing on the old key version, and begin beaconing on the new key version.
* mesh: Add Tx/Rx support of Mesh Private BeaconsBrian Gix2023-01-301-52/+120
| | | | | | | With this change, we start evaluating received Mesh Private Beacons in addition to the legacy Secure Network Beacons. We also add the ability to request Tx of Mesh Private Beacons, which are regenerated with new Random Nonce a minimum of every 0 - 2550 seconds.
* mesh: Keep cancelled SAR data for at least 10 secIsak Westin2022-10-121-5/+26
| | | | | | | When a SAR transmission has been completed or cancelled, the recipent should store the block authentication values for at least 10 seconds and ignore new segments with the same values during this period. See MshPRFv1.0.1 section 3.5.3.4.
* mesh: Fix msg cache ring bufferIsak Westin2022-10-071-2/+1
| | | | | The message cache should be a strict ring buffer, suppressed message should not move to the front of the queue.
* mesh: Always relay messages from Low Power nodesIsak Westin2022-10-061-11/+36
| | | | | | | If we receive a message from one of our Low Power nodes, which is encrypted using frendship credentials and where the destination is not us, we must relay that message using master credentials. See MshPRFv1.0.1 section 3.6.6.2.
* mesh: Queue a friend update on IV Update changeIsak Westin2022-10-061-0/+1
| | | | | A friend update should be queued when we receive a Secure Network beacon that changes the IV Update state.
* mesh: Verify padding bits in Friend Poll messagesIsak Westin2022-10-061-1/+1
| | | | | The padding bits in a Friend Poll message must be zero. See MshPRFv1.0.1 section 3.6.5.1.
* mesh: Allow Key refresh to skip Phase 2Isak Westin2022-10-031-2/+3
| | | | | | If we are in Key Refresh Phase 1, and receive a Secure Network beacon using the new NetKey and with KR flag set to 0, Phase 2 should be skipped. See MshPRFv1.0.1 section 3.10.4.1.
* mesh: Ignore SNB with invalid IV Index valuesIsak Westin2022-10-031-0/+4
| | | | | | If we are in IV update in progress state, and receive a Secure Network beacon with an IV index equal to last known IV index + 1, and IV update flag set to 1, it should be ignored. See MshPRFv1.0.1 section 3.10.5.
* mesh: Ignore Secure Network Beacon from subnetIsak Westin2022-10-031-1/+12
| | | | | | | If this node is a member of a primary subnet and receives a Secure Network beacon on a secondary subnet with an IV Index greater than the last known IV Index of the primary subnet, the Secure Network beacon shall be ignored. See MshPRFv1.0.1 section 3.10.5.
* mesh: Correct HB sub state updatesIsak Westin2022-09-261-16/+4
| | | | | | | | | If heartbeat subscription is disabled, all fields should be set to zero but collected data should be preserved. If HB subscription is enabled, the collected data should be reset (which includes Min Hops = 0x7f). HB subscription is disabled by setting any of the following fields to zero: Source, destination or period log. HB subscription is enabled by setting all the same fields to valid values.
* mesh: Add interface output filterIsak Westin2022-09-221-0/+28
| | | | | According to the mesh profile (3.4.5.2), if TTL is set to 1 for an outgoing message, that message shall be dropped.
* mesh: Use correct net_id for received CTL messagesIsak Westin2022-06-301-2/+2
| | | | | | | | For received CTL mesh messages, the wrong network ID variable was passed to ctl_received. This patch changes to the correct variable. Also, changed type of net_key_id argument in ctl_received function to be consistent wich the whole call chain.
* mesh: use explicit uint32_t when bit shifting leftInga Stotland2022-03-311-6/+6
| | | | | | | | | This addresses a situation when a boolean type is represented by an integer and performing a left shift on a boolean causes an integer overflow. This fixes the following runtime error: "left shift of 1 by 31 places cannot be represented in type 'int'"
* mesh: Make key_aid and net_key_id naming consistentMichał Lowas-Rzechonek2022-02-041-55/+56
| | | | | | | | - key_aid refers to application key AID - net_key_id refers to unique, internal id of the network key, used in net-keys.h Also, remove unused mesh_frnd_pkt struct.
* mesh: Fix sequence number of message in friend queueBrian Gix2022-02-041-1/+0
| | | | | | | As pointed out by https://github.com/bluez/bluez/issues/250, the last segment of a multi-segmented message added to Friend Queue was getting reset to the seqAuth value incorrectly. The correct sequence was set within the preceding for loop.
* mesh: Fix segmented msg RX with friendshipBrian Gix2021-03-251-0/+1
| | | | | | This fixes an uninitialized memory issue where a message received for a local node is silently discarded if an uninitialized boolean is mistakenly set to TRUE, when friendships exist.
* mesh: Fix infinite loop on IVIndex updatePrzemysław Fierek2021-03-011-13/+21
| | | | | | | | | | | | | | | | | | | | This patch fixes inifinite loop problem caused by recurring call of the `net_key_beacon_refresh` function. Problem occurs when at least two nodes are connected to the same BlueZ instance and they are connected to the same network (use same network key). Issue is triggered when IVIndex update process stabilize and one of the nodes receives network beacon with IVUpdate flag set to 0. Then it processes the "local" beacon and compose new `snb` (with IVUpdate flag set to 0) attached to `net_key` instance. After that it calls `net_local_beacon` and another node processes the new beacon (this node has IVUpdate flag still set to 1). Note that the `net->ivupdate` has set value 1. The `update_iv_ivu_state` says that "IVU clear attempted too soon". The node composes new `snb` with IVUpdate flag set to 1 and writes it to the `net_key` instance in the `net_key_beacon_refresh` function. After that it calls `net_local_beacon` which causes repeat of all process. We are rotating in this loop until end-of-memory.
* mesh: Update AppKeys on transition to Phase 0Michael N. Moran2021-01-041-0/+2
| | | | | | | | | | At the end of the mesh Key Refresh procedure when a subnet transitions to Phase 0, local AppKeys that were updated were not updating until the bluetooth-meshd daemon was restarted. This patch iterates the AppKeys at the end of mesh Key Refresh when the subnet transitions to Phase 0, setting the new state of each updated AppKey.
* mesh: Fix regression error in HB subscription setInga Stotland2020-11-191-5/+10
| | | | | | | | | | This fixes a regression introduced in commit c77bb848a9fb ("mesh: Refactor heartbeat pub/sub"): Heartbeat subscription should be enabled unless either source or destination are unassigned addresses or period log is zero. Also, decrement ref count on group destination address if period log is zero since the subscription is not supposed to be processed.
* mesh: Only deregister io for the last network detachedMichael N. Moran2020-11-101-2/+6
| | | | | | | | When multiple mesh networks are active and one is detached using Leave(), the I/O to all networks is halted. This patch prevents that by only deregistering the I/O if all networks have been detached.
* mesh: Add SPDX License IdentifierTedd Ho-Jeong An2020-09-211-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds SPDX License Identifier and removes the license text. ------------------------------------- License COUNT ------------------------------------- LGPL-2.1-or-later : 48 License: LGPL-2.1-or-later mesh/mesh-mgmt.h mesh/mesh-mgmt.c mesh/net-keys.c mesh/mesh-io-api.h mesh/mesh.h mesh/net-keys.h mesh/model.h mesh/util.h mesh/appkey.c mesh/cfgmod.h mesh/appkey.h mesh/prov.h mesh/prov-acceptor.c mesh/net.c mesh/dbus.h mesh/friend.h mesh/mesh-io-generic.c mesh/main.c mesh/util.c mesh/dbus.c mesh/error.h mesh/mesh-config-json.c mesh/agent.h mesh/pb-adv.c mesh/crypto.c mesh/crypto.h mesh/friend.c mesh/pb-adv.h mesh/provision.h mesh/mesh-config.h mesh/mesh-io-generic.h mesh/agent.c mesh/cfgmod-server.c mesh/mesh-io.h mesh/keyring.h mesh/net.h mesh/keyring.c mesh/mesh-defs.h mesh/mesh.c mesh/rpl.c mesh/manager.c mesh/model.c mesh/mesh-io.c mesh/node.c mesh/prov-initiator.c mesh/rpl.h mesh/node.h mesh/manager.h
* mesh: Move RPL check from model to net layerInga Stotland2020-08-281-85/+99
| | | | | | | | | Check whether an incoming message has an RPL entry prior to handing it over to model layer for processing. If present in RPL or the RPL queue is full, ignore the incoming message. If the incoming message is processed successfully, add the message as a new RPL entry.
* mesh: Initialize RPL when creating or loading a nodeInga Stotland2020-08-281-7/+7
| | | | | | | | When either a new node is created or an existing node is loaded from storage, initialize RPL storage directory. Additionally, when an existing node configguration is read from storage, load saved RPL entries into the corresponding RPL lists.
* mesh: Use correct retransmit parameters for publicationsInga Stotland2020-08-221-16/+26
| | | | | | This adds previously missing retransmit count and interval values specific to model publications. The values are configured by Config CLient and may be different to each model.
* mesh: Check for enabled modes when dst is fixed addressInga Stotland2020-08-201-0/+9
| | | | | | This moves the check for incoming messages addressed to fixed addresses, e.g. RELAY, PROXY, FRIEND. If the corresponding feature is not enabled, the message is not processed.
* mesh: Refactor heartbeat pub/subInga Stotland2020-08-101-73/+200
| | | | | | | | | | Move heartbeat publication/subscription timers and housekeeping to net.c since this is where the trigger events and control messages are handled. Configuration server (cfgmod-server.c) stays responsible for parsing the set pub/sub message parameters and assemblying the pub/sub status messages. Also, make sure that the correct message status is reported.
* mesh: Clean up handling of config KR phase messagesInga Stotland2020-08-101-35/+18
| | | | | | | | | This modification allows using a single point for sending out the composed status messages by the Config Server. Also, this checks for the correct relationship between KR transition and KR phase values. Correct error codes are sent on unsuccessful requests and malformed requests are ignored.
* mesh: Allow deleting non-existing net keyMichał Lowas-Rzechonek2020-08-061-4/+4
| | | | | When deleting a non-existing key, first check that it doesn't exist (and return success), then verify it's not the last key we have.
* mesh: Emit PropertiesChanged when IV Index changesInga Stotland2020-06-221-0/+2
| | | | | | This adds emitting of PropertiesChanged signal whenever the mesh IV index is updated to indicate that the vlaues of "IvIndex" property has been modified.
* mesh: Delete unused structures/functionsInga Stotland2020-06-161-49/+15
| | | | | This deletes unused functions and structures in net.c & net.h. Plus, some style cleanup.
* mesh: Fix clean-up introduced bugBrian Gix2020-06-081-1/+0
| | | | | | | | | Before the clean-up we were making a useless check of an otherwise unused boolean (net->provisioner) to determine if we should decode with device keys (which was incorrect). This was replaced by a check the node type (node->provisioner). However, the check was incorrect in the first place, and prevents provisioner nodes from decrypting non device key messages.
* mesh: Remove unused/redundant functionsInga Stotland2020-06-081-10/+0
| | | | | This removes mesh_net_provisioner_mode_set (unused) and mesh_net_provisioner_mode_get (duplicates node_is_provisioner)
* mesh: Remove unused functions from net.cInga Stotland2020-06-011-145/+4
| | | | | | | | | | | | | | | | | 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()
* mesh: Clean up style in net.cInga Stotland2020-06-011-153/+100
|
* mesh: Remove debug-only related callback for packet sendInga Stotland2020-06-011-19/+1
| | | | | | 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.
* mesh: Debug output clean upInga Stotland2020-06-011-101/+49
| | | | | This changes l_info() to l_debug() for recurring cases and removes some excessive debug output.
* mesh: Fix valgrind memory leak warningsBrian Gix2020-05-151-1/+11
| | | | | These warnings are caused by not completely freeing memory allocations at shutdown, and are not serious, but they make valgrind output cleaner.
* mesh: Ignore beacons with IVU if IV already updatedRafał Gajda2020-04-081-0/+8
| | | | | | | | | | | | | 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.
* mesh: Add net key index to sar structurePrzemysław Fierek2020-03-311-15/+23
| | | | | This patch adds net key index to struct mesh_sar. This fixes problem with using invalid network key to encrypt application messages.
* mesh: Remove unused functions: 'mesh_net_sub_list_add' and ↵Przemysław Fierek2020-03-311-27/+0
| | | | 'mesh_net_sub_list_del'
* mesh: Remove unused argument from 'mesh_net_transport_send' functionPrzemysław Fierek2020-03-311-7/+7
|
* mesh: Handle netkey delete when netkey is not in netkeylistPrathyusha N2020-03-251-1/+1
| | | | | | | | | 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.
* mesh: Fix Replay Protection CacheBrian Gix2020-03-231-1/+1
| | | | | There was a bug identified in the RPL storage, such that the real-time queue was being filled by incorrect unicast addresses. (Thx ccsanden).
* mesh: Allow short messages to be segmentedBrian Gix2020-03-201-28/+62
| | | | | | | | | | | 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.
* mesh: Remove unused parameters from internal rx functionsInga Stotland2020-03-051-2/+2
| | | | | | | | | 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)
* mesh: rework incoming advertisement filteringBrian Gix2020-02-261-4/+9
| | | | | | | 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.
* mesh: Re-arrange replay protection check and addBrian Gix2020-01-311-31/+31
| | | | | | | 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.
* mesh: Add NVM storage of Replay ProtectionBrian Gix2020-01-301-7/+14
| | | | | | | | | 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.
* mesh: Clean-up unneeded Sequence Number incrementsBrian Gix2020-01-301-8/+9
| | | | | | 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.