diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt
index 0ac2fdf..ff6b333 100644
--- a/doc/mesh-api.txt
+++ b/doc/mesh-api.txt
This call affects the local bluetooth-meshd key database only.
+ It is an error to call this with address range overlapping
+ with local element addresses.
+
PossibleErrors:
org.bluez.mesh.Error.Failed
org.bluez.mesh.Error.InvalidArguments
This call affects the local bluetooth-meshd key database only.
+ It is an error to call this with address range overlapping
+ with local element addresses.
+
PossibleErrors:
org.bluez.mesh.Error.InvalidArguments
diff --git a/mesh/keyring.c b/mesh/keyring.c
index 3ea8319..4b3d8b2 100644
--- a/mesh/keyring.c
+++ b/mesh/keyring.c
bool result = true;
int fd, i;
+ if (!IS_UNICAST_RANGE(unicast, count))
+ return false;
+
if (!node)
return false;
bool result = false;
int fd;
+ if (!IS_UNICAST(unicast))
+ return false;
+
if (!node)
return false;
node_path = node_get_storage_dir(node);
+
snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path, dev_key_dir,
unicast);
char key_file[PATH_MAX];
int i;
+ if (!IS_UNICAST_RANGE(unicast, count))
+ return false;
+
if (!node)
return false;
node_path = node_get_storage_dir(node);
+
for (i = 0; i < count; i++) {
snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path,
dev_key_dir, unicast + i);
diff --git a/mesh/manager.c b/mesh/manager.c
index 77d7b75..cf4782c 100644
--- a/mesh/manager.c
+++ b/mesh/manager.c
void *user_data)
{
struct mesh_node *node = user_data;
+ struct mesh_net *net = node_get_net(node);
struct l_dbus_message_iter iter_key;
uint16_t primary;
uint8_t num_ele;
return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
"Bad device key");
+ if (mesh_net_is_local_address(net, primary, num_ele))
+ return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
+ "Cannot overwrite local device key");
+
if (!keyring_put_remote_dev_key(node, primary, num_ele, key))
return dbus_error(msg, MESH_ERROR_FAILED, NULL);
void *user_data)
{
struct mesh_node *node = user_data;
+ struct mesh_net *net = node_get_net(node);
uint16_t primary;
uint8_t num_ele;
if (!l_dbus_message_get_arguments(msg, "qy", &primary, &num_ele))
return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
+ if (mesh_net_is_local_address(net, primary, num_ele))
+ return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
+ "Cannot remove local device key");
+
keyring_del_remote_dev_key(node, primary, num_ele);
return l_dbus_message_new_method_return(msg);
diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h
index 1a199f1..82be91d 100644
--- a/mesh/mesh-defs.h
+++ b/mesh/mesh-defs.h
#define IS_UNASSIGNED(x) ((x) == UNASSIGNED_ADDRESS)
#define IS_UNICAST(x) (((x) > UNASSIGNED_ADDRESS) && \
((x) < VIRTUAL_ADDRESS_LOW))
+#define IS_UNICAST_RANGE(x, c) (IS_UNICAST(x) && IS_UNICAST(x + c - 1))
#define IS_VIRTUAL(x) (((x) >= VIRTUAL_ADDRESS_LOW) && \
((x) <= VIRTUAL_ADDRESS_HIGH))
#define IS_GROUP(x) ((((x) >= GROUP_ADDRESS_LOW) && \
diff --git a/mesh/model.c b/mesh/model.c
index 00b4801..8f3d67e 100644
--- a/mesh/model.c
+++ b/mesh/model.c
forward.data);
else if (decrypt_idx == APP_IDX_DEV_REMOTE ||
(decrypt_idx == APP_IDX_DEV_LOCAL &&
- mesh_net_is_local_address(net, src)))
+ mesh_net_is_local_address(net, src, 1)))
send_dev_key_msg_rcvd(node, i, src, 0,
forward.size, forward.data);
}
diff --git a/mesh/net.c b/mesh/net.c
index d411654..7c92cfd 100644
--- a/mesh/net.c
+++ b/mesh/net.c
L_UINT_TO_PTR(idx)) != NULL);
}
-bool mesh_net_is_local_address(struct mesh_net *net, uint16_t addr)
+bool mesh_net_is_local_address(struct mesh_net *net, uint16_t src,
+ uint16_t count)
{
+ const uint16_t last = src + count - 1;
if (!net)
return false;
- return (addr >= net->src_addr && addr <= net->last_addr);
+ return (src >= net->src_addr && src <= net->last_addr) &&
+ (last >= net->src_addr && last <= net->last_addr);
}
void mesh_net_set_window_accuracy(struct mesh_net *net, uint8_t accuracy)
diff --git a/mesh/net.h b/mesh/net.h
index 834a735..b7aa377 100644
--- a/mesh/net.h
+++ b/mesh/net.h
struct mesh_io *mesh_net_get_io(struct mesh_net *net);
struct mesh_node *mesh_net_node_get(struct mesh_net *net);
bool mesh_net_have_key(struct mesh_net *net, uint16_t net_idx);
-bool mesh_net_is_local_address(struct mesh_net *net, uint16_t addr);
+bool mesh_net_is_local_address(struct mesh_net *net, uint16_t src,
+ uint16_t count);
void mesh_net_set_window_accuracy(struct mesh_net *net, uint8_t accuracy);
void mesh_net_transmit_params_set(struct mesh_net *net, uint8_t count,
uint16_t interval);