Commit Graph

534 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
0599a7fa9f mesh: Fix build error
This fixes the following error:

In function ‘get_composition’,
    inlined from ‘cfg_srv_pkt’ at mesh/cfgmod-server.c:801:8:
mesh/cfgmod-server.c:758:9: error: ‘comp’ may be used
uninitialized [-Werror=maybe-uninitialized]
  758 |         memcpy(buf, comp, len);
      |         ^~~~~~~~~~~~~~~~~~~~~~
mesh/cfgmod-server.c: In function ‘cfg_srv_pkt’:
mesh/cfgmod-server.c:739:24: note: ‘comp’ was declared here
  739 |         const uint8_t *comp;
      |                        ^~~~
2023-06-13 13:32:11 -07:00
Inga Stotland
93d0d8b2fc mesh: Update the behavior of --io option
This aligns the behavior of command line option --io to
add new "auto" value and modify the behavior of "generic"
value:

*auto* - Use first available controller: via MGMT interface
if kernel supports it, otherwise, via raw HCI socket (i.e.,
default to *generic*).

*generic:[hci]<index>* - Use generic HCI io on interface hci<index>

The default value is now *auto*, whereas *generic* is used
only if the specific HCI controller is explicitly specified.
2023-05-12 11:22:14 -07:00
Inga Stotland
cffd5832a5 mesh: Tighten IO and fix out-of-bounds array access
This fixes the out-of-bounds array access in mesh-io-mgmt.c caught
by address sanitizer. Similar fixes were applied earlier to
generic and unit IOs. With this patch, the common code is factored
into a centralized location.
2023-04-03 13:29:00 -07:00
Inga Stotland
4a3f465a55 mesh: On exit free timer for filtering duplicates
This frees resources associated with duplicate filter timer
when destroying management IO.
2023-03-20 12:18:37 -07:00
Brian Gix
806230e4fd mesh: Don't send Prov Failed on non-existant links
If remote device does not respond to a Prov Link Open request, then the
callbacks do not get established, and attempting to send Failure
messages on the non-existent link rersult in seg fault.
2023-03-15 18:12:38 -07:00
Brian Gix
c1f7aed635 mesh: Make MGMT mesh-io less noisy
Remove excessive logging traffic
2023-03-15 10:24:52 -07:00
Brian Gix
a5998b588c mesh: Filter originated Provisioning Data packets
The mesh daemon can process incoming mesh packets on more than one
controller, but if a Provisioning data packet that originated from the
local daemon is received by a different controller, it must be filtered
and disregarded, or it will break the provisioning protocol.
2023-03-15 10:16:35 -07:00
Brian Gix
7c0fb2fefb mesh: Loopback unprovisioned beacons
Because the daemon explicitly supports multiple nodes, we need
local Config Clients to be able to see local unprovisioned devices.

This loops the unprovisioned beacon, so that local Provisioning servers
can see it.

Fixes Issue: https://github.com/bluez/bluez/issues/341
2023-03-14 14:34:36 -07:00
Brian Gix
5934f133d4 mesh: Fix uninitialized memory usage
When attempting to cancel an unknown Scan request structure must be
NULL initialized.
2023-03-14 14:34:36 -07:00
Inga Stotland
40576ac1ba mesh: Fix node when loading from storage
This fixes adding mandatory models (config server, remote provisioner)
to a node whose configuration is being loaded from storage:
mesh_model_add() was called with a wrong argument.

Was:     mesh_model_add(..., PRIMARY_ELE_IDX, ...);
Correct: mesh_model_add(..., ele->models, ...);
2023-03-12 11:57:54 -07:00
Brian Gix
5045e9845b mesh: Remove unused byte swap for ScanBuild 2023-01-30 16:14:41 -08:00
Brian Gix
4bdd7090f0 mesh: Fix Checksmatch warning 2023-01-30 16:14:41 -08:00
Brian Gix
e71d0e8026 mesh: Switch beaconing net key
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.
2023-01-30 16:14:41 -08:00
Brian Gix
ebb2196141 mesh: Add internal Mesh Private Beacon model
Adds recgnition that the Mesh Private Beacon model is internal
and foundational, without bindings.
2023-01-30 16:14:41 -08:00
Brian Gix
5ba57cf851 mesh: Add Tx/Rx support of Mesh Private Beacons
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.
2023-01-30 16:14:41 -08:00
Brian Gix
6619b24cc2 mesh: Add Mesh Private Beacon server
This initial server supports only the Mesh Private Beacon and returns
"Not Suppoerted" for Get/Set of Private GATT Proxy and Private Node
Identity beacons.
2023-01-30 16:14:41 -08:00
Brian Gix
cbeca2fba1 mesh: Add storage of Mesh Private Beacon settings
If current storage does not exist in node.json, the Mesh Private
Beacon will be disabled.
2023-01-30 16:14:41 -08:00
Brian Gix
9923c09de5 mesh: Rename parameter list per crypto usage
The derived key generated by the "nkpk" salt and network master key is
used to create Private Beacons as of Mesh Profile Specification v1.1
2023-01-30 16:14:41 -08:00
Brian Gix
f3243ecba0 mesh: Add Remote Provisioning
Add Remote Provisioning Server
Add Remote Provisioning Client
Remove local scanning/provisioning
Add delete-all dev key function
Add NPPI procedures
2023-01-30 16:14:41 -08:00
Isak Westin
5f06473908 mesh: Keep cancelled SAR data for at least 10 sec
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.
2022-10-12 14:20:03 -07:00
Isak Westin
dabf32b313 mesh: Fix msg cache ring buffer
The message cache should be a strict ring buffer, suppressed message
should not move to the front of the queue.
2022-10-07 07:59:24 -07:00
Isak Westin
838ddc9312 mesh: provisionee: Check prov start parameters
Verify that all parameters in a Provisioning Start PDU are valid, also
compared to the capabilities that has been sent.
2022-10-06 13:56:22 -07:00
Isak Westin
77da94eb7a mesh: provisionee: Handle failed provisioning
When a provisioning fails, all additionally received PDU should be
unexpected until link is closed by provisioner. See MshPRFv1.0.1 section
5.4.4.
2022-10-06 13:56:21 -07:00
Isak Westin
c1f1a49aeb mesh: provisionee: Handle unknown PDUs
If an unknown PDU is received during provisioning, the provisioning
should fail with "Invalid PDU".
2022-10-06 13:56:21 -07:00
Isak Westin
95bf980b01 mesh: Update Key Refresh flag after provision
The Key Refresh flag in the Secure Network beacon is now correctly
updated based on provisioning data after being successfully provisioned.
2022-10-06 13:56:21 -07:00
Isak Westin
c89e9c4b22 mesh: Always relay messages from Low Power nodes
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.
2022-10-06 13:34:20 -07:00
Isak Westin
3f3a7b8e19 mesh: Queue a friend update on IV Update change
A friend update should be queued when we receive a Secure Network beacon
that changes the IV Update state.
2022-10-06 13:34:20 -07:00
Isak Westin
7ff3e10d92 mesh: Verify padding bits in Friend Poll messages
The padding bits in a Friend Poll message must be zero.
See MshPRFv1.0.1 section 3.6.5.1.
2022-10-06 13:34:20 -07:00
Isak Westin
e9a8e88410 mesh: Correct size of friend cache
The cache size communicated to the Low Power node should be the same as
the cache size actually used.
2022-10-06 13:34:20 -07:00
Inga Stotland
e71e1103ab mesh: Fix mesh to work with MESH_IO_TYPE_UNIT_TEST
This fixes mesh io flow for MESH_IO_TYPE_UNIT_TEST which
got broken after:
commit 9966cb8b69
("mesh: Add new kernel MGMT based IO transport")
2022-10-05 13:48:35 -07:00
Isak Westin
291cff0680 mesh: Allow Key Refresh Phase 0 to 3 transition
Transition to Phase 3 from Phase 0 does not cause any state change, but
is a valid transition. See MshPRFv1.0.1 section 4.2.14.
2022-10-03 14:19:19 -07:00
Isak Westin
9d22d54244 mesh: Allow Key refresh to skip Phase 2
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.
2022-10-03 14:19:19 -07:00
Isak Westin
7d050890f0 mesh: Ignore SNB with invalid IV Index values
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.
2022-10-03 14:19:19 -07:00
Isak Westin
926d16db8a mesh: Ignore Secure Network Beacon from subnet
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.
2022-10-03 14:19:19 -07:00
Isak Westin
d763bfa4d0 mesh: Clear HB sub status field if disabled
When replying to a HB subscription get message, and the current state of
source or destination fields is zero (which means that HB subscription
is disabled), all fields in the status reply should be zero.
2022-09-26 13:14:47 -07:00
Isak Westin
902389f3e7 mesh: Correct HB sub state updates
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.
2022-09-26 13:14:47 -07:00
Isak Westin
1ef221ca02 mesh: Reply to HB pub set with same fields
If a Config Heartbeat Publication Set message is unsuccessfully
processed, the fields in the status reply should be the same as in the
original message. See MshPRFv1.0.1 section 4.4.1.2.15.
2022-09-26 13:14:47 -07:00
Isak Westin
5b569e3d14 mesh: Correct u32 to u8 log transformation
Fixed the log transformation to correctly follow the value mapping
defined in the mesh profile (section 4.1.2).
2022-09-26 13:14:47 -07:00
Brian Gix
9966cb8b69 mesh: Add new kernel MGMT based IO transport
1. Re-structures MGMT handling such that it is used to detect kernel
   support of the mesh MGMT opcodes and events before selecting between
   using MGMT or the legacy raw HCI socket method.

2. Re-structures main() to allow command line to prefer MGMT over HCI or
   visa versa, plus optionally pass an explicte controller.

3. Adds mesh-io-mgmt as a transport.
2022-09-26 13:14:47 -07:00
Brian Gix
491be481a9 mesh: Improve PB-ADV timing for reliability
Because provisioning is not speed dependent, Timing on outbound PB-ADV
packets have been modified to be less likely missed by remote controlers
with looser timing capabilities.
2022-09-26 13:14:47 -07:00
Isak Westin
95d9dc6764 mesh: Reply error if appkey added for wrong netkey
If a known appkey is added for a different netkey, the status reply
should be Invalid NetKey.
2022-09-23 10:06:37 -07:00
Isak Westin
32d866b4df mesh: Clear addr field if virt sub failed
If processing failed for a Config Model Subscription Virtual Address
Add/Delete/Overwrite message, the address field in the status reply
should be set to zero. See MshPRFv1.0.1 section 4.4.1.2.8.
2022-09-23 10:06:37 -07:00
Isak Westin
c9fadca7eb mesh: Remove RFU check for publication set
It is not stated in the mesh profile that the RFU bits in a Model
Publication Set message have to be zero. In fact, PTS test
MESH/NODE/CFG/MP/BV-01-C is sending that command with non-zero RFU and
expects a reply.
2022-09-22 14:02:38 -07:00
Isak Westin
b72edcc5ca mesh: Do not accept publication for unbound appkey
If a user tries to configure publication of a model with an appkey that
is not bound to that model, an error should be returned.
2022-09-22 14:02:38 -07:00
Isak Westin
a76ff5879b mesh: Add interface output filter
According to the mesh profile (3.4.5.2), if TTL is set to 1 for an
outgoing message, that message shall be dropped.
2022-09-22 14:02:38 -07:00
Brian Gix
75ba186a9c mesh: Fix potential memory leak
This memory leak will never happen, however since we added a new
return from function that malloc'd memory, the free should still be
done.
2022-09-22 14:02:38 -07:00
Brian Gix
5351d4d86a mesh: Fix snprintf return values not being checked
Some versions of the GCC compiler complain when the return value of
snprintf is not checked. This patch cleans up the Mesh JSON parser.
2022-06-30 13:27:51 -07:00
Isak Westin
be7ebf29b3 mesh: Use correct net_id for received CTL messages
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.
2022-06-30 13:18:06 -07:00
Jonas Maes
71560e1286 mesh: Fix bug where bluetooth-meshd stops sending
When there is a backlog of mesh packets to be sent, the packet sender
Fix bug where bluetooth-meshd stops sending

When there is a backlog of mesh packets to be sent, the packet sender
incorrectly infers that the tx worker thread is already running
and therefore needn't be invoked. As a result, the mesh daemon will
sometimes stop broadcasting while there are still packets in the queue.
It will not resume broadcasting.

This patch will invoke the tx worker thread correctly in that case.

The logic to send packets at least twice when the transmitter is idle
was slightly modified accordingly, and should behave the same way as
before.
2022-06-21 13:18:16 -07:00
Brian Gix
5cc08527c0 mesh: Fix keyring snprintf usage range checking
snprintf performs it's own range checking and returns a negative value
if string construction fails. Not checking the return value throws a
warning at compile time on GCC 12 and later. This patch removes
redundent range chacking and checks all snprintf return values.
2022-06-14 13:42:09 -07:00