Bluetooth: Mesh: Model extension concept

Adds the model extension concept to the access layer, as described in
the Mesh Profile Specification, Section 2.3.6. Extensions are
implemented as a tree, using two pointers in each model:

The extends pointer points to the first extended model, and the next
pointer points to the next sibling or (if the NEXT_IS_PARENT flag is
set) the parent model in the tree, forming a cyclical "Left-child
right-sibling" (LCRS) tree. The tree root can be obtained by calling
bt_mesh_model_root_get(), and the extended models can be walked by
calling bt_mesh_model_tree_walk().

According to the Mesh Profile Specification Section 4.2.3, all models in
the same extension tree share one subscription list per element. This is
implemented by walking the model's extension tree, and pooling the
subscription lists of all models in the same element into one. If the
config server adds a subscription to a model, it may be stored in any of
the model tree's models' subscription lists. No two models in the same
extension tree and element will have duplicate groups listed. This
allows us to increase extended models' capacity for subscriptions
significantly.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
Trond Einar Snekvik 2019-10-18 13:23:06 +02:00 committed by Johan Hedberg
commit 0151d6dc33
8 changed files with 302 additions and 124 deletions

View file

@ -501,7 +501,7 @@ struct bt_mesh_model {
/* Internal information, mainly for persistent storage */
u8_t elem_idx; /* Belongs to Nth element */
u8_t mod_idx; /* Is the Nth model in the element */
u16_t flags; /* Information about what has changed */
u16_t flags; /* Model flags for internal bookkeeping */
/* Model Publication */
struct bt_mesh_model_pub * const pub;
@ -517,6 +517,12 @@ struct bt_mesh_model {
/* Model callback structure. */
const struct bt_mesh_model_cb * const cb;
#ifdef CONFIG_BT_MESH_MODEL_EXTENSIONS
/* Pointer to the next model in a model extension tree. */
struct bt_mesh_model *next;
/* Pointer to the first model this model extends. */
struct bt_mesh_model *extends;
#endif
/* Model-specific user data */
void *user_data;
};
@ -622,6 +628,30 @@ static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)
int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd,
const void *data, size_t data_len);
/** @brief Let a model extend another.
*
* Mesh models may be extended to reuse their functionality, forming a more
* complex model. A Mesh model may extend any number of models, in any element.
* The extensions may also be nested, ie a model that extends another may itself
* be extended. Extensions may not be cyclical, and a model can only be extended
* by one other model.
*
* A set of models that extend each other form a model extension tree.
*
* All models in an extension tree share one subscription list per element. The
* access layer will utilize the combined subscription list of all models in an
* extension tree and element, giving the models extended subscription list
* capacity.
*
* @param[in] mod Mesh model.
* @param[in] base_mod The model being extended.
*
* @retval 0 Successfully extended the base_mod model.
* @retval -EALREADY The base_mod model is already extended.
*/
int bt_mesh_model_extend(struct bt_mesh_model *mod,
struct bt_mesh_model *base_mod);
/** Node Composition */
struct bt_mesh_comp {
u16_t cid;