diff options
Diffstat (limited to 'src/libs/mynewt-nimble/nimble/host/mesh/include')
15 files changed, 1856 insertions, 348 deletions
diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/access.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/access.h index 1f99f412..9f923cb9 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/access.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/access.h @@ -28,14 +28,23 @@ extern "C" { #define BT_MESH_ADDR_RELAYS 0xfffe #define BT_MESH_KEY_UNUSED 0xffff +#define BT_MESH_KEY_ANY 0xffff #define BT_MESH_KEY_DEV 0xfffe #define BT_MESH_KEY_DEV_LOCAL BT_MESH_KEY_DEV #define BT_MESH_KEY_DEV_REMOTE 0xfffd #define BT_MESH_KEY_DEV_ANY 0xfffc +#define BT_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000) +#define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) <= 0xff00) +#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000) +#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb) + #define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \ key == BT_MESH_KEY_DEV_REMOTE) +#define BT_MESH_APP_SEG_SDU_MAX 12 +#define BT_MESH_TX_SDU_MAX (CONFIG_BT_MESH_TX_SEG_MAX * BT_MESH_APP_SEG_SDU_MAX) +#define BT_MESH_RX_SDU_MAX (CONFIG_BT_MESH_RX_SEG_MAX * BT_MESH_APP_SEG_SDU_MAX) /** Helper to define a mesh element within an array. * * In case the element has no SIG or Vendor models the helper @@ -57,13 +66,13 @@ extern "C" { /** Abstraction that describes a Mesh Element */ struct bt_mesh_elem { /* Unicast Address. Set at runtime during provisioning. */ - u16_t addr; + uint16_t addr; /* Location Descriptor (GATT Bluetooth Namespace Descriptors) */ - const u16_t loc; + const uint16_t loc; - const u8_t model_count; - const u8_t vnd_model_count; + const uint8_t model_count; + const uint8_t vnd_model_count; struct bt_mesh_model * const models; struct bt_mesh_model * const vnd_models; @@ -132,33 +141,33 @@ struct bt_mesh_elem { /** Message sending context. */ struct bt_mesh_msg_ctx { /** NetKey Index of the subnet to send the message on. */ - u16_t net_idx; + uint16_t net_idx; /** AppKey Index to encrypt the message with. */ - u16_t app_idx; + uint16_t app_idx; /** Remote address. */ - u16_t addr; + uint16_t addr; /** Destination address of a received message. Not used for sending. */ - u16_t recv_dst; + uint16_t recv_dst; /** RSSI of received packet. Not used for sending. */ - s8_t recv_rssi; + int8_t recv_rssi; /** Received TTL value. Not used for sending. */ - u8_t recv_ttl; + uint8_t recv_ttl; /** Force sending reliably by using segment acknowledgement */ bool send_rel; /** TTL, or BT_MESH_TTL_DEFAULT for default TTL. */ - u8_t send_ttl; + uint8_t send_ttl; }; struct bt_mesh_model_op { /* OpCode encoded using the BT_MESH_MODEL_OP_* macros */ - const u32_t opcode; + const uint32_t opcode; /* Minimum required message length */ const size_t min_len; @@ -324,7 +333,7 @@ struct bt_mesh_model_op { * * @return Transmission count (actual transmissions is N + 1). */ -#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (u8_t)BIT_MASK(3))) +#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3))) /** @def BT_MESH_TRANSMIT_INT * @@ -375,23 +384,24 @@ struct bt_mesh_model_pub { /** The model the context belongs to. Initialized by the stack. */ struct bt_mesh_model *mod; - u16_t addr; /**< Publish Address. */ - u16_t key; /**< Publish AppKey Index. */ + uint16_t addr; /**< Publish Address. */ + uint16_t key; /**< Publish AppKey Index. */ - u8_t ttl; /**< Publish Time to Live. */ - u8_t retransmit; /**< Retransmit Count & Interval Steps. */ - u8_t period; /**< Publish Period. */ - u8_t period_div:4, /**< Divisor for the Period. */ + uint8_t ttl; /**< Publish Time to Live. */ + uint8_t retransmit; /**< Retransmit Count & Interval Steps. */ + uint8_t period; /**< Publish Period. */ + uint8_t period_div:4, /**< Divisor for the Period. */ cred:1, /**< Friendship Credentials Flag. */ + send_rel:1, fast_period:1,/**< Use FastPeriodDivisor */ count:3; /**< Retransmissions left. */ - u32_t period_start; /**< Start of the current period. */ + uint32_t period_start; /**< Start of the current period. */ /** @brief Publication buffer, containing the publication message. * * The application is expected to initialize this with - * a valid net_buf_simple pointer, with the help of e.g. + * a valid os_mbuf pointer, with the help of e.g. * the NET_BUF_SIMPLE() macro. The publication buffer must * contain a valid publication message before calling the * bt_mesh_model_publish() API or after the publication's @@ -414,6 +424,10 @@ struct bt_mesh_model_pub { * will be called periodically and is expected to update * @ref bt_mesh_model_pub.msg with a valid publication * message. + * + * If the callback returns non-zero, the publication is skipped + * and will resume on the next periodic publishing interval. + * * * @param mod The Model the Publication Context belogs to. * @@ -432,16 +446,18 @@ struct bt_mesh_model_cb { * @sa settings_handler::h_set * * @param model Model to set the persistent data of. + * @param name Name/key of the settings item. * @param val Data from the backend. * * @return 0 on success, error otherwise. */ - int (*const settings_set)(struct bt_mesh_model *model, char *val); + int (*const settings_set)(struct bt_mesh_model *model, + const char *name, char *val); - /** @brief Callback called when all settings have been loaded. + /** @brief Callback called when the mesh is started. * - * This handler gets called after the settings have been loaded in - * full. + * This handler gets called after the node has been provisioned, or + * after all mesh data has been loaded from persistent storage. * * @sa settings_handler::h_commit * @@ -449,12 +465,17 @@ struct bt_mesh_model_cb { * * @return 0 on success, error otherwise. */ - int (*const settings_commit)(struct bt_mesh_model *model); + int (*const start)(struct bt_mesh_model *model); /** @brief Model init callback. * * Called on every model instance during mesh initialization. * + * + * If any of the model init callbacks return an error, the Mesh + * subsystem initialization will be aborted, and the error will be + * returned to the caller of @ref bt_mesh_init. + * * @param model Model to be initialized. * * @return 0 on success, error otherwise. @@ -466,6 +487,9 @@ struct bt_mesh_model_cb { * Called when the mesh node is reset. All model data is deleted on * reset, and the model should clear its state. * + * @note If the model stores any persistent data, this needs to be + * erased manually. + * * @param model Model this callback belongs to. */ void (*const reset)(struct bt_mesh_model *model); @@ -474,26 +498,26 @@ struct bt_mesh_model_cb { /** Abstraction that describes a Mesh Model instance */ struct bt_mesh_model { union { - const u16_t id; + const uint16_t id; struct { - u16_t company; - u16_t id; + uint16_t company; + uint16_t id; } vnd; }; /* 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; /* Model flags for internal bookkeeping */ + uint8_t elem_idx; /* Belongs to Nth element */ + uint8_t mod_idx; /* Is the Nth model in the element */ + uint16_t flags; /* Model flags for internal bookkeeping */ /* Model Publication */ struct bt_mesh_model_pub * const pub; /* AppKey List */ - u16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; + uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; /* Subscription List (group or virtual addresses) */ - u16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; + uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; const struct bt_mesh_model_op * const op; @@ -511,11 +535,11 @@ struct bt_mesh_model { }; struct bt_mesh_send_cb { - void (*start)(u16_t duration, int err, void *cb_data); + void (*start)(uint16_t duration, int err, void *cb_data); void (*end)(int err, void *cb_data); }; -void bt_mesh_model_msg_init(struct os_mbuf *msg, u32_t opcode); +void bt_mesh_model_msg_init(struct os_mbuf *msg, uint32_t opcode); /** Special TTL value to request using configured default TTL */ #define BT_MESH_TTL_DEFAULT 0xff @@ -574,7 +598,7 @@ struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod); * if no SIG model with the given ID exists in the given element. */ struct bt_mesh_model *bt_mesh_model_find(const struct bt_mesh_elem *elem, - u16_t id); + uint16_t id); /** @brief Find a vendor model. * @@ -586,7 +610,7 @@ struct bt_mesh_model *bt_mesh_model_find(const struct bt_mesh_elem *elem, * if no vendor model with the given ID exists in the given element. */ struct bt_mesh_model *bt_mesh_model_find_vnd(const struct bt_mesh_elem *elem, - u16_t company, u16_t id); + uint16_t company, uint16_t id); /** @brief Get whether the model is in the primary element of the device. * @@ -603,13 +627,14 @@ static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod) * * @param mod Mesh model. * @param vnd This is a vendor model. + * @param name Name/key of the settings item. * @param data Model data to store, or NULL to delete any model data. * @param data_len Length of the model data. * * @return 0 on success, or (negative) error code on failure. */ int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd, - const void *data, size_t data_len); + const char *name, const void *data, size_t data_len); /** @brief Let a model extend another. * @@ -637,9 +662,9 @@ int bt_mesh_model_extend(struct bt_mesh_model *mod, /** Node Composition */ struct bt_mesh_comp { - u16_t cid; - u16_t pid; - u16_t vid; + uint16_t cid; + uint16_t pid; + uint16_t vid; size_t elem_count; struct bt_mesh_elem *elem; diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/atomic.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/atomic.h new file mode 100644 index 00000000..2c731794 --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/atomic.h @@ -0,0 +1,409 @@ +/* atomic operations */ + +/* + * Copyright (c) 1997-2015, Wind River Systems, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __ATOMIC_H__ +#define __ATOMIC_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef int atomic_t; +typedef atomic_t atomic_val_t; + +/** + * @defgroup atomic_apis Atomic Services APIs + * @ingroup kernel_apis + * @{ + */ + +/** + * @brief Atomic compare-and-set. + * + * This routine performs an atomic compare-and-set on @a target. If the current + * value of @a target equals @a old_value, @a target is set to @a new_value. + * If the current value of @a target does not equal @a old_value, @a target + * is left unchanged. + * + * @param target Address of atomic variable. + * @param old_value Original value to compare against. + * @param new_value New value to store. + * @return 1 if @a new_value is written, 0 otherwise. + */ +static inline int atomic_cas(atomic_t *target, atomic_val_t old_value, + atomic_val_t new_value) +{ + return __atomic_compare_exchange_n(target, &old_value, new_value, + 0, __ATOMIC_SEQ_CST, + __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic addition. + * + * This routine performs an atomic addition on @a target. + * + * @param target Address of atomic variable. + * @param value Value to add. + * + * @return Previous value of @a target. + */ +static inline atomic_val_t atomic_add(atomic_t *target, atomic_val_t value) +{ + return __atomic_fetch_add(target, value, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic subtraction. + * + * This routine performs an atomic subtraction on @a target. + * + * @param target Address of atomic variable. + * @param value Value to subtract. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value) +{ + return __atomic_fetch_sub(target, value, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic increment. + * + * This routine performs an atomic increment by 1 on @a target. + * + * @param target Address of atomic variable. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_inc(atomic_t *target) +{ + return atomic_add(target, 1); +} + +/** + * + * @brief Atomic decrement. + * + * This routine performs an atomic decrement by 1 on @a target. + * + * @param target Address of atomic variable. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_dec(atomic_t *target) +{ + return atomic_sub(target, 1); +} + +/** + * + * @brief Atomic get. + * + * This routine performs an atomic read on @a target. + * + * @param target Address of atomic variable. + * + * @return Value of @a target. + */ + +static inline atomic_val_t atomic_get(const atomic_t *target) +{ + return __atomic_load_n(target, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic get-and-set. + * + * This routine atomically sets @a target to @a value and returns + * the previous value of @a target. + * + * @param target Address of atomic variable. + * @param value Value to write to @a target. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value) +{ + /* This builtin, as described by Intel, is not a traditional + * test-and-set operation, but rather an atomic exchange operation. It + * writes value into *ptr, and returns the previous contents of *ptr. + */ + return __atomic_exchange_n(target, value, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic clear. + * + * This routine atomically sets @a target to zero and returns its previous + * value. (Hence, it is equivalent to atomic_set(target, 0).) + * + * @param target Address of atomic variable. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_clear(atomic_t *target) +{ + return atomic_set(target, 0); +} + +/** + * + * @brief Atomic bitwise inclusive OR. + * + * This routine atomically sets @a target to the bitwise inclusive OR of + * @a target and @a value. + * + * @param target Address of atomic variable. + * @param value Value to OR. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_or(atomic_t *target, atomic_val_t value) +{ + return __atomic_fetch_or(target, value, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic bitwise exclusive OR (XOR). + * + * This routine atomically sets @a target to the bitwise exclusive OR (XOR) of + * @a target and @a value. + * + * @param target Address of atomic variable. + * @param value Value to XOR + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value) +{ + return __atomic_fetch_xor(target, value, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic bitwise AND. + * + * This routine atomically sets @a target to the bitwise AND of @a target + * and @a value. + * + * @param target Address of atomic variable. + * @param value Value to AND. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_and(atomic_t *target, atomic_val_t value) +{ + return __atomic_fetch_and(target, value, __ATOMIC_SEQ_CST); +} + +/** + * + * @brief Atomic bitwise NAND. + * + * This routine atomically sets @a target to the bitwise NAND of @a target + * and @a value. (This operation is equivalent to target = ~(target & value).) + * + * @param target Address of atomic variable. + * @param value Value to NAND. + * + * @return Previous value of @a target. + */ + +static inline atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value) +{ + return __atomic_fetch_nand(target, value, __ATOMIC_SEQ_CST); +} + + /** + * @brief Initialize an atomic variable. + * + * This macro can be used to initialize an atomic variable. For example, + * @code atomic_t my_var = ATOMIC_INIT(75); @endcode + * + * @param i Value to assign to atomic variable. + */ +#define ATOMIC_INIT(i) (i) + + /** + * @cond INTERNAL_HIDDEN + */ + +#define ATOMIC_BITS (sizeof(atomic_val_t) * 8) +#define ATOMIC_MASK(bit) (1 << ((bit) & (ATOMIC_BITS - 1))) +#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS)) + + /** + * INTERNAL_HIDDEN @endcond + */ + + /** + * @brief Define an array of atomic variables. + * + * This macro defines an array of atomic variables containing at least + * @a num_bits bits. + * + * @note + * If used from file scope, the bits of the array are initialized to zero; + * if used from within a function, the bits are left uninitialized. + * + * @param name Name of array of atomic variables. + * @param num_bits Number of bits needed. + */ +#define ATOMIC_DEFINE(name, num_bits) \ + atomic_t name[1 + ((num_bits) - 1) / ATOMIC_BITS] + + /** + * @brief Atomically test a bit. + * + * This routine tests whether bit number @a bit of @a target is set or not. + * The target may be a single atomic variable or an array of them. + * + * @param target Address of atomic variable or array. + * @param bit Bit number (starting from 0). + * + * @return 1 if the bit was set, 0 if it wasn't. + */ + static inline int + atomic_test_bit(const atomic_t *target, int bit) + { + atomic_val_t val = atomic_get(ATOMIC_ELEM(target, bit)); + + return (1 & (val >> (bit & (ATOMIC_BITS - 1)))); + } + + /** + * @brief Atomically test and clear a bit. + * + * Atomically clear bit number @a bit of @a target and return its old value. + * The target may be a single atomic variable or an array of them. + * + * @param target Address of atomic variable or array. + * @param bit Bit number (starting from 0). + * + * @return 1 if the bit was set, 0 if it wasn't. + */ + static inline int + atomic_test_and_clear_bit(atomic_t *target, int bit) + { + atomic_val_t mask = ATOMIC_MASK(bit); + atomic_val_t old; + + old = atomic_and(ATOMIC_ELEM(target, bit), ~mask); + + return (old & mask) != 0; + } + + /** + * @brief Atomically set a bit. + * + * Atomically set bit number @a bit of @a target and return its old value. + * The target may be a single atomic variable or an array of them. + * + * @param target Address of atomic variable or array. + * @param bit Bit number (starting from 0). + * + * @return 1 if the bit was set, 0 if it wasn't. + */ + static inline int + atomic_test_and_set_bit(atomic_t *target, int bit) + { + atomic_val_t mask = ATOMIC_MASK(bit); + atomic_val_t old; + + old = atomic_or(ATOMIC_ELEM(target, bit), mask); + + return (old & mask) != 0; + } + + /** + * @brief Atomically clear a bit. + * + * Atomically clear bit number @a bit of @a target. + * The target may be a single atomic variable or an array of them. + * + * @param target Address of atomic variable or array. + * @param bit Bit number (starting from 0). + * + * @return N/A + */ + static inline void + atomic_clear_bit(atomic_t *target, int bit) + { + atomic_val_t mask = ATOMIC_MASK(bit); + + atomic_and(ATOMIC_ELEM(target, bit), ~mask); + } + + /** + * @brief Atomically set a bit. + * + * Atomically set bit number @a bit of @a target. + * The target may be a single atomic variable or an array of them. + * + * @param target Address of atomic variable or array. + * @param bit Bit number (starting from 0). + * + * @return N/A + */ + static inline void + atomic_set_bit(atomic_t *target, int bit) + { + atomic_val_t mask = ATOMIC_MASK(bit); + + atomic_or(ATOMIC_ELEM(target, bit), mask); + } + +/** +* @brief Atomically set a bit to a given value. +* +* Atomically set bit number @a bit of @a target to value @a val. +* The target may be a single atomic variable or an array of them. +* +* @param target Address of atomic variable or array. +* @param bit Bit number (starting from 0). +* @param val true for 1, false for 0. +* +* @return N/A +*/ +static inline void atomic_set_bit_to(atomic_t *target, int bit, bool val) +{ + atomic_val_t mask = ATOMIC_MASK(bit); + + if (val) { + (void)atomic_or(ATOMIC_ELEM(target, bit), mask); + } else { + (void)atomic_and(ATOMIC_ELEM(target, bit), ~mask); + } +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __ATOMIC_H__ */ diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cdb.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cdb.h new file mode 100644 index 00000000..8f9a6bc9 --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cdb.h @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2019 Tobias Svehagen + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef _BLUETOOTH_MESH_CDB_H_ +#define _BLUETOOTH_MESH_CDB_H_ + +#include "syscfg/syscfg.h" + +#if MYNEWT_VAL(BLE_MESH_CDB) +#define NODE_COUNT CONFIG_BT_MESH_NODE_COUNT +#define SUBNET_COUNT CONFIG_BT_MESH_SUBNET_COUNT +#define APP_KEY_COUNT CONFIG_BT_MESH_APP_KEY_COUNT +#else +#define NODE_COUNT 0 +#define SUBNET_COUNT 0 +#define APP_KEY_COUNT 0 +#endif + +#include "atomic.h" + +enum { + BT_MESH_CDB_NODE_CONFIGURED, + BT_MESH_CDB_NODE_BLACKLISTED, + + BT_MESH_CDB_NODE_FLAG_COUNT +}; + +struct bt_mesh_cdb_node { + uint8_t uuid[16]; + uint16_t addr; + uint16_t net_idx; + uint8_t num_elem; + uint8_t dev_key[16]; + + ATOMIC_DEFINE(flags, BT_MESH_CDB_NODE_FLAG_COUNT); +}; + +struct bt_mesh_cdb_subnet { + uint16_t net_idx; + + bool kr_flag; + uint8_t kr_phase; + + struct { + uint8_t net_key[16]; + } keys[2]; +}; + +struct bt_mesh_cdb_app_key { + uint16_t net_idx; + uint16_t app_idx; + + struct { + uint8_t app_key[16]; + } keys[2]; +}; + +enum { + BT_MESH_CDB_VALID, + BT_MESH_CDB_SUBNET_PENDING, + BT_MESH_CDB_KEYS_PENDING, + BT_MESH_CDB_NODES_PENDING, + BT_MESH_CDB_IVU_IN_PROGRESS, + + BT_MESH_CDB_FLAG_COUNT, +}; + +struct bt_mesh_cdb { + uint32_t iv_index; + + ATOMIC_DEFINE(flags, BT_MESH_CDB_FLAG_COUNT); + + struct bt_mesh_cdb_node nodes[NODE_COUNT]; + struct bt_mesh_cdb_subnet subnets[SUBNET_COUNT]; + struct bt_mesh_cdb_app_key app_keys[APP_KEY_COUNT]; +}; + +extern struct bt_mesh_cdb bt_mesh_cdb; + +/** @brief Create the Mesh Configuration Database. + * + * Create and initialize the Mesh Configuration Database. A primary subnet, + * ie one with NetIdx 0, will be added and the provided key will be used as + * NetKey for that subnet. + * + * @param key The NetKey to be used for the primary subnet. + * + * @return 0 on success or negative error code on failure. + */ +int bt_mesh_cdb_create(const uint8_t key[16]); + +/** @brief Clear the Mesh Configuration Database. + * + * Remove all nodes, subnets and app-keys stored in the database and mark + * the database as invalid. The data will be cleared from persistent storage + * if CONFIG_BT_SETTINGS is enabled. + */ +void bt_mesh_cdb_clear(void); + +/** @brief Set and store the IV Index and IV Update flag. + * + * The IV Index stored in the CDB will be the one used during provisioning + * of new nodes. This function is generally only used from inside the stack. + * + * This function will store the data to persistent storage if + * CONFIG_BT_SETTINGS is enabled. + * + * @param iv_index The new IV Index to use. + * @param iv_update True if there is an ongoing IV Update procedure. + */ +void bt_mesh_cdb_iv_update(uint32_t iv_index, bool iv_update); + +/** @brief Allocate a node. + * + * Allocate a new node in the CDB. + * + * @param uuid UUID of the node. + * @param addr Address of the node's primary element. If 0, the lowest + * possible address available will be assigned to the node. + * @param num_elem Number of elements that the node has. + * @param net_idx NetIdx that the node was provisioned to. + * + * @return The new node or NULL if it cannot be allocated. + */ +struct bt_mesh_cdb_node *bt_mesh_cdb_node_alloc(const uint8_t uuid[16], uint16_t addr, + uint8_t num_elem, uint16_t net_idx); + +/** @brief Delete a node. + * + * Delete a node from the CDB. + * + * @param node The node to be deleted. + * @param store If true, the node will be cleared from persistent storage. + */ +void bt_mesh_cdb_node_del(struct bt_mesh_cdb_node *node, bool store); + +/** @brief Get a node by address. + * + * Try to find the node that has the provided address assigned to one of its + * elements. + * + * @param addr Address of the element to look for. + * + * @return The node that has an element with address addr or NULL if no such + * node exists. + */ +struct bt_mesh_cdb_node *bt_mesh_cdb_node_get(uint16_t addr); + +/** @brief Store node to persistent storage. + * + * @param node Node to be stored. + */ +void bt_mesh_cdb_node_store(const struct bt_mesh_cdb_node *node); + +enum { + BT_MESH_CDB_ITER_STOP = 0, + BT_MESH_CDB_ITER_CONTINUE, +}; + +/** @typedef bt_mesh_cdb_node_func_t + * @brief Node iterator callback. + * + * @param node Node found. + * @param user_data Data given. + * + * @return BT_MESH_CDB_ITER_CONTINUE to continue to iterate through the nodes + * or BT_MESH_CDB_ITER_STOP to stop. + */ +typedef uint8_t (*bt_mesh_cdb_node_func_t)(struct bt_mesh_cdb_node *node, + void *user_data); + +/** @brief Node iterator. + * + * Iterate nodes in the Mesh Configuration Database. The callback function + * will only be called for valid, ie allocated, nodes. + * + * @param func Callback function. + * @param user_data Data to pass to the callback. + */ +void bt_mesh_cdb_node_foreach(bt_mesh_cdb_node_func_t func, void *user_data); + +/** @brief Allocate a subnet. + * + * Allocate a new subnet in the CDB. + * + * @param net_idx NetIdx of the subnet. + * + * @return The new subnet or NULL if it cannot be allocated. + */ +struct bt_mesh_cdb_subnet *bt_mesh_cdb_subnet_alloc(uint16_t net_idx); + +/** @brief Delete a subnet. + * + * Delete a subnet from the CDB. + * + * @param sub The subnet to be deleted. + * @param store If true, the subnet will be cleared from persistent storage. + */ +void bt_mesh_cdb_subnet_del(struct bt_mesh_cdb_subnet *sub, bool store); + +/** @brief Get a subnet by NetIdx + * + * Try to find the subnet with the specified NetIdx. + * + * @param net_idx NetIdx of the subnet to look for. + * + * @return The subnet with the specified NetIdx or NULL if no such subnet + * exists. + */ +struct bt_mesh_cdb_subnet *bt_mesh_cdb_subnet_get(uint16_t net_idx); + +/** @brief Store subnet to persistent storage. + * + * @param sub Subnet to be stored. + */ +void bt_mesh_cdb_subnet_store(const struct bt_mesh_cdb_subnet *sub); + +/** @brief Get the flags for a subnet + * + * @param sub The subnet to get flags for. + * + * @return The flags for the subnet. + */ +uint8_t bt_mesh_cdb_subnet_flags(const struct bt_mesh_cdb_subnet *sub); + + +/** @brief Allocate an application key. + * + * Allocate a new application key in the CDB. + * + * @param net_idx NetIdx of NetKey that the application key is bound to. + * @param app_idx AppIdx of the application key. + * + * @return The new application key or NULL if it cannot be allocated. + */ +struct bt_mesh_cdb_app_key *bt_mesh_cdb_app_key_alloc(uint16_t net_idx, + uint16_t app_idx); + +/** @brief Delete an application key. + * + * Delete an application key from the CDB. + * + * @param key The application key to be deleted. + * @param store If true, the key will be cleared from persistent storage. + */ +void bt_mesh_cdb_app_key_del(struct bt_mesh_cdb_app_key *key, bool store); + +/** @brief Get an application key by AppIdx + * + * Try to find the application key with the specified AppIdx. + * + * @param app_idx AppIdx of the application key to look for. + * + * @return The application key with the specified AppIdx or NULL if no such key + * exists. + */ +struct bt_mesh_cdb_app_key *bt_mesh_cdb_app_key_get(uint16_t app_idx); + +/** @brief Store application key to persistent storage. + * + * @param key Application key to be stored. + */ +void bt_mesh_cdb_app_key_store(const struct bt_mesh_cdb_app_key *key); + +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_CDB_H_ */
\ No newline at end of file diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg.h new file mode 100644 index 00000000..378f0a0a --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg.h @@ -0,0 +1,485 @@ +/** @file + * @brief Bluetooth Mesh Runtime Configuration APIs. + */ + +/* + * Copyright (c) 2020 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef _BT_MESH_CFG_H_ +#define _BT_MESH_CFG_H_ + +#include <stdbool.h> +#include <stddef.h> +#include <sys/types.h> + +/** + * @brief Bluetooth Mesh Runtime Configuration API + * @defgroup bt_mesh_cfg Bluetooth Mesh Runtime Configuration + * @ingroup bt_mesh + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** Bluetooth Mesh Feature states */ +enum bt_mesh_feat_state { + /** Feature is supported, but disabled. */ + BT_MESH_FEATURE_DISABLED, + /** Feature is supported and enabled. */ + BT_MESH_FEATURE_ENABLED, + /** Feature is not supported, and cannot be enabled. */ + BT_MESH_FEATURE_NOT_SUPPORTED, +}; + +/* Legacy feature defines */ +#define BT_MESH_RELAY_DISABLED BT_MESH_FEATURE_DISABLED +#define BT_MESH_RELAY_ENABLED BT_MESH_FEATURE_ENABLED +#define BT_MESH_RELAY_NOT_SUPPORTED BT_MESH_FEATURE_NOT_SUPPORTED + +#define BT_MESH_BEACON_DISABLED BT_MESH_FEATURE_DISABLED +#define BT_MESH_BEACON_ENABLED BT_MESH_FEATURE_ENABLED + +#define BT_MESH_GATT_PROXY_DISABLED BT_MESH_FEATURE_DISABLED +#define BT_MESH_GATT_PROXY_ENABLED BT_MESH_FEATURE_ENABLED +#define BT_MESH_GATT_PROXY_NOT_SUPPORTED BT_MESH_FEATURE_NOT_SUPPORTED + +#define BT_MESH_FRIEND_DISABLED BT_MESH_FEATURE_DISABLED +#define BT_MESH_FRIEND_ENABLED BT_MESH_FEATURE_ENABLED +#define BT_MESH_FRIEND_NOT_SUPPORTED BT_MESH_FEATURE_NOT_SUPPORTED + +#define BT_MESH_NODE_IDENTITY_STOPPED BT_MESH_FEATURE_DISABLED +#define BT_MESH_NODE_IDENTITY_RUNNING BT_MESH_FEATURE_ENABLED +#define BT_MESH_NODE_IDENTITY_NOT_SUPPORTED BT_MESH_FEATURE_NOT_SUPPORTED + +/** @brief Enable or disable sending of the Secure Network Beacon. + * + * @param beacon New Secure Network Beacon state. + */ +void bt_mesh_beacon_set(bool beacon); + +/** @brief Get the current Secure Network Beacon state. + * + * @returns Whether the Secure Network Beacon feature is enabled. + */ +bool bt_mesh_beacon_enabled(void); + +/** @brief Set the default TTL value. + * + * The default TTL value is used when no explicit TTL value is set. Models will + * use the default TTL value when @ref bt_mesh_msg_ctx::send_ttl is + * @ref BT_MESH_TTL_DEFAULT. + * + * @param default_ttl The new default TTL value. Valid values are 0x00 and 0x02 + * to @ref BT_MESH_TTL_MAX. + * + * @retval 0 Successfully set the default TTL value. + * @retval -EINVAL Invalid TTL value. + */ +int bt_mesh_default_ttl_set(uint8_t default_ttl); + +/** @brief Get the current default TTL value. + * + * @return The current default TTL value. + */ +uint8_t bt_mesh_default_ttl_get(void); + +/** @brief Set the Network Transmit parameters. + * + * The Network Transmit parameters determine the parameters local messages are + * transmitted with. + * + * @see BT_MESH_TRANSMIT + * + * @param xmit New Network Transmit parameters. Use @ref BT_MESH_TRANSMIT for + * encoding. + */ +void bt_mesh_net_transmit_set(uint8_t xmit); + +/** @brief Get the current Network Transmit parameters. + * + * The @ref BT_MESH_TRANSMIT_COUNT and @ref BT_MESH_TRANSMIT_INT macros can be + * used to decode the Network Transmit parameters. + * + * @return The current Network Transmit parameters. + */ +uint8_t bt_mesh_net_transmit_get(void); + +/** @brief Configure the Relay feature. + * + * Enable or disable the Relay feature, and configure the parameters to + * transmit relayed messages with. + * + * Support for the Relay feature must be enabled through the + * @c CONFIG_BT_MESH_RELAY configuration option. + * + * @see BT_MESH_TRANSMIT + * + * @param relay New Relay feature state. Must be one of + * @ref BT_MESH_FEATURE_ENABLED and + * @ref BT_MESH_FEATURE_DISABLED. + * @param xmit New Relay retransmit parameters. Use @ref BT_MESH_TRANSMIT for + * encoding. + * + * @retval 0 Successfully changed the Relay configuration. + * @retval -ENOTSUP The Relay feature is not supported. + * @retval -EINVAL Invalid parameter. + * @retval -EALREADY Already using the given parameters. + */ +int bt_mesh_relay_set(enum bt_mesh_feat_state relay, uint8_t xmit); + +/** @brief Get the current Relay feature state. + * + * @returns The Relay feature state. + */ +enum bt_mesh_feat_state bt_mesh_relay_get(void); + +/** @brief Get the current Relay Retransmit parameters. + * + * The @ref BT_MESH_TRANSMIT_COUNT and @ref BT_MESH_TRANSMIT_INT macros can be + * used to decode the Relay Retransmit parameters. + * + * @return The current Relay Retransmit parameters, or 0 if relay is not + * supported. + */ +uint8_t bt_mesh_relay_retransmit_get(void); + +/** @brief Enable or disable the GATT Proxy feature. + * + * Support for the GATT Proxy feature must be enabled through the + * @c CONFIG_BT_MESH_GATT_PROXY configuration option. + * + * @note The GATT Proxy feature only controls a Proxy node's ability to relay + * messages to the mesh network. A node that supports GATT Proxy will + * still advertise Connectable Proxy beacons, even if the feature is + * disabled. The Proxy feature can only be fully disabled through compile + * time configuration. + * + * @param gatt_proxy New GATT Proxy state. Must be one of + * @ref BT_MESH_FEATURE_ENABLED and + * @ref BT_MESH_FEATURE_DISABLED. + * + * @retval 0 Successfully changed the GATT Proxy feature state. + * @retval -ENOTSUP The GATT Proxy feature is not supported. + * @retval -EINVAL Invalid parameter. + * @retval -EALREADY Already in the given state. + */ +int bt_mesh_gatt_proxy_set(enum bt_mesh_feat_state gatt_proxy); + +/** @brief Get the current GATT Proxy state. + * + * @returns The GATT Proxy feature state. + */ +enum bt_mesh_feat_state bt_mesh_gatt_proxy_get(void); + +/** @brief Enable or disable the Friend feature. + * + * Any active friendships will be terminated immediately if the Friend feature + * is disabled. + * + * Support for the Friend feature must be enabled through the + * @c CONFIG_BT_MESH_FRIEND configuration option. + * + * @param friendship New Friend feature state. Must be one of + * @ref BT_MESH_FEATURE_ENABLED and + * @ref BT_MESH_FEATURE_DISABLED. + * + * @retval 0 Successfully changed the Friend feature state. + * @retval -ENOTSUP The Friend feature is not supported. + * @retval -EINVAL Invalid parameter. + * @retval -EALREADY Already in the given state. + */ +int bt_mesh_friend_set(enum bt_mesh_feat_state friendship); + +/** @brief Get the current Friend state. + * + * @returns The Friend feature state. + */ +enum bt_mesh_feat_state bt_mesh_friend_get(void); + +/** + * @brief Bluetooth Mesh Subnet Configuration + * @defgroup bt_mesh_cfg_subnet Bluetooth Mesh Subnet Configuration + * @{ + */ + +/** @brief Add a Subnet. + * + * Adds a subnet with the given network index and network key to the list of + * known Subnets. All messages sent on the given Subnet will be processed by + * this node, and the node may send and receive Network Beacons on the given + * Subnet. + * + * @param net_idx Network index. + * @param key Root network key of the Subnet. All other keys are derived + * from this. + * + * @retval STATUS_SUCCESS The Subnet was successfully added. + * @retval STATUS_INSUFF_RESOURCES No room for this Subnet. + * @retval STATUS_UNSPECIFIED The Subnet couldn't be created for some reason. + */ +uint8_t bt_mesh_subnet_add(uint16_t net_idx, const uint8_t key[16]); + +/** @brief Update the given Subnet. + * + * Starts the Key Refresh procedure for this Subnet by adding a second set of + * encryption keys. The Subnet will continue sending with the old key (but + * receiving messages using both) until the Subnet enters Key Refresh phase 2. + * + * This allows a network configurator to replace old network and application + * keys for the entire network, effectively removing access for all nodes that + * aren't given the new keys. + * + * @param net_idx Network index. + * @param key New root network key of the Subnet. + * + * @retval STATUS_SUCCESS The Subnet was updated with a second key. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + * @retval STATUS_IDX_ALREADY_STORED The @c key value is the same as the + * current key. + * @retval STATUS_CANNOT_UPDATE The Subnet cannot be updated for some reason. + */ +uint8_t bt_mesh_subnet_update(uint16_t net_idx, const uint8_t key[16]); + +/** @brief Delete a Subnet. + * + * Removes the Subnet with the given network index from the node. The node will + * stop sending Network Beacons with the given Subnet, and can no longer + * process messages on this Subnet. + * + * All Applications bound to this Subnet are also deleted. + * + * @param net_idx Network index. + * + * @retval STATUS_SUCCESS The Subnet was deleted. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + */ +uint8_t bt_mesh_subnet_del(uint16_t net_idx); + +/** @brief Check whether a Subnet is known. + * + * @param net_idx Network index + * + * @return true if a Subnet with the given index exists, false otherwise. + */ +bool bt_mesh_subnet_exists(uint16_t net_idx); + +/** @brief Set the Subnet's Key Refresh phase. + * + * The Key Refresh procedure is started by updating the Subnet keys through + * @ref bt_mesh_subnet_update. This puts the Subnet in Key Refresh Phase 1. + * Once all nodes have received the new Subnet key, Key Refresh Phase 2 can be + * activated through this function to start transmitting with the new network + * key. Finally, to revoke the old key, set the Key Refresh Phase to 3. This + * removes the old keys from the node, and returns the Subnet back to normal + * single-key operation with the new key set. + * + * @param net_idx Network index. + * @param phase Pointer to the new Key Refresh phase. Will return the actual + * Key Refresh phase after updating. + * + * @retval STATUS_SUCCESS The Key Refresh phase of the Subnet was successfully + * changed. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + * @retval STATUS_CANNOT_UPDATE The given phase change is invalid. + */ +uint8_t bt_mesh_subnet_kr_phase_set(uint16_t net_idx, uint8_t *phase); + +/** @brief Get the Subnet's Key Refresh phase. + * + * @param net_idx Network index. + * @param phase Pointer to the Key Refresh variable to fill. + * + * @retval STATUS_SUCCESS Successfully populated the @c phase variable. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + */ +uint8_t bt_mesh_subnet_kr_phase_get(uint16_t net_idx, uint8_t *phase); + +/** @brief Set the Node Identity state of the Subnet. + * + * The Node Identity state of a Subnet determines whether the Subnet advertises + * connectable Node Identity beacons for Proxy Clients to connect to. + * Once started, the Node Identity beacon runs for 60 seconds, or until it is + * stopped. + * + * This function serves the same purpose as @ref bt_mesh_proxy_identity_enable, + * but only acts on a single Subnet. + * + * GATT Proxy support must be enabled through + * @option{CONFIG_BT_MESH_GATT_PROXY}. + * + * @param net_idx Network index. + * @param node_id New Node Identity state, must be either @ref + * BT_MESH_FEATURE_ENABLED or @ref BT_MESH_FEATURE_DISABLED. + * + * @retval STATUS_SUCCESS Successfully set the Node Identity state of the + * Subnet. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + * @retval STATUS_FEAT_NOT_SUPP The Node Identity feature is not supported. + * @retval STATUS_CANNOT_SET Couldn't set the Node Identity state. + */ +uint8_t bt_mesh_subnet_node_id_set(uint16_t net_idx, + enum bt_mesh_feat_state node_id); + +/** @brief Get the Node Identity state of the Subnet. + * + * @param net_idx Network index. + * @param node_id Node Identity variable to fill. + * + * @retval STATUS_SUCCESS Successfully populated the @c node_id variable. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + */ +uint8_t bt_mesh_subnet_node_id_get(uint16_t net_idx, + enum bt_mesh_feat_state *node_id); + +/** @brief Get a list of all known Subnet indexes. + * + * Builds a list of all known Subnet indexes in the @c net_idxs array. + * If the @c net_idxs array is smaller than the list of known Subnets, this + * function fills all available entries and returns @c -ENOMEM. In this + * case, the next @c max entries of the list can be read out by calling + * @code + * bt_mesh_subnets_get(list, max, max); + * @endcode + * + * Note that any changes to the Subnet list between calls to this function + * could change the order and number of entries in the list. + * + * @param net_idxs Array to fill. + * @param max Max number of indexes to return. + * @param skip Number of indexes to skip. Enables batched processing of the + * list. + * + * @return The number of indexes added to the @c net_idxs array, or @c -ENOMEM + * if the number of known Subnets exceeds the @c max parameter. + */ +ssize_t bt_mesh_subnets_get(uint16_t net_idxs[], size_t max, off_t skip); + +/** + * @} + */ + +/** + * @brief Bluetooth Mesh Application Configuration + * @defgroup bt_mesh_cfg_app Bluetooth Mesh Application Configuration + * @{ + */ + +/** @brief Add an Application key. + * + * Adds the Application with the given index to the list of known applications. + * Allows the node to send and receive model messages encrypted with this + * Application key. + * + * Every Application is bound to a specific Subnet. The node must know the + * Subnet the Application is bound to before it can add the Application. + * + * @param app_idx Application index. + * @param net_idx Network index the Application is bound to. + * @param key Application key value. + * + * @retval STATUS_SUCCESS The Application was successfully added. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + * @retval STATUS_INSUFF_RESOURCES There's no room for storing this + * Application. + * @retval STATUS_INVALID_BINDING This AppIdx is already bound to another + * Subnet. + * @retval STATUS_IDX_ALREADY_STORED This AppIdx is already stored with a + * different key value. + * @retval STATUS_CANNOT_SET Cannot set the Application key for some reason. + */ +uint8_t bt_mesh_app_key_add(uint16_t app_idx, uint16_t net_idx, + const uint8_t key[16]); + +/** @brief Update an Application key. + * + * Update an Application with a second Application key, as part of the + * Key Refresh procedure of the bound Subnet. The node will continue + * transmitting with the old application key (but receiving on both) until the + * Subnet enters Key Refresh phase 2. Once the Subnet enters Key Refresh phase + * 3, the old application key will be deleted. + * + * @note The Application key can only be updated if the bound Subnet is in Key + * Refresh phase 1. + * + * @param app_idx Application index. + * @param net_idx Network index the Application is bound to, or + * @ref BT_MESH_KEY_ANY to skip the binding check. + * @param key New key value. + * + * @retval STATUS_SUCCESS The Application key was successfully updated. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + * @retval STATUS_INVALID_BINDING This AppIdx is not bound to the given NetIdx. + * @retval STATUS_CANNOT_UPDATE The Application key cannot be updated for some + * reason. + * @retval STATUS_IDX_ALREADY_STORED This AppIdx is already updated with a + * different key value. + */ +uint8_t bt_mesh_app_key_update(uint16_t app_idx, uint16_t net_idx, + const uint8_t key[16]); + +/** @brief Delete an Application key. + * + * All models bound to this application will remove this binding. + * All models publishing with this application will stop publishing. + * + * @param app_idx Application index. + * @param net_idx Network index. + * + * @retval STATUS_SUCCESS The Application key was successfully deleted. + * @retval STATUS_INVALID_NETKEY The NetIdx is unknown. + * @retval STATUS_INVALID_BINDING This AppIdx is not bound to the given NetIdx. + */ +uint8_t bt_mesh_app_key_del(uint16_t app_idx, uint16_t net_idx); + +/** @brief Check if an Application key is known. + * + * @param app_idx Application index. + * + * @return true if the Application is known, false otherwise. + */ +bool bt_mesh_app_key_exists(uint16_t app_idx); + +/** @brief Get a list of all known Application key indexes. + * + * Builds a list of all Application indexes for the given network index in the + * @c app_idxs array. If the @c app_idxs array cannot fit all bound + * Applications, this function fills all available entries and returns @c + * -ENOMEM. In this case, the next @c max entries of the list can be read out + * by calling + * @code + * bt_mesh_app_keys_get(net_idx, list, max, max); + * @endcode + * + * Note that any changes to the Application key list between calls to this + * function could change the order and number of entries in the list. + * + * @param net_idx Network Index to get the Applications of, or @ref + * BT_MESH_KEY_ANY to get all Applications. + * @param app_idxs Array to fill. + * @param max Max number of indexes to return. + * @param skip Number of indexes to skip. Enables batched processing of the + * list. + * + * @return The number of indexes added to the @c app_idxs array, or @c -ENOMEM + * if the number of known Applications exceeds the @c max parameter. + */ +ssize_t bt_mesh_app_keys_get(uint16_t net_idx, uint16_t app_idxs[], size_t max, + off_t skip); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* _BT_MESH_CFG_H_ */
\ No newline at end of file diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_cli.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_cli.h index 7dc237be..bd2f9fe5 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_cli.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_cli.h @@ -26,7 +26,7 @@ struct bt_mesh_cfg_cli { struct bt_mesh_model *model; struct k_sem op_sync; - u32_t op_pending; + uint32_t op_pending; void *op_param; }; @@ -37,45 +37,81 @@ extern const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb; BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_op, NULL, \ cli_data, &bt_mesh_cfg_cli_cb) -int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page, - u8_t *status, struct os_mbuf *comp); +int bt_mesh_cfg_node_reset(uint16_t net_idx, uint16_t addr, bool *status); -int bt_mesh_cfg_beacon_get(u16_t net_idx, u16_t addr, u8_t *status); +int bt_mesh_cfg_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, + uint8_t *status, struct os_mbuf *comp); -int bt_mesh_cfg_beacon_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status); +int bt_mesh_cfg_beacon_get(uint16_t net_idx, uint16_t addr, uint8_t *status); -int bt_mesh_cfg_ttl_get(u16_t net_idx, u16_t addr, u8_t *ttl); +int bt_mesh_cfg_beacon_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status); -int bt_mesh_cfg_ttl_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *ttl); +int bt_mesh_cfg_ttl_get(uint16_t net_idx, uint16_t addr, uint8_t *ttl); -int bt_mesh_cfg_friend_get(u16_t net_idx, u16_t addr, u8_t *status); +int bt_mesh_cfg_ttl_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *ttl); -int bt_mesh_cfg_friend_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status); +int bt_mesh_cfg_friend_get(uint16_t net_idx, uint16_t addr, uint8_t *status); -int bt_mesh_cfg_gatt_proxy_get(u16_t net_idx, u16_t addr, u8_t *status); +int bt_mesh_cfg_friend_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status); -int bt_mesh_cfg_gatt_proxy_set(u16_t net_idx, u16_t addr, u8_t val, - u8_t *status); +int bt_mesh_cfg_gatt_proxy_get(uint16_t net_idx, uint16_t addr, uint8_t *status); -int bt_mesh_cfg_relay_get(u16_t net_idx, u16_t addr, u8_t *status, - u8_t *transmit); +int bt_mesh_cfg_gatt_proxy_set(uint16_t net_idx, uint16_t addr, uint8_t val, + uint8_t *status); -int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay, - u8_t new_transmit, u8_t *status, u8_t *transmit); +int bt_mesh_cfg_net_transmit_get(uint16_t net_idx, uint16_t addr, + uint8_t *transmit); -int bt_mesh_cfg_net_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx, - const u8_t net_key[16], u8_t *status); +int bt_mesh_cfg_net_transmit_set(uint16_t net_idx, uint16_t addr, + uint8_t val, uint8_t *transmit); -int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx, - u16_t key_app_idx, const u8_t app_key[16], - u8_t *status); +int bt_mesh_cfg_relay_get(uint16_t net_idx, uint16_t addr, uint8_t *status, + uint8_t *transmit); -int bt_mesh_cfg_mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t mod_app_idx, u16_t mod_id, u8_t *status); +int bt_mesh_cfg_relay_set(uint16_t net_idx, uint16_t addr, uint8_t new_relay, + uint8_t new_transmit, uint8_t *status, uint8_t *transmit); -int bt_mesh_cfg_mod_app_bind_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t mod_app_idx, u16_t mod_id, u16_t cid, - u8_t *status); +int bt_mesh_cfg_net_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, + const uint8_t net_key[16], uint8_t *status); + +int bt_mesh_cfg_net_key_get(uint16_t net_idx, uint16_t addr, uint16_t *keys, + size_t *key_cnt); + +int bt_mesh_cfg_net_key_del(uint16_t net_idx, uint16_t addr, + uint16_t key_net_idx, uint8_t *status); + +int bt_mesh_cfg_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, + uint16_t key_app_idx, const uint8_t app_key[16], + uint8_t *status); + +int bt_mesh_cfg_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, + uint8_t *status, uint16_t *keys, size_t *key_cnt); + +int bt_mesh_cfg_app_key_del(uint16_t net_idx, uint16_t addr, + uint16_t key_net_idx, uint16_t key_app_idx, uint8_t *status); + +int bt_mesh_cfg_mod_app_bind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_app_idx, uint16_t mod_id, uint8_t *status); + +int bt_mesh_cfg_mod_app_unbind(uint16_t net_idx, uint16_t addr, + uint16_t elem_addr, uint16_t mod_app_idx, + uint16_t mod_id, uint8_t *status); + +int bt_mesh_cfg_mod_app_bind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_app_idx, uint16_t mod_id, uint16_t cid, + uint8_t *status); + +int bt_mesh_cfg_mod_app_unbind_vnd(uint16_t net_idx, uint16_t addr, + uint16_t elem_addr, uint16_t mod_app_idx, uint16_t mod_id, + uint16_t cid, uint8_t *status); + +int bt_mesh_cfg_mod_app_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, uint8_t *status, uint16_t *apps, + size_t *app_cnt); + +int bt_mesh_cfg_mod_app_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, uint16_t cid, uint8_t *status, + uint16_t *apps, size_t *app_cnt); /** @def BT_MESH_PUB_PERIOD_100MS * @@ -120,109 +156,117 @@ int bt_mesh_cfg_mod_app_bind_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, #define BT_MESH_PUB_PERIOD_10MIN(steps) (((steps) & BIT_MASK(6)) | (3 << 6)) struct bt_mesh_cfg_mod_pub { - u16_t addr; - u16_t app_idx; + uint16_t addr; + uint16_t app_idx; bool cred_flag; - u8_t ttl; - u8_t period; - u8_t transmit; + uint8_t ttl; + uint8_t period; + uint8_t transmit; }; -int bt_mesh_cfg_mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t mod_id, struct bt_mesh_cfg_mod_pub *pub, - u8_t *status); +int bt_mesh_cfg_mod_pub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, struct bt_mesh_cfg_mod_pub *pub, + uint8_t *status); + +int bt_mesh_cfg_mod_pub_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, uint16_t cid, + struct bt_mesh_cfg_mod_pub *pub, uint8_t *status); + +int bt_mesh_cfg_mod_pub_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, struct bt_mesh_cfg_mod_pub *pub, + uint8_t *status); -int bt_mesh_cfg_mod_pub_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t mod_id, u16_t cid, - struct bt_mesh_cfg_mod_pub *pub, u8_t *status); +int bt_mesh_cfg_mod_pub_set_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, uint16_t cid, + struct bt_mesh_cfg_mod_pub *pub, uint8_t *status); -int bt_mesh_cfg_mod_pub_set(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t mod_id, struct bt_mesh_cfg_mod_pub *pub, - u8_t *status); +int bt_mesh_cfg_mod_sub_add(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t sub_addr, uint16_t mod_id, uint8_t *status); -int bt_mesh_cfg_mod_pub_set_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t mod_id, u16_t cid, - struct bt_mesh_cfg_mod_pub *pub, u8_t *status); +int bt_mesh_cfg_mod_sub_add_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t sub_addr, uint16_t mod_id, uint16_t cid, + uint8_t *status); -int bt_mesh_cfg_mod_sub_add(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u8_t *status); +int bt_mesh_cfg_mod_sub_del(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t sub_addr, uint16_t mod_id, uint8_t *status); -int bt_mesh_cfg_mod_sub_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid, - u8_t *status); +int bt_mesh_cfg_mod_sub_del_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t sub_addr, uint16_t mod_id, uint16_t cid, + uint8_t *status); -int bt_mesh_cfg_mod_sub_del(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u8_t *status); +int bt_mesh_cfg_mod_sub_overwrite(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t sub_addr, uint16_t mod_id, uint8_t *status); -int bt_mesh_cfg_mod_sub_del_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid, - u8_t *status); +int bt_mesh_cfg_mod_sub_overwrite_vnd(uint16_t net_idx, uint16_t addr, + uint16_t elem_addr, uint16_t sub_addr, + uint16_t mod_id, uint16_t cid, uint8_t *status); -int bt_mesh_cfg_mod_sub_overwrite(u16_t net_idx, u16_t addr, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u8_t *status); +int bt_mesh_cfg_mod_sub_va_add(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + const uint8_t label[16], uint16_t mod_id, + uint16_t *virt_addr, uint8_t *status); -int bt_mesh_cfg_mod_sub_overwrite_vnd(u16_t net_idx, u16_t addr, - u16_t elem_addr, u16_t sub_addr, - u16_t mod_id, u16_t cid, u8_t *status); +int bt_mesh_cfg_mod_sub_va_add_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + const uint8_t label[16], uint16_t mod_id, + uint16_t cid, uint16_t *virt_addr, uint8_t *status); -int bt_mesh_cfg_mod_sub_va_add(u16_t net_idx, u16_t addr, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, - u16_t *virt_addr, u8_t *status); +int bt_mesh_cfg_mod_sub_va_del(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + const uint8_t label[16], uint16_t mod_id, + uint16_t *virt_addr, uint8_t *status); -int bt_mesh_cfg_mod_sub_va_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, - u16_t cid, u16_t *virt_addr, u8_t *status); +int bt_mesh_cfg_mod_sub_va_del_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + const uint8_t label[16], uint16_t mod_id, + uint16_t cid, uint16_t *virt_addr, uint8_t *status); -int bt_mesh_cfg_mod_sub_va_del(u16_t net_idx, u16_t addr, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, - u16_t *virt_addr, u8_t *status); +int bt_mesh_cfg_mod_sub_va_overwrite(uint16_t net_idx, uint16_t addr, + uint16_t elem_addr, const uint8_t label[16], + uint16_t mod_id, uint16_t *virt_addr, + uint8_t *status); -int bt_mesh_cfg_mod_sub_va_del_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, - u16_t cid, u16_t *virt_addr, u8_t *status); +int bt_mesh_cfg_mod_sub_va_overwrite_vnd(uint16_t net_idx, uint16_t addr, + uint16_t elem_addr, const uint8_t label[16], + uint16_t mod_id, uint16_t cid, + uint16_t *virt_addr, uint8_t *status); -int bt_mesh_cfg_mod_sub_va_overwrite(u16_t net_idx, u16_t addr, - u16_t elem_addr, const u8_t label[16], - u16_t mod_id, u16_t *virt_addr, - u8_t *status); +int bt_mesh_cfg_mod_sub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, uint8_t *status, uint16_t *subs, + size_t *sub_cnt); -int bt_mesh_cfg_mod_sub_va_overwrite_vnd(u16_t net_idx, u16_t addr, - u16_t elem_addr, const u8_t label[16], - u16_t mod_id, u16_t cid, - u16_t *virt_addr, u8_t *status); +int bt_mesh_cfg_mod_sub_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, + uint16_t mod_id, uint16_t cid, uint8_t *status, + uint16_t *subs, size_t *sub_cnt); struct bt_mesh_cfg_hb_sub { - u16_t src; - u16_t dst; - u8_t period; - u8_t count; - u8_t min; - u8_t max; + uint16_t src; + uint16_t dst; + uint8_t period; + uint8_t count; + uint8_t min; + uint8_t max; }; -int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr, - struct bt_mesh_cfg_hb_sub *sub, u8_t *status); +int bt_mesh_cfg_hb_sub_set(uint16_t net_idx, uint16_t addr, + struct bt_mesh_cfg_hb_sub *sub, uint8_t *status); -int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr, - struct bt_mesh_cfg_hb_sub *sub, u8_t *status); +int bt_mesh_cfg_hb_sub_get(uint16_t net_idx, uint16_t addr, + struct bt_mesh_cfg_hb_sub *sub, uint8_t *status); struct bt_mesh_cfg_hb_pub { - u16_t dst; - u8_t count; - u8_t period; - u8_t ttl; - u16_t feat; - u16_t net_idx; + uint16_t dst; + uint8_t count; + uint8_t period; + uint8_t ttl; + uint16_t feat; + uint16_t net_idx; }; -int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, - const struct bt_mesh_cfg_hb_pub *pub, u8_t *status); +int bt_mesh_cfg_hb_pub_set(uint16_t net_idx, uint16_t addr, + const struct bt_mesh_cfg_hb_pub *pub, uint8_t *status); -int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, - struct bt_mesh_cfg_hb_pub *pub, u8_t *status); +int bt_mesh_cfg_hb_pub_get(uint16_t net_idx, uint16_t addr, + struct bt_mesh_cfg_hb_pub *pub, uint8_t *status); -s32_t bt_mesh_cfg_cli_timeout_get(void); -void bt_mesh_cfg_cli_timeout_set(s32_t timeout); +int32_t bt_mesh_cfg_cli_timeout_get(void); +void bt_mesh_cfg_cli_timeout_set(int32_t timeout); #ifdef __cplusplus } diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_srv.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_srv.h index 14d8a295..5bf3f439 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_srv.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_srv.h @@ -21,51 +21,13 @@ extern "C" { #endif -/** Mesh Configuration Server Model Context */ -struct bt_mesh_cfg_srv { - struct bt_mesh_model *model; - - u8_t net_transmit; /* Network Transmit state */ - u8_t relay; /* Relay Mode state */ - u8_t relay_retransmit; /* Relay Retransmit state */ - u8_t beacon; /* Secure Network Beacon state */ - u8_t gatt_proxy; /* GATT Proxy state */ - u8_t frnd; /* Friend state */ - u8_t default_ttl; /* Default TTL */ - - /* Heartbeat Publication */ - struct bt_mesh_hb_pub { - struct k_delayed_work timer; - - u16_t dst; - u16_t count; - u8_t period; - u8_t ttl; - u16_t feat; - u16_t net_idx; - } hb_pub; - - /* Heartbeat Subscription */ - struct bt_mesh_hb_sub { - s64_t expiry; - - u16_t src; - u16_t dst; - u16_t count; - u8_t min_hops; - u8_t max_hops; - - /* Optional subscription tracking function */ - void (*func)(u8_t hops, u16_t feat); - } hb_sub; -}; extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; extern const struct bt_mesh_model_cb bt_mesh_cfg_srv_cb; -#define BT_MESH_MODEL_CFG_SRV(srv_data) \ +#define BT_MESH_MODEL_CFG_SRV \ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_op, NULL, \ - srv_data, &bt_mesh_cfg_srv_cb) + NULL, &bt_mesh_cfg_srv_cb) #ifdef __cplusplus } diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/glue.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/glue.h index e37fcfbc..abe3dd53 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/glue.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/glue.h @@ -51,15 +51,6 @@ extern "C" { #endif -#define u8_t uint8_t -#define s8_t int8_t -#define u16_t uint16_t -#define s16_t int16_t -#define u32_t uint32_t -#define u64_t uint64_t -#define s64_t int64_t -#define s32_t int32_t - /** @brief Helper to declare elements of bt_data arrays * * This macro is mainly for creating an array of struct bt_data @@ -73,7 +64,7 @@ extern "C" { { \ .type = (_type), \ .data_len = (_data_len), \ - .data = (const u8_t *)(_data), \ + .data = (const uint8_t *)(_data), \ } /** @brief Helper to declare elements of bt_data arrays @@ -85,8 +76,8 @@ extern "C" { * @param _bytes Variable number of single-byte parameters */ #define BT_DATA_BYTES(_type, _bytes...) \ - BT_DATA(_type, ((u8_t []) { _bytes }), \ - sizeof((u8_t []) { _bytes })) + BT_DATA(_type, ((uint8_t []) { _bytes }), \ + sizeof((uint8_t []) { _bytes })) /* EIR/AD data type definitions */ #define BT_DATA_FLAGS 0x01 /* AD flags */ @@ -119,9 +110,13 @@ extern "C" { #define sys_put_be16(a,b) put_be16(b, a) #define sys_put_le16(a,b) put_le16(b, a) +#define sys_put_le24(a,b) put_le24(b, a) +#define sys_put_be24(a,b) put_be24(b, a) #define sys_put_be32(a,b) put_be32(b, a) #define sys_get_be16(a) get_be16(a) +#define sys_get_be24(a) get_be24(a) #define sys_get_le16(a) get_le16(a) +#define sys_get_le24(a) get_le24(a) #define sys_get_be32(a) get_be32(a) #define sys_cpu_to_be16(a) htobe16(a) #define sys_cpu_to_be32(a) htobe32(a) @@ -196,9 +191,9 @@ typedef ble_addr_t bt_addr_le_t; struct net_buf_simple_state { /** Offset of the data pointer from the beginning of the storage */ - u16_t offset; + uint16_t offset; /** Length of data */ - u16_t len; + uint16_t len; }; static inline struct os_mbuf * NET_BUF_SIMPLE(uint16_t size) @@ -238,6 +233,14 @@ static inline void net_buf_simple_init(struct os_mbuf *buf, buf->om_len = 0; } +#define net_buf_simple_init_with_data(buf, data, size) \ + os_mbuf_copyinto(buf, 0, data, size); + +static inline void net_buf_simple_reset(struct os_mbuf *om) +{ + net_buf_simple_init(om, 0); +} + void net_buf_put(struct ble_npl_eventq *fifo, struct os_mbuf *buf); void * net_buf_ref(struct os_mbuf *om); void net_buf_unref(struct os_mbuf *om); @@ -248,18 +251,20 @@ uint32_t net_buf_simple_pull_le32(struct os_mbuf *om); uint8_t net_buf_simple_pull_u8(struct os_mbuf *om); void net_buf_simple_add_le16(struct os_mbuf *om, uint16_t val); void net_buf_simple_add_be16(struct os_mbuf *om, uint16_t val); +void net_buf_simple_add_le24(struct os_mbuf *om, uint32_t val); void net_buf_simple_add_u8(struct os_mbuf *om, uint8_t val); void net_buf_simple_add_be32(struct os_mbuf *om, uint32_t val); void net_buf_simple_add_le32(struct os_mbuf *om, uint32_t val); void net_buf_add_zeros(struct os_mbuf *om, uint8_t len); void net_buf_simple_push_le16(struct os_mbuf *om, uint16_t val); void net_buf_simple_push_be16(struct os_mbuf *om, uint16_t val); +void net_buf_simple_push_be24(struct os_mbuf *om, uint32_t val); void net_buf_simple_push_u8(struct os_mbuf *om, uint8_t val); void *net_buf_simple_pull(struct os_mbuf *om, uint8_t len); void *net_buf_simple_pull_mem(struct os_mbuf *om, uint8_t len); void *net_buf_simple_add(struct os_mbuf *om, uint8_t len); bool k_fifo_is_empty(struct ble_npl_eventq *q); -void *net_buf_get(struct ble_npl_eventq *fifo,s32_t t); +void *net_buf_get(struct ble_npl_eventq *fifo,int32_t t); uint8_t *net_buf_simple_push(struct os_mbuf *om, uint8_t len); void net_buf_reserve(struct os_mbuf *om, size_t reserve); @@ -271,7 +276,7 @@ void net_buf_reserve(struct os_mbuf *om, size_t reserve); #define net_buf_clone(a, b) os_mbuf_dup(a) #define net_buf_add_be32(a, b) net_buf_simple_add_be32(a, b) #define net_buf_add_be16(a, b) net_buf_simple_add_be16(a, b) -#define net_buf_pull(a, b) net_buf_simple_pull(a, b) +#define net_buf_pull(a, b) net_buf_simple_pull_mem(a, b) #define net_buf_pull_mem(a, b) net_buf_simple_pull_mem(a, b) #define net_buf_pull_u8(a) net_buf_simple_pull_u8(a) #define net_buf_pull_be16(a) net_buf_simple_pull_be16(a) @@ -279,14 +284,16 @@ void net_buf_reserve(struct os_mbuf *om, size_t reserve); #define BT_GATT_CCC_NOTIFY BLE_GATT_CHR_PROP_NOTIFY +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) /** Description of different data types that can be encoded into * advertising data. Used to form arrays that are passed to the * bt_le_adv_start() function. */ struct bt_data { - u8_t type; - u8_t data_len; - const u8_t *data; + uint8_t type; + uint8_t data_len; + const uint8_t *data; }; struct bt_pub_key_cb { @@ -298,18 +305,24 @@ struct bt_pub_key_cb { * * @param key The local public key, or NULL in case of no key. */ - void (*func)(const u8_t key[64]); + void (*func)(const uint8_t key[64]); struct bt_pub_key_cb *_next; }; -typedef void (*bt_dh_key_cb_t)(const u8_t key[32]); -int bt_dh_key_gen(const u8_t remote_pk[64], bt_dh_key_cb_t cb); +typedef void (*bt_dh_key_cb_t)(const uint8_t key[32]); +int bt_dh_key_gen(const uint8_t remote_pk[64], bt_dh_key_cb_t cb); int bt_pub_key_gen(struct bt_pub_key_cb *new_cb); uint8_t *bt_pub_key_get(void); int bt_rand(void *buf, size_t len); const char * bt_hex(const void *buf, size_t len); int bt_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *enc_data); +int bt_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *enc_data, + size_t len, const uint8_t *aad, size_t aad_len, + uint8_t *plaintext, size_t mic_size); +int bt_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t *enc_data, + size_t len, const uint8_t *aad, size_t aad_len, + uint8_t *plaintext, size_t mic_size); void bt_mesh_register_gatt(void); int bt_le_adv_start(const struct ble_gap_adv_params *param, const struct bt_data *ad, size_t ad_len, @@ -323,9 +336,10 @@ struct k_delayed_work { void k_work_init(struct ble_npl_callout *work, ble_npl_event_fn handler); void k_delayed_work_init(struct k_delayed_work *w, ble_npl_event_fn *f); void k_delayed_work_cancel(struct k_delayed_work *w); +bool k_delayed_work_pending(struct k_delayed_work *w); void k_delayed_work_submit(struct k_delayed_work *w, uint32_t ms); int64_t k_uptime_get(void); -u32_t k_uptime_get_32(void); +uint32_t k_uptime_get_32(void); void k_sleep(int32_t duration); void k_work_submit(struct ble_npl_callout *w); void k_work_add_arg(struct ble_npl_callout *w, void *arg); @@ -355,18 +369,18 @@ static inline void sys_memcpy_swap(void *dst, const void *src, size_t length) src += length - 1; for (; length > 0; length--) { - *((u8_t *)dst++) = *((u8_t *)src--); + *((uint8_t *)dst++) = *((uint8_t *)src--); } } #define popcount(x) __builtin_popcount(x) -static inline unsigned int find_lsb_set(u32_t op) +static inline unsigned int find_lsb_set(uint32_t op) { return __builtin_ffs(op); } -static inline unsigned int find_msb_set(u32_t op) +static inline unsigned int find_msb_set(uint32_t op) { if (!op) return 0; @@ -374,43 +388,61 @@ static inline unsigned int find_msb_set(u32_t op) return 32 - __builtin_clz(op); } -#define CONFIG_BT_MESH_FRIEND BLE_MESH_FRIEND -#define CONFIG_BT_MESH_GATT_PROXY BLE_MESH_GATT_PROXY -#define CONFIG_BT_MESH_IV_UPDATE_TEST BLE_MESH_IV_UPDATE_TEST -#define CONFIG_BT_MESH_LOW_POWER BLE_MESH_LOW_POWER -#define CONFIG_BT_MESH_LPN_AUTO BLE_MESH_LPN_AUTO -#define CONFIG_BT_MESH_LPN_ESTABLISHMENT BLE_MESH_LPN_ESTABLISHMENT -#define CONFIG_BT_MESH_PB_ADV BLE_MESH_PB_ADV -#define CONFIG_BT_MESH_PB_GATT BLE_MESH_PB_GATT -#define CONFIG_BT_MESH_PROV BLE_MESH_PROV -#define CONFIG_BT_MESH_PROXY BLE_MESH_PROXY -#define CONFIG_BT_TESTING BLE_MESH_TESTING -#define CONFIG_BT_SETTINGS BLE_MESH_SETTINGS -#define CONFIG_SETTINGS BLE_MESH_SETTINGS -#define CONFIG_BT_MESH_PROVISIONER BLE_MESH_PROVISIONER +#define CONFIG_BT_MESH_FRIEND BLE_MESH_FRIEND +#define CONFIG_BT_MESH_GATT_PROXY BLE_MESH_GATT_PROXY +#define CONFIG_BT_MESH_IV_UPDATE_TEST BLE_MESH_IV_UPDATE_TEST +#define CONFIG_BT_MESH_LOW_POWER BLE_MESH_LOW_POWER +#define CONFIG_BT_MESH_LPN_SUB_ALL_NODES_ADDR BLE_MESH_LPN_SUB_ALL_NODES_ADDR +#define CONFIG_BT_MESH_LPN_AUTO BLE_MESH_LPN_AUTO +#define CONFIG_BT_MESH_LPN_ESTABLISHMENT BLE_MESH_LPN_ESTABLISHMENT +#define CONFIG_BT_MESH_PB_ADV BLE_MESH_PB_ADV +#define CONFIG_BT_MESH_PB_GATT BLE_MESH_PB_GATT +#define CONFIG_BT_MESH_PROV BLE_MESH_PROV +#define CONFIG_BT_MESH_PROXY BLE_MESH_PROXY +#define CONFIG_BT_TESTING BLE_MESH_TESTING +#define CONFIG_BT_SETTINGS BLE_MESH_SETTINGS +#define CONFIG_SETTINGS BLE_MESH_SETTINGS +#define CONFIG_BT_MESH_PROVISIONER BLE_MESH_PROVISIONER +#define CONFIG_BT_MESH_PROV_DEVICE BLE_MESH_PROV_DEVICE /* Above flags are used with IS_ENABLED macro */ #define IS_ENABLED(config) MYNEWT_VAL(config) -#define CONFIG_BT_MESH_LPN_GROUPS MYNEWT_VAL(BLE_MESH_LPN_GROUPS) -#define CONFIG_BT_MESH_ADV_BUF_COUNT MYNEWT_VAL(BLE_MESH_ADV_BUF_COUNT) -#define CONFIG_BT_MESH_FRIEND_QUEUE_SIZE MYNEWT_VAL(BLE_MESH_FRIEND_QUEUE_SIZE) -#define CONFIG_BT_MESH_FRIEND_RECV_WIN MYNEWT_VAL(BLE_MESH_FRIEND_RECV_WIN) -#define CONFIG_BT_MESH_LPN_POLL_TIMEOUT MYNEWT_VAL(BLE_MESH_LPN_POLL_TIMEOUT) -#define CONFIG_BT_MESH_MODEL_GROUP_COUNT MYNEWT_VAL(BLE_MESH_MODEL_GROUP_COUNT) -#define CONFIG_BT_MESH_MODEL_KEY_COUNT MYNEWT_VAL(BLE_MESH_MODEL_KEY_COUNT) -#define CONFIG_BT_MESH_NODE_ID_TIMEOUT MYNEWT_VAL(BLE_MESH_NODE_ID_TIMEOUT) -#define CONFIG_BT_MAX_CONN MYNEWT_VAL(BLE_MAX_CONNECTIONS) -#define CONFIG_BT_MESH_SEQ_STORE_RATE MYNEWT_VAL(BLE_MESH_SEQ_STORE_RATE) -#define CONFIG_BT_MESH_RPL_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_RPL_STORE_TIMEOUT) -#define CONFIG_BT_MESH_APP_KEY_COUNT MYNEWT_VAL(BLE_MESH_APP_KEY_COUNT) -#define CONFIG_BT_MESH_SUBNET_COUNT MYNEWT_VAL(BLE_MESH_SUBNET_COUNT) -#define CONFIG_BT_MESH_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_STORE_TIMEOUT) -#define CONFIG_BT_MESH_IVU_DIVIDER MYNEWT_VAL(BLE_MESH_IVU_DIVIDER) -#define CONFIG_BT_DEVICE_NAME MYNEWT_VAL(BLE_MESH_DEVICE_NAME) -#define CONFIG_BT_MESH_TX_SEG_MAX MYNEWT_VAL(BLE_MESH_TX_SEG_MAX) -#define CONFIG_BT_MESH_LABEL_COUNT MYNEWT_VAL(BLE_MESH_LABEL_COUNT) -#define CONFIG_BT_MESH_NODE_COUNT MYNEWT_VAL(BLE_MESH_NODE_COUNT) +#define CONFIG_BT_MESH_LPN_GROUPS MYNEWT_VAL(BLE_MESH_LPN_GROUPS) +#define CONFIG_BT_MESH_ADV_BUF_COUNT MYNEWT_VAL(BLE_MESH_ADV_BUF_COUNT) +#define CONFIG_BT_MESH_SEG_BUFS MYNEWT_VAL(BLE_MESH_SEG_BUFS ) +#define CONFIG_BT_MESH_FRIEND_QUEUE_SIZE MYNEWT_VAL(BLE_MESH_FRIEND_QUEUE_SIZE) +#define CONFIG_BT_MESH_FRIEND_RECV_WIN MYNEWT_VAL(BLE_MESH_FRIEND_RECV_WIN) +#define CONFIG_BT_MESH_LPN_POLL_TIMEOUT MYNEWT_VAL(BLE_MESH_LPN_POLL_TIMEOUT) +#define CONFIG_BT_MESH_MODEL_GROUP_COUNT MYNEWT_VAL(BLE_MESH_MODEL_GROUP_COUNT) +#define CONFIG_BT_MESH_MODEL_KEY_COUNT MYNEWT_VAL(BLE_MESH_MODEL_KEY_COUNT) +#define CONFIG_BT_MESH_NODE_ID_TIMEOUT MYNEWT_VAL(BLE_MESH_NODE_ID_TIMEOUT) +#define CONFIG_BT_MAX_CONN MYNEWT_VAL(BLE_MAX_CONNECTIONS) +#define CONFIG_BT_MESH_SEQ_STORE_RATE MYNEWT_VAL(BLE_MESH_SEQ_STORE_RATE) +#define CONFIG_BT_MESH_RPL_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_RPL_STORE_TIMEOUT) +#define CONFIG_BT_MESH_APP_KEY_COUNT MYNEWT_VAL(BLE_MESH_APP_KEY_COUNT) +#define CONFIG_BT_MESH_SUBNET_COUNT MYNEWT_VAL(BLE_MESH_SUBNET_COUNT) +#define CONFIG_BT_MESH_STORE_TIMEOUT MYNEWT_VAL(BLE_MESH_STORE_TIMEOUT) +#define CONFIG_BT_MESH_IVU_DIVIDER MYNEWT_VAL(BLE_MESH_IVU_DIVIDER) +#define CONFIG_BT_DEVICE_NAME MYNEWT_VAL(BLE_MESH_DEVICE_NAME) +#define CONFIG_BT_RX_SEG_MAX MYNEWT_VAL(BLE_MESH_RX_SEG_MAX) +#define CONFIG_BT_MESH_TX_SEG_MAX MYNEWT_VAL(BLE_MESH_TX_SEG_MAX) +#define CONFIG_BT_MESH_RX_SEG_MAX MYNEWT_VAL(BLE_MESH_RX_SEG_MAX) +#define CONFIG_BT_MESH_RX_SEG_MSG_COUNT MYNEWT_VAL(BLE_MESH_RX_SEG_MSG_COUNT) +#define CONFIG_BT_MESH_LABEL_COUNT MYNEWT_VAL(BLE_MESH_LABEL_COUNT) +#define CONFIG_BT_MESH_NODE_COUNT MYNEWT_VAL(BLE_MESH_CDB_NODE_COUNT) +#define CONFIG_BT_GATT_PROXY_ENABLED MYNEWT_VAL(BLE_MESH_GATT_PROXY_ENABLED) +#define CONFIG_BT_MESH_DEFAULT_TTL MYNEWT_VAL(BLE_MESH_DEFAULT_TTL) +#define CONFIG_BT_MESH_NETWORK_TRANSMIT_COUNT MYNEWT_VAL(BLE_MESH_NETWORK_TRANSMIT_COUNT) +#define CONFIG_BT_MESH_NETWORK_TRANSMIT_INTERVAL MYNEWT_VAL(BLE_MESH_NETWORK_TRANSMIT_INTERVAL) +#define CONFIG_BT_MESH_RELAY_ENABLED MYNEWT_VAL(BLE_MESH_RELAY_ENABLED) +#define CONFIG_BT_MESH_RELAY_RETRANSMIT_INTERVAL MYNEWT_VAL(BLE_MESH_RELAY_RETRANSMIT_INTERVAL) +#define CONFIG_BT_MESH_BEACON_ENABLED MYNEWT_VAL(BLE_MESH_BEACON_ENABLED) +#define CONFIG_BT_MESH_FRIEND_ENABLED MYNEWT_VAL(BLE_MESH_FRIEND_ENABLED) +#define CONFIG_BT_MESH_RELAY MYNEWT_VAL(BLE_MESH_RELAY) +#define CONFIG_BT_MESH_RELAY_RETRANSMIT_COUNT MYNEWT_VAL(BLE_MESH_RELAY_RETRANSMIT_COUNT) +#define CONFIG_BT_MESH_GATT_PROXY_ENABLED MYNEWT_VAL(BLE_MESH_GATT_PROXY_ENABLED) +#define CONFIG_BT_MESH_CDB BLE_MESH_CDB #define printk console_printf @@ -426,7 +458,7 @@ static inline void k_sem_init(struct k_sem *sem, unsigned int initial_count, ble_npl_sem_init(sem, initial_count); } -static inline int k_sem_take(struct k_sem *sem, s32_t timeout) +static inline int k_sem_take(struct k_sem *sem, int32_t timeout) { uint32_t ticks; @@ -448,8 +480,8 @@ static inline void k_sem_give(struct k_sem *sem) static inline int net_buf_id(struct os_mbuf *buf) { struct os_mbuf_pool *pool = buf->om_omp; - u8_t *pool_start = (u8_t *)pool->omp_pool->mp_membuf_addr; - u8_t *buf_ptr = (u8_t *)buf; + uint8_t *pool_start = (uint8_t *)pool->omp_pool->mp_membuf_addr; + uint8_t *buf_ptr = (uint8_t *)buf; return (buf_ptr - pool_start) / BUF_SIZE(pool); } @@ -495,6 +527,46 @@ settings_load(void) #define BUILD_ASSERT(cond) _Static_assert(cond, "") + +/* Memory slabs/blocks */ + +/** Memory slab structure */ +struct k_mem_slab { + /** + * _wait_q_t is not required now, as we don't implement zephyr timeouts - + * if slab couldn't be allocated, we simply return error + */ + uint32_t num_blocks; /** number of memory blocks available for allocation */ + size_t block_size; /** size of single block */ + /** + * buffer for blocks - must be alligned to N-byte, where N is a power of 2. + * Minimal size of buffer is num_blocks * block_size + */ + char *buffer; + char *free_list; /** list of free memory blocks */ + uint32_t num_used; /** count of used memory blocks */ +}; + +struct k_mem_block_id { + uint32_t pool : 8; + uint32_t level : 4; + uint32_t block : 20; +}; + +struct k_mem_block { + void *data; + struct k_mem_block_id id; +}; + +extern void k_mem_slab_free(struct k_mem_slab *slab, void **mem); +extern int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem); +static inline uint32_t k_mem_slab_num_free_get(struct k_mem_slab *slab) +{ + return slab->num_blocks - slab->num_used; +} + +int create_free_list(struct k_mem_slab *slab); + #ifdef __cplusplus } #endif diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_cli.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_cli.h index 8ab8d6d5..e9efe4b1 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_cli.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_cli.h @@ -25,12 +25,12 @@ extern "C" { struct bt_mesh_health_cli { struct bt_mesh_model *model; - void (*current_status)(struct bt_mesh_health_cli *cli, u16_t addr, - u8_t test_id, u16_t cid, u8_t *faults, + void (*current_status)(struct bt_mesh_health_cli *cli, uint16_t addr, + uint8_t test_id, uint16_t cid, uint8_t *faults, size_t fault_count); struct k_sem op_sync; - u32_t op_pending; + uint32_t op_pending; void *op_param; }; @@ -43,32 +43,30 @@ extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb; int bt_mesh_health_cli_set(struct bt_mesh_model *model); -int bt_mesh_health_fault_get(u16_t net_idx, u16_t addr, u16_t app_idx, - u16_t cid, u8_t *test_id, u8_t *faults, - size_t *fault_count); +int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid, + uint8_t *test_id, uint8_t *faults, + size_t *fault_count); -int bt_mesh_health_fault_clear(u16_t net_idx, u16_t addr, u16_t app_idx, - u16_t cid, u8_t *test_id, u8_t *faults, - size_t *fault_count); +int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid, + uint8_t *test_id, uint8_t *faults, + size_t *fault_count); -int bt_mesh_health_fault_test(u16_t net_idx, u16_t addr, u16_t app_idx, - u16_t cid, u8_t test_id, u8_t *faults, - size_t *fault_count); +int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid, + uint8_t test_id, uint8_t *faults, + size_t *fault_count); -int bt_mesh_health_period_get(u16_t net_idx, u16_t addr, u16_t app_idx, - u8_t *divisor); +int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor); -int bt_mesh_health_period_set(u16_t net_idx, u16_t addr, u16_t app_idx, - u8_t divisor, u8_t *updated_divisor); +int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor, + uint8_t *updated_divisor); -int bt_mesh_health_attention_get(u16_t net_idx, u16_t addr, u16_t app_idx, - u8_t *attention); +int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *attention); -int bt_mesh_health_attention_set(u16_t net_idx, u16_t addr, u16_t app_idx, - u8_t attention, u8_t *updated_attention); +int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx, uint8_t attention, + uint8_t *updated_attention); -s32_t bt_mesh_health_cli_timeout_get(void); -void bt_mesh_health_cli_timeout_set(s32_t timeout); +int32_t bt_mesh_health_cli_timeout_get(void); +void bt_mesh_health_cli_timeout_set(int32_t timeout); #ifdef __cplusplus } diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_srv.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_srv.h index 83982376..ad79e368 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_srv.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_srv.h @@ -23,21 +23,21 @@ extern "C" { struct bt_mesh_health_srv_cb { /* Fetch current faults */ - int (*fault_get_cur)(struct bt_mesh_model *model, u8_t *test_id, - u16_t *company_id, u8_t *faults, - u8_t *fault_count); + int (*fault_get_cur)(struct bt_mesh_model *model, uint8_t *test_id, + uint16_t *company_id, uint8_t *faults, + uint8_t *fault_count); /* Fetch registered faults */ - int (*fault_get_reg)(struct bt_mesh_model *model, u16_t company_id, - u8_t *test_id, u8_t *faults, - u8_t *fault_count); + int (*fault_get_reg)(struct bt_mesh_model *model, uint16_t company_id, + uint8_t *test_id, uint8_t *faults, + uint8_t *fault_count); /* Clear registered faults */ - int (*fault_clear)(struct bt_mesh_model *model, u16_t company_id); + int (*fault_clear)(struct bt_mesh_model *model, uint16_t company_id); /* Run a specific test */ - int (*fault_test)(struct bt_mesh_model *model, u8_t test_id, - u16_t company_id); + int (*fault_test)(struct bt_mesh_model *model, uint8_t test_id, + uint16_t company_id); /* Attention on */ void (*attn_on)(struct bt_mesh_model *model); @@ -52,7 +52,7 @@ struct bt_mesh_health_srv_cb { * * @param max_faults Maximum number of faults the element can have. * - * @return a New net_buf_simple of the needed size. + * @return a New os_mbuf of the needed size. */ #define BT_MESH_HEALTH_FAULT_MSG(max_faults) \ NET_BUF_SIMPLE(1 + 3 + (max_faults)) diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/heartbeat.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/heartbeat.h new file mode 100644 index 00000000..b9990f6f --- /dev/null +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/heartbeat.h @@ -0,0 +1,123 @@ +/** @file + * @brief Bluetooth Mesh Heartbeat API. + */ + +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef _BLUETOOTH_MESH_HEARTBEAT_H_ +#define _BLUETOOTH_MESH_HEARTBEAT_H_ + +/** + * @brief Bluetooth Mesh + * @defgroup bt_mesh_heartbeat Bluetooth Mesh Heartbeat + * @ingroup bt_mesh + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** Heartbeat Publication parameters */ +struct bt_mesh_hb_pub { + /** Destination address. */ + uint16_t dst; + /** Remaining publish count. */ + uint16_t count; + /** Time To Live value. */ + uint8_t ttl; + /** + * Bitmap of features that trigger a Heartbeat publication if + * they change. Legal values are @ref BT_MESH_FEAT_RELAY, + * @ref BT_MESH_FEAT_PROXY, @ref BT_MESH_FEAT_FRIEND and + * @ref BT_MESH_FEAT_LOW_POWER. + */ + uint16_t feat; + /** Network index used for publishing. */ + uint16_t net_idx; + /** Publication period in seconds. */ + uint32_t period; +}; + +/** Heartbeat Subscription parameters. */ +struct bt_mesh_hb_sub { + /** Subscription period in seconds. */ + uint32_t period; + /** Remaining subscription time in seconds. */ + uint32_t remaining; + /** Source address to receive Heartbeats from. */ + uint16_t src; + /** Destination address to received Heartbeats on. */ + uint16_t dst; + /** The number of received Heartbeat messages so far. */ + uint16_t count; + /** + * Minimum hops in received messages, ie the shortest registered + * path from the publishing node to the subscribing node. A + * Heartbeat received from an immediate neighbor has hop + * count = 1. + */ + uint8_t min_hops; + /** + * Maximum hops in received messages, ie the longest registered + * path from the publishing node to the subscribing node. A + * Heartbeat received from an immediate neighbor has hop + * count = 1. + */ + uint8_t max_hops; +}; + +/** Heartbeat callback structure */ +struct bt_mesh_hb_cb { + /** @brief Receive callback for heartbeats. + * + * Gets called on every received Heartbeat that matches the current + * Heartbeat subscription parameters. + * + * @param sub Current Heartbeat subscription parameters. + * @param hops The number of hops the Heartbeat was received + * with. + * @param feat The feature set of the publishing node. The + * value is a bitmap of @ref BT_MESH_FEAT_RELAY, + * @ref BT_MESH_FEAT_PROXY, + * @ref BT_MESH_FEAT_FRIEND and + * @ref BT_MESH_FEAT_LOW_POWER. + */ + void (*recv)(const struct bt_mesh_hb_sub *sub, uint8_t hops, + uint16_t feat); + + /** @brief Subscription end callback for heartbeats. + * + * Gets called when the subscription period ends, providing a summary + * of the received heartbeat messages. + * + * @param sub Current Heartbeat subscription parameters. + */ + void (*sub_end)(const struct bt_mesh_hb_sub *sub); +}; + +/** @brief Get the current Heartbeat publication parameters. + * + * @param get Heartbeat publication parameters return buffer. + */ +void bt_mesh_hb_pub_get(struct bt_mesh_hb_pub *get); + +/** @brief Get the current Heartbeat subscription parameters. + * + * @param get Heartbeat subscription parameters return buffer. + */ +void bt_mesh_hb_sub_get(struct bt_mesh_hb_sub *get); + +extern struct bt_mesh_hb_cb hb_cb; + +#ifdef __cplusplus +} +#endif +/** + * @} + */ + +#endif /* _BLUETOOTH_MESH_HEARTBEAT_H_ */
\ No newline at end of file diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/main.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/main.h index 4a5bedba..2bcb05c8 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/main.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/main.h @@ -59,10 +59,37 @@ typedef enum { BT_MESH_PROV_OOB_ON_DEV = BIT(15), } bt_mesh_prov_oob_info_t; +/** Device Capabilities. */ +struct bt_mesh_dev_capabilities { + /** Number of elements supported by the device */ + uint8_t elem_count; + + /** Supported algorithms and other capabilities */ + uint16_t algorithms; + + /** Supported public key types */ + uint8_t pub_key_type; + + /** Supported static OOB Types */ + uint8_t static_oob; + + /** Supported Output OOB Actions */ + bt_mesh_output_action_t output_actions; + + /** Supported Input OOB Actions */ + bt_mesh_input_action_t input_actions; + + /** Maximum size of Output OOB supported */ + uint8_t output_size; + + /** Maximum size in octets of Input OOB supported */ + uint8_t input_size; +}; + /** Provisioning properties & capabilities. */ struct bt_mesh_prov { /** The UUID that's used when advertising as unprovisioned */ - const u8_t *uuid; + const uint8_t *uuid; /** Optional URI. This will be advertised separately from the * unprovisioned beacon, however the unprovisioned beacon will @@ -75,19 +102,34 @@ struct bt_mesh_prov { bt_mesh_prov_oob_info_t oob_info; /** Static OOB value */ - const u8_t *static_val; + const uint8_t *static_val; /** Static OOB value length */ - u8_t static_val_len; + uint8_t static_val_len; /** Maximum size of Output OOB supported */ - u8_t output_size; + uint8_t output_size; /** Supported Output OOB Actions */ - u16_t output_actions; + uint16_t output_actions; /* Maximum size of Input OOB supported */ - u8_t input_size; + uint8_t input_size; /** Supported Input OOB Actions */ - u16_t input_actions; + uint16_t input_actions; + + /** @brief Provisioning Capabilities. + * + * This callback notifies the application that the provisioning capabilities + * of the unprovisioned device has been received. + * + * The application can consequently call bt_mesh_auth_method_set_<*> to + * select suitable provisioning oob authentication method. + * + * When this callback returns, the provisioner will start authentication with + * the chosen method. + * + * @param cap capabilities supported by device. + */ + void (*capabilities)(const struct bt_mesh_dev_capabilities *cap); /** @brief Output of a number is requested. * @@ -99,7 +141,7 @@ struct bt_mesh_prov { * * @return Zero on success or negative error code otherwise */ - int (*output_number)(bt_mesh_output_action_t act, u32_t num); + int (*output_number)(bt_mesh_output_action_t act, uint32_t num); /** @brief Output of a string is requested. * @@ -126,7 +168,7 @@ struct bt_mesh_prov { * * @return Zero on success or negative error code otherwise */ - int (*input)(bt_mesh_input_action_t act, u8_t size); + int (*input)(bt_mesh_input_action_t act, uint8_t size); /** @brief The other device finished their OOB input. * @@ -146,9 +188,9 @@ struct bt_mesh_prov { * @param uri_hash Pointer to URI Hash value. NULL if no hash was * present in the beacon. */ - void (*unprovisioned_beacon)(u8_t uuid[16], + void (*unprovisioned_beacon)(uint8_t uuid[16], bt_mesh_prov_oob_info_t oob_info, - u32_t *uri_hash); + uint32_t *uri_hash); /** @brief Provisioning link has been opened. * @@ -177,7 +219,7 @@ struct bt_mesh_prov { * @param net_idx NetKeyIndex given during provisioning. * @param addr Primary element address. */ - void (*complete)(u16_t net_idx, u16_t addr); + void (*complete)(uint16_t net_idx, uint16_t addr); /** @brief A new node has been added to the provisioning database. * @@ -186,10 +228,12 @@ struct bt_mesh_prov { * the specified NetKeyIndex and primary element address. * * @param net_idx NetKeyIndex given during provisioning. + * @param uuid UUID of the added node * @param addr Primary element address. * @param num_elem Number of elements that this node has. */ - void (*node_added)(u16_t net_idx, u16_t addr, u8_t num_elem); + void (*node_added)(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, + uint8_t num_elem); /** @brief Node has been reset. * @@ -222,7 +266,90 @@ int bt_mesh_input_string(const char *str); * * @return Zero on success or (negative) error code otherwise. */ -int bt_mesh_input_number(u32_t num); +int bt_mesh_input_number(uint32_t num); + +/** @brief Provide Device public key. + * + * @param public_key Device public key. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_prov_remote_pub_key_set(const uint8_t public_key[64]); + +/** @brief Use Input OOB authentication. + * + * Provisioner only. + * + * Instruct the unprovisioned device to use the specified Input OOB + * authentication action. When using @ref BT_MESH_PUSH, @ref BT_MESH_TWIST or + * @ref BT_MESH_ENTER_NUMBER, the @ref bt_mesh_prov::output_number callback is + * called with a random number that has to be entered on the unprovisioned + * device. + * + * When using @ref BT_MESH_ENTER_STRING, the @ref bt_mesh_prov::output_string + * callback is called with a random string that has to be entered on the + * unprovisioned device. + * + * @param action Authentication action used by the unprovisioned device. + * @param size Authentication size. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_auth_method_set_input(bt_mesh_input_action_t action, uint8_t size); + +/** @brief Use Output OOB authentication. + * + * Provisioner only. + * + * Instruct the unprovisioned device to use the specified Output OOB + * authentication action. The @ref bt_mesh_prov::input callback will + * be called. + * + * When using @ref BT_MESH_BLINK, @ref BT_MESH_BEEP, @ref BT_MESH_VIBRATE + * or @ref BT_MESH_DISPLAY_NUMBER, and the application has to call + * @ref bt_mesh_input_number with the random number indicated by + * the unprovisioned device. + * + * When using @ref BT_MESH_DISPLAY_STRING, the application has to call + * @ref bt_mesh_input_string with the random string displayed by the + * unprovisioned device. + * + * @param action Authentication action used by the unprovisioned device. + * @param size Authentication size. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size); + +/** @brief Use static OOB authentication. + * + * Provisioner only. + * + * Instruct the unprovisioned device to use static OOB authentication, and use + * the given static authentication value when provisioning. + * + * @param static_val Static OOB value. + * @param size Static OOB value size. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size); + +/** @brief Don't use OOB authentication. + * + * Provisioner only. + * + * Don't use any authentication when provisioning new devices. This is the + * default behavior. + * + * @warning Not using any authentication exposes the mesh network to + * impersonation attacks, where attackers can pretend to be the + * unprovisioned device to gain access to the network. Authentication + * is strongly encouraged. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_auth_method_set_none(void); /** @brief Enable specific provisioning bearers * @@ -258,25 +385,6 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers); /* Primary Network Key index */ #define BT_MESH_NET_PRIMARY 0x000 -#define BT_MESH_RELAY_DISABLED 0x00 -#define BT_MESH_RELAY_ENABLED 0x01 -#define BT_MESH_RELAY_NOT_SUPPORTED 0x02 - -#define BT_MESH_BEACON_DISABLED 0x00 -#define BT_MESH_BEACON_ENABLED 0x01 - -#define BT_MESH_GATT_PROXY_DISABLED 0x00 -#define BT_MESH_GATT_PROXY_ENABLED 0x01 -#define BT_MESH_GATT_PROXY_NOT_SUPPORTED 0x02 - -#define BT_MESH_FRIEND_DISABLED 0x00 -#define BT_MESH_FRIEND_ENABLED 0x01 -#define BT_MESH_FRIEND_NOT_SUPPORTED 0x02 - -#define BT_MESH_NODE_IDENTITY_STOPPED 0x00 -#define BT_MESH_NODE_IDENTITY_RUNNING 0x01 -#define BT_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02 - /* Features */ #define BT_MESH_FEAT_RELAY BIT(0) #define BT_MESH_FEAT_PROXY BIT(1) @@ -299,7 +407,7 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers); * * @return Zero on success or (negative) error code otherwise. */ -int bt_mesh_init(u8_t own_addr_type, +int bt_mesh_init(uint8_t own_addr_type, const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp); @@ -351,9 +459,9 @@ int bt_mesh_resume(void); * * @return Zero on success or (negative) error code otherwise. */ -int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, - u8_t flags, u32_t iv_index, u16_t addr, - const u8_t dev_key[16]); +int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, + uint8_t flags, uint32_t iv_index, uint16_t addr, + const uint8_t dev_key[16]); /** @brief Provision a Mesh Node using PB-ADV * @@ -365,8 +473,8 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, * * @return Zero on success or (negative) error code otherwise. */ -int bt_mesh_provision_adv(const u8_t uuid[16], u16_t net_idx, u16_t addr, - u8_t attention_duration); +int bt_mesh_provision_adv(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr, + uint8_t attention_duration); /** @brief Check if the local node has been provisioned. * @@ -428,7 +536,17 @@ int bt_mesh_lpn_poll(void); * * @param cb Function to call when the Friendship status changes. */ -void bt_mesh_lpn_set_cb(void (*cb)(u16_t friend_addr, bool established)); +void bt_mesh_lpn_set_cb(void (*cb)(uint16_t friend_addr, bool established)); + +/** @brief Terminate Friendship. + * + * Terminated Friendship for given LPN. + * + * @param lpn_addr Low Power Node address. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_friend_terminate(uint16_t lpn_addr); #ifdef __cplusplus } diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/mesh.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/mesh.h index 9ba63ef0..b9bc24fb 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/mesh.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/mesh.h @@ -17,10 +17,15 @@ #include "glue.h" #include "access.h" #include "main.h" +#include "cfg.h" #include "cfg_srv.h" #include "health_srv.h" #include "cfg_cli.h" #include "health_cli.h" #include "proxy.h" +#include "cdb.h" +#include "cfg.h" +#include "heartbeat.h" +#include "../src/app_keys.h" #endif /* __BT_MESH_H */ diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_cli.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_cli.h index f2e77a47..87e2dd2b 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_cli.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_cli.h @@ -15,7 +15,7 @@ struct bt_mesh_gen_model_cli { struct bt_mesh_model *model; struct k_sem op_sync; - u32_t op_pending; + uint32_t op_pending; void *op_param; }; @@ -33,14 +33,14 @@ extern const struct bt_mesh_model_cb bt_mesh_gen_level_cli_cb; BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_LEVEL_CLI, gen_level_cli_op, pub,\ cli_data, &bt_mesh_gen_level_cli_cb) -int bt_mesh_gen_onoff_get(u16_t net_idx, u16_t addr, u16_t app_idx, - u8_t *state); -int bt_mesh_gen_onoff_set(u16_t net_idx, u16_t addr, u16_t app_idx, - u8_t val, u8_t *state); -int bt_mesh_gen_level_get(u16_t net_idx, u16_t addr, u16_t app_idx, - s16_t *level); -int bt_mesh_gen_level_set(u16_t net_idx, u16_t addr, u16_t app_idx, - s16_t val, s16_t *state); +int bt_mesh_gen_onoff_get(uint16_t net_idx, uint16_t addr, uint16_t app_idx, + uint8_t *state); +int bt_mesh_gen_onoff_set(uint16_t net_idx, uint16_t addr, uint16_t app_idx, + uint8_t val, uint8_t *state); +int bt_mesh_gen_level_get(uint16_t net_idx, uint16_t addr, uint16_t app_idx, + int16_t *level); +int bt_mesh_gen_level_set(uint16_t net_idx, uint16_t addr, uint16_t app_idx, + int16_t val, int16_t *state); #ifdef __cplusplus } diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_srv.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_srv.h index e498ad34..a23296b8 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_srv.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_srv.h @@ -14,8 +14,8 @@ extern "C" { struct bt_mesh_gen_onoff_srv { struct bt_mesh_model *model; - int (*get)(struct bt_mesh_model *model, u8_t *state); - int (*set)(struct bt_mesh_model *model, u8_t state); + int (*get)(struct bt_mesh_model *model, uint8_t *state); + int (*set)(struct bt_mesh_model *model, uint8_t state); }; extern const struct bt_mesh_model_op gen_onoff_srv_op[]; @@ -28,8 +28,8 @@ extern const struct bt_mesh_model_cb gen_onoff_srv_cb; struct bt_mesh_gen_level_srv { struct bt_mesh_model *model; - int (*get)(struct bt_mesh_model *model, s16_t *level); - int (*set)(struct bt_mesh_model *model, s16_t level); + int (*get)(struct bt_mesh_model *model, int16_t *level); + int (*set)(struct bt_mesh_model *model, int16_t level); }; extern const struct bt_mesh_model_op gen_level_srv_op[]; @@ -42,8 +42,8 @@ extern const struct bt_mesh_model_cb gen_level_srv_cb; struct bt_mesh_light_lightness_srv { struct bt_mesh_model *model; - int (*get)(struct bt_mesh_model *model, s16_t *level); - int (*set)(struct bt_mesh_model *model, s16_t level); + int (*get)(struct bt_mesh_model *model, int16_t *level); + int (*set)(struct bt_mesh_model *model, int16_t level); }; extern const struct bt_mesh_model_op light_lightness_srv_op[]; @@ -53,12 +53,12 @@ extern const struct bt_mesh_model_cb light_lightness_srv_cb; BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, \ light_lightness_srv_op, pub, srv, &light_lightness_srv_cb) -void bt_mesh_set_gen_onoff_srv_cb(int (*get)(struct bt_mesh_model *model, u8_t *state), - int (*set)(struct bt_mesh_model *model, u8_t state)); -void bt_mesh_set_gen_level_srv_cb(int (*get)(struct bt_mesh_model *model, s16_t *level), - int (*set)(struct bt_mesh_model *model, s16_t level)); -void bt_mesh_set_light_lightness_srv_cb(int (*get)(struct bt_mesh_model *model, s16_t *level), - int (*set)(struct bt_mesh_model *model, s16_t level)); +void bt_mesh_set_gen_onoff_srv_cb(int (*get)(struct bt_mesh_model *model, uint8_t *state), + int (*set)(struct bt_mesh_model *model, uint8_t state)); +void bt_mesh_set_gen_level_srv_cb(int (*get)(struct bt_mesh_model *model, int16_t *level), + int (*set)(struct bt_mesh_model *model, int16_t level)); +void bt_mesh_set_light_lightness_srv_cb(int (*get)(struct bt_mesh_model *model, int16_t *level), + int (*set)(struct bt_mesh_model *model, int16_t level)); #ifdef __cplusplus } diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/testing.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/testing.h index 4c2b2a61..580aafe4 100644 --- a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/testing.h +++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/testing.h @@ -33,13 +33,13 @@ extern "C" { * Allows access to Bluetooth stack internals, not exposed by public API. */ struct bt_test_cb { - void (*mesh_net_recv)(u8_t ttl, u8_t ctl, u16_t src, u16_t dst, + void (*mesh_net_recv)(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len); - void (*mesh_model_bound)(u16_t addr, struct bt_mesh_model *model, - u16_t key_idx); - void (*mesh_model_unbound)(u16_t addr, struct bt_mesh_model *model, - u16_t key_idx); - void (*mesh_prov_invalid_bearer)(u8_t opcode); + void (*mesh_model_bound)(uint16_t addr, struct bt_mesh_model *model, + uint16_t key_idx); + void (*mesh_model_unbound)(uint16_t addr, struct bt_mesh_model *model, + uint16_t key_idx); + void (*mesh_prov_invalid_bearer)(uint8_t opcode); void (*mesh_trans_incomp_timer_exp)(void); sys_snode_t node; @@ -66,7 +66,7 @@ void bt_test_cb_unregister(struct bt_test_cb *cb); * * @return Zero on success or (negative) error code otherwise. */ -int bt_test_mesh_lpn_group_add(u16_t group); +int bt_test_mesh_lpn_group_add(uint16_t group); /** Send Friend Subscription List Remove message. * @@ -79,7 +79,7 @@ int bt_test_mesh_lpn_group_add(u16_t group); * * @return Zero on success or (negative) error code otherwise. */ -int bt_test_mesh_lpn_group_remove(u16_t *groups, size_t groups_count); +int bt_test_mesh_lpn_group_remove(uint16_t *groups, size_t groups_count); /** Clear replay protection list cache. * @@ -87,12 +87,12 @@ int bt_test_mesh_lpn_group_remove(u16_t *groups, size_t groups_count); */ int bt_test_mesh_rpl_clear(void); -u8_t mod_bind(struct bt_mesh_model *model, u16_t key_idx); -u8_t mod_unbind(struct bt_mesh_model *model, u16_t key_idx, bool store); +uint8_t mod_bind(struct bt_mesh_model *model, uint16_t key_idx); +uint8_t mod_unbind(struct bt_mesh_model *model, uint16_t key_idx, bool store); int cmd_mesh_init(int argc, char *argv[]); int bt_test_shell_init(void); -int bt_test_bind_app_key_to_model(struct bt_mesh_model *model, u16_t key_idx, u16_t id); +int bt_test_bind_app_key_to_model(struct bt_mesh_model *model, uint16_t key_idx, uint16_t id); /** * @} |