summaryrefslogtreecommitdiff
path: root/src/libs/mynewt-nimble/nimble/host/mesh/include
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-04-26 10:25:59 +0200
committerJF <jf@codingfield.com>2020-04-26 10:25:59 +0200
commitbdc10744fb338ae197692713a0b48a7ccc36f566 (patch)
treeaf7a8f2f16ddd2e5483758effec15c7683f6c453 /src/libs/mynewt-nimble/nimble/host/mesh/include
parent032fad094c6411ad3ff4321ad61ceed95d7dc4ff (diff)
Add Nimble in libs directory
Diffstat (limited to 'src/libs/mynewt-nimble/nimble/host/mesh/include')
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/access.h656
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_cli.h234
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_srv.h78
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/glue.h502
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_cli.h81
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_srv.h100
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/main.h441
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/mesh.h26
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_cli.h49
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_srv.h67
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/porting.h27
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/proxy.h43
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/slist.h468
-rw-r--r--src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/testing.h105
14 files changed, 2877 insertions, 0 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
new file mode 100644
index 00000000..1f99f412
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/access.h
@@ -0,0 +1,656 @@
+/** @file
+ * @brief Bluetooth Mesh Access Layer APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_ACCESS_H
+#define __BT_MESH_ACCESS_H
+
+/**
+ * @brief Bluetooth Mesh Access Layer
+ * @defgroup bt_mesh_access Bluetooth Mesh Access Layer
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BT_MESH_ADDR_UNASSIGNED 0x0000
+#define BT_MESH_ADDR_ALL_NODES 0xffff
+#define BT_MESH_ADDR_PROXIES 0xfffc
+#define BT_MESH_ADDR_FRIENDS 0xfffd
+#define BT_MESH_ADDR_RELAYS 0xfffe
+
+#define BT_MESH_KEY_UNUSED 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_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \
+ key == BT_MESH_KEY_DEV_REMOTE)
+
+/** Helper to define a mesh element within an array.
+ *
+ * In case the element has no SIG or Vendor models the helper
+ * macro BT_MESH_MODEL_NONE can be given instead.
+ *
+ * @param _loc Location Descriptor.
+ * @param _mods Array of models.
+ * @param _vnd_mods Array of vendor models.
+ */
+#define BT_MESH_ELEM(_loc, _mods, _vnd_mods) \
+{ \
+ .loc = (_loc), \
+ .model_count = ARRAY_SIZE(_mods), \
+ .models = (_mods), \
+ .vnd_model_count = ARRAY_SIZE(_vnd_mods), \
+ .vnd_models = (_vnd_mods), \
+}
+
+/** Abstraction that describes a Mesh Element */
+struct bt_mesh_elem {
+ /* Unicast Address. Set at runtime during provisioning. */
+ u16_t addr;
+
+ /* Location Descriptor (GATT Bluetooth Namespace Descriptors) */
+ const u16_t loc;
+
+ const u8_t model_count;
+ const u8_t vnd_model_count;
+
+ struct bt_mesh_model * const models;
+ struct bt_mesh_model * const vnd_models;
+};
+
+/* Foundation Models */
+#define BT_MESH_MODEL_ID_CFG_SRV 0x0000
+#define BT_MESH_MODEL_ID_CFG_CLI 0x0001
+#define BT_MESH_MODEL_ID_HEALTH_SRV 0x0002
+#define BT_MESH_MODEL_ID_HEALTH_CLI 0x0003
+
+/* Models from the Mesh Model Specification */
+#define BT_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
+#define BT_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001
+#define BT_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002
+#define BT_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003
+#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004
+#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005
+#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006
+#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007
+#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008
+#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009
+#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a
+#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b
+#define BT_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
+#define BT_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
+#define BT_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
+#define BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f
+#define BT_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
+#define BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
+#define BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
+#define BT_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013
+#define BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014
+#define BT_MESH_MODEL_ID_GEN_PROP_CLI 0x1015
+#define BT_MESH_MODEL_ID_SENSOR_SRV 0x1100
+#define BT_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101
+#define BT_MESH_MODEL_ID_SENSOR_CLI 0x1102
+#define BT_MESH_MODEL_ID_TIME_SRV 0x1200
+#define BT_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201
+#define BT_MESH_MODEL_ID_TIME_CLI 0x1202
+#define BT_MESH_MODEL_ID_SCENE_SRV 0x1203
+#define BT_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204
+#define BT_MESH_MODEL_ID_SCENE_CLI 0x1205
+#define BT_MESH_MODEL_ID_SCHEDULER_SRV 0x1206
+#define BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207
+#define BT_MESH_MODEL_ID_SCHEDULER_CLI 0x1208
+#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300
+#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301
+#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302
+#define BT_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303
+#define BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304
+#define BT_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305
+#define BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306
+#define BT_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307
+#define BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308
+#define BT_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309
+#define BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a
+#define BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b
+#define BT_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c
+#define BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
+#define BT_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
+#define BT_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
+#define BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310
+#define BT_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
+
+/** Message sending context. */
+struct bt_mesh_msg_ctx {
+ /** NetKey Index of the subnet to send the message on. */
+ u16_t net_idx;
+
+ /** AppKey Index to encrypt the message with. */
+ u16_t app_idx;
+
+ /** Remote address. */
+ u16_t addr;
+
+ /** Destination address of a received message. Not used for sending. */
+ u16_t recv_dst;
+
+ /** RSSI of received packet. Not used for sending. */
+ s8_t recv_rssi;
+
+ /** Received TTL value. Not used for sending. */
+ u8_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;
+};
+
+struct bt_mesh_model_op {
+ /* OpCode encoded using the BT_MESH_MODEL_OP_* macros */
+ const u32_t opcode;
+
+ /* Minimum required message length */
+ const size_t min_len;
+
+ /* Message handler for the opcode */
+ void (*const func)(struct bt_mesh_model *model,
+ struct bt_mesh_msg_ctx *ctx,
+ struct os_mbuf *buf);
+};
+
+#define BT_MESH_MODEL_OP_1(b0) (b0)
+#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
+#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
+
+#define BT_MESH_MODEL_OP_END { 0, 0, NULL }
+#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
+ { BT_MESH_MODEL_OP_END })
+
+/** Helper to define an empty model array */
+#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){})
+
+/** Length of a short Mesh MIC. */
+#define BT_MESH_MIC_SHORT 4
+/** Length of a long Mesh MIC. */
+#define BT_MESH_MIC_LONG 8
+
+/** @def BT_MESH_MODEL_OP_LEN
+ *
+ * @brief Helper to determine the length of an opcode.
+ *
+ * @param _op Opcode.
+ */
+#define BT_MESH_MODEL_OP_LEN(_op) ((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)
+
+/** @def BT_MESH_MODEL_BUF_LEN
+ *
+ * @brief Helper for model message buffer length.
+ *
+ * Returns the length of a Mesh model message buffer, including the opcode
+ * length and a short MIC.
+ *
+ * @param _op Opcode of the message.
+ * @param _payload_len Length of the model payload.
+ */
+#define BT_MESH_MODEL_BUF_LEN(_op, _payload_len) \
+ (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_SHORT)
+
+/** @def BT_MESH_MODEL_BUF_LEN_LONG_MIC
+ *
+ * @brief Helper for model message buffer length.
+ *
+ * Returns the length of a Mesh model message buffer, including the opcode
+ * length and a long MIC.
+ *
+ * @param _op Opcode of the message.
+ * @param _payload_len Length of the model payload.
+ */
+#define BT_MESH_MODEL_BUF_LEN_LONG_MIC(_op, _payload_len) \
+ (BT_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BT_MESH_MIC_LONG)
+
+/** @def BT_MESH_MODEL_BUF_DEFINE
+ *
+ * @brief Define a Mesh model message buffer using @ref NET_BUF_SIMPLE.
+ *
+ * @param _op Opcode of the message.
+ * @param _payload_len Length of the model message payload.
+ */
+#define BT_MESH_MODEL_BUF(_op, _payload_len) \
+ NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN(_op, (_payload_len)))
+
+/** @def BT_MESH_MODEL_CB
+ *
+ * @brief Composition data SIG model entry with callback functions.
+ *
+ * @param _id Model ID.
+ * @param _op Array of model opcode handlers.
+ * @param _pub Model publish parameters.
+ * @param _user_data User data for the model.
+ * @param _cb Callback structure, or NULL to keep no callbacks.
+ */
+#define BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
+{ \
+ .id = (_id), \
+ .op = _op, \
+ .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
+ BT_MESH_KEY_UNUSED }, \
+ .pub = _pub, \
+ .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
+ BT_MESH_ADDR_UNASSIGNED }, \
+ .user_data = _user_data, \
+ .cb = _cb, \
+}
+
+/** @def BT_MESH_MODEL_VND_CB
+ *
+ * @brief Composition data vendor model entry with callback functions.
+ *
+ * @param _company Company ID.
+ * @param _id Model ID.
+ * @param _op Array of model opcode handlers.
+ * @param _pub Model publish parameters.
+ * @param _user_data User data for the model.
+ * @param _cb Callback structure, or NULL to keep no callbacks.
+ */
+#define BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
+{ \
+ .vnd.company = (_company), \
+ .vnd.id = (_id), \
+ .op = _op, \
+ .pub = _pub, \
+ .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
+ BT_MESH_KEY_UNUSED }, \
+ .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
+ BT_MESH_ADDR_UNASSIGNED }, \
+ .user_data = _user_data, \
+ .cb = _cb, \
+}
+
+
+/** @def BT_MESH_MODEL
+ *
+ * @brief Composition data SIG model entry.
+ *
+ * @param _id Model ID.
+ * @param _op Array of model opcode handlers.
+ * @param _pub Model publish parameters.
+ * @param _user_data User data for the model.
+ */
+#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \
+ BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, NULL)
+
+/** @def BT_MESH_MODEL_VND
+ *
+ * @brief Composition data vendor model entry.
+ *
+ * @param _company Company ID.
+ * @param _id Model ID.
+ * @param _op Array of model opcode handlers.
+ * @param _pub Model publish parameters.
+ * @param _user_data User data for the model.
+ */
+#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \
+ BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, NULL)
+
+/** @def BT_MESH_TRANSMIT
+ *
+ * @brief Encode transmission count & interval steps.
+ *
+ * @param count Number of retransmissions (first transmission is excluded).
+ * @param int_ms Interval steps in milliseconds. Must be greater than 0,
+ * less than or equal to 320, and a multiple of 10.
+ *
+ * @return Mesh transmit value that can be used e.g. for the default
+ * values of the configuration model data.
+ */
+#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3))
+
+/** @def BT_MESH_TRANSMIT_COUNT
+ *
+ * @brief Decode transmit count from a transmit value.
+ *
+ * @param transmit Encoded transmit count & interval value.
+ *
+ * @return Transmission count (actual transmissions is N + 1).
+ */
+#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (u8_t)BIT_MASK(3)))
+
+/** @def BT_MESH_TRANSMIT_INT
+ *
+ * @brief Decode transmit interval from a transmit value.
+ *
+ * @param transmit Encoded transmit count & interval value.
+ *
+ * @return Transmission interval in milliseconds.
+ */
+#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
+
+/** @def BT_MESH_PUB_TRANSMIT
+ *
+ * @brief Encode Publish Retransmit count & interval steps.
+ *
+ * @param count Number of retransmissions (first transmission is excluded).
+ * @param int_ms Interval steps in milliseconds. Must be greater than 0
+ * and a multiple of 50.
+ *
+ * @return Mesh transmit value that can be used e.g. for the default
+ * values of the configuration model data.
+ */
+#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
+ (int_ms) / 5)
+
+/** @def BT_MESH_PUB_TRANSMIT_COUNT
+ *
+ * @brief Decode Pubhlish Retransmit count from a given value.
+ *
+ * @param transmit Encoded Publish Retransmit count & interval value.
+ *
+ * @return Retransmission count (actual transmissions is N + 1).
+ */
+#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
+
+/** @def BT_MESH_PUB_TRANSMIT_INT
+ *
+ * @brief Decode Publish Retransmit interval from a given value.
+ *
+ * @param transmit Encoded Publish Retransmit count & interval value.
+ *
+ * @return Transmission interval in milliseconds.
+ */
+#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
+
+/** Model publication context. */
+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. */
+
+ 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. */
+ cred:1, /**< Friendship Credentials Flag. */
+ fast_period:1,/**< Use FastPeriodDivisor */
+ count:3; /**< Retransmissions left. */
+
+ u32_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.
+ * 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
+ * @ref bt_mesh_model_pub.update callback has been called
+ * and returned success. The buffer must be created outside
+ * of function context, i.e. it must not be on the stack.
+ * This is most conveniently acheived by creating it inline
+ * when declaring the publication context:
+ *
+ * static struct bt_mesh_model_pub my_pub = {
+ * .msg = NET_BUF_SIMPLE(size),
+ * };
+ */
+ struct os_mbuf *msg;
+
+ /** @brief Callback for updating the publication buffer.
+ *
+ * When set to NULL, the model is assumed not to support
+ * periodic publishing. When set to non-NULL the callback
+ * will be called periodically and is expected to update
+ * @ref bt_mesh_model_pub.msg with a valid publication
+ * message.
+ *
+ * @param mod The Model the Publication Context belogs to.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+ int (*update)(struct bt_mesh_model *mod);
+
+ /** Publish Period Timer. Only for stack-internal use. */
+ struct k_delayed_work timer;
+};
+
+/** Model callback functions. */
+struct bt_mesh_model_cb {
+ /** @brief Set value handler of user data tied to the model.
+ *
+ * @sa settings_handler::h_set
+ *
+ * @param model Model to set the persistent data of.
+ * @param val Data from the backend.
+ *
+ * @return 0 on success, error otherwise.
+ */
+ int (*const settings_set)(struct bt_mesh_model *model, char *val);
+
+ /** @brief Callback called when all settings have been loaded.
+ *
+ * This handler gets called after the settings have been loaded in
+ * full.
+ *
+ * @sa settings_handler::h_commit
+ *
+ * @param model Model this callback belongs to.
+ *
+ * @return 0 on success, error otherwise.
+ */
+ int (*const settings_commit)(struct bt_mesh_model *model);
+
+ /** @brief Model init callback.
+ *
+ * Called on every model instance during mesh initialization.
+ *
+ * @param model Model to be initialized.
+ *
+ * @return 0 on success, error otherwise.
+ */
+ int (*const init)(struct bt_mesh_model *model);
+
+ /** @brief Model reset callback.
+ *
+ * Called when the mesh node is reset. All model data is deleted on
+ * reset, and the model should clear its state.
+ *
+ * @param model Model this callback belongs to.
+ */
+ void (*const reset)(struct bt_mesh_model *model);
+};
+
+/** Abstraction that describes a Mesh Model instance */
+struct bt_mesh_model {
+ union {
+ const u16_t id;
+ struct {
+ u16_t company;
+ u16_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 */
+
+ /* Model Publication */
+ struct bt_mesh_model_pub * const pub;
+
+ /* AppKey List */
+ u16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
+
+ /* Subscription List (group or virtual addresses) */
+ u16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
+
+ const struct bt_mesh_model_op * const op;
+
+ /* Model callback structure. */
+ const struct bt_mesh_model_cb * const cb;
+
+#if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS)
+ /* Pointer to the next model in a model extension tree. */
+ struct bt_mesh_model *next;
+ /* Pointer to the first model this model extends. */
+ struct bt_mesh_model *extends;
+#endif
+ /* Model-specific user data */
+ void *user_data;
+};
+
+struct bt_mesh_send_cb {
+ void (*start)(u16_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);
+
+/** Special TTL value to request using configured default TTL */
+#define BT_MESH_TTL_DEFAULT 0xff
+
+/** Maximum allowed TTL value */
+#define BT_MESH_TTL_MAX 0x7f
+
+/**
+ * @brief Send an Access Layer message.
+ *
+ * @param model Mesh (client) Model that the message belongs to.
+ * @param ctx Message context, includes keys, TTL, etc.
+ * @param msg Access Layer payload (the actual message to be sent).
+ * @param cb Optional "message sent" callback.
+ * @param cb_data User data to be passed to the callback.
+ *
+ * @return 0 on success, or (negative) error code on failure.
+ */
+int bt_mesh_model_send(struct bt_mesh_model *model,
+ struct bt_mesh_msg_ctx *ctx,
+ struct os_mbuf *msg,
+ const struct bt_mesh_send_cb *cb,
+ void *cb_data);
+
+/**
+ * @brief Send a model publication message.
+ *
+ * Before calling this function, the user needs to ensure that the model
+ * publication message (@ref bt_mesh_model_pub.msg) contains a valid
+ * message to be sent. Note that this API is only to be used for
+ * non-period publishing. For periodic publishing the app only needs
+ * to make sure that @ref bt_mesh_model_pub.msg contains a valid message
+ * whenever the @ref bt_mesh_model_pub.update callback is called.
+ *
+ * @param model Mesh (client) Model that's publishing the message.
+ *
+ * @return 0 on success, or (negative) error code on failure.
+ */
+int bt_mesh_model_publish(struct bt_mesh_model *model);
+
+/**
+ * @brief Get the element that a model belongs to.
+ *
+ * @param mod Mesh model.
+ *
+ * @return Pointer to the element that the given model belongs to.
+ */
+struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod);
+
+/** @brief Find a SIG model.
+ *
+ * @param elem Element to search for the model in.
+ * @param id Model ID of the model.
+ *
+ * @return A pointer to the Mesh model matching the given parameters, or NULL
+ * 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);
+
+/** @brief Find a vendor model.
+ *
+ * @param elem Element to search for the model in.
+ * @param company Company ID of the model.
+ * @param id Model ID of the model.
+ *
+ * @return A pointer to the Mesh model matching the given parameters, or NULL
+ * 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);
+
+/** @brief Get whether the model is in the primary element of the device.
+ *
+ * @param mod Mesh model.
+ *
+ * @return true if the model is on the primary element, false otherwise.
+ */
+static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)
+{
+ return (mod->elem_idx == 0);
+}
+
+/** @brief Immediately store the model's user data in persistent storage.
+ *
+ * @param mod Mesh model.
+ * @param vnd This is a vendor model.
+ * @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);
+
+/** @brief Let a model extend another.
+ *
+ * Mesh models may be extended to reuse their functionality, forming a more
+ * complex model. A Mesh model may extend any number of models, in any element.
+ * The extensions may also be nested, ie a model that extends another may itself
+ * be extended. Extensions may not be cyclical, and a model can only be extended
+ * by one other model.
+ *
+ * A set of models that extend each other form a model extension tree.
+ *
+ * All models in an extension tree share one subscription list per element. The
+ * access layer will utilize the combined subscription list of all models in an
+ * extension tree and element, giving the models extended subscription list
+ * capacity.
+ *
+ * @param[in] mod Mesh model.
+ * @param[in] base_mod The model being extended.
+ *
+ * @retval 0 Successfully extended the base_mod model.
+ * @retval -EALREADY The base_mod model is already extended.
+ */
+int bt_mesh_model_extend(struct bt_mesh_model *mod,
+ struct bt_mesh_model *base_mod);
+
+/** Node Composition */
+struct bt_mesh_comp {
+ u16_t cid;
+ u16_t pid;
+ u16_t vid;
+
+ size_t elem_count;
+ struct bt_mesh_elem *elem;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_ACCESS_H */
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
new file mode 100644
index 00000000..7dc237be
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_cli.h
@@ -0,0 +1,234 @@
+/** @file
+ * @brief Bluetooth Mesh Configuration Client Model APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_CFG_CLI_H
+#define __BT_MESH_CFG_CLI_H
+
+/**
+ * @brief Bluetooth Mesh
+ * @defgroup bt_mesh_cfg_cli Bluetooth Mesh Configuration Client Model
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Mesh Configuration Client Model Context */
+struct bt_mesh_cfg_cli {
+ struct bt_mesh_model *model;
+
+ struct k_sem op_sync;
+ u32_t op_pending;
+ void *op_param;
+};
+
+extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
+extern const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb;
+
+#define BT_MESH_MODEL_CFG_CLI(cli_data) \
+ 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_beacon_get(u16_t net_idx, u16_t addr, u8_t *status);
+
+int bt_mesh_cfg_beacon_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status);
+
+int bt_mesh_cfg_ttl_get(u16_t net_idx, u16_t addr, u8_t *ttl);
+
+int bt_mesh_cfg_ttl_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *ttl);
+
+int bt_mesh_cfg_friend_get(u16_t net_idx, u16_t addr, u8_t *status);
+
+int bt_mesh_cfg_friend_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status);
+
+int bt_mesh_cfg_gatt_proxy_get(u16_t net_idx, u16_t addr, u8_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_relay_get(u16_t net_idx, u16_t addr, u8_t *status,
+ u8_t *transmit);
+
+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_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_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_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_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);
+
+/** @def BT_MESH_PUB_PERIOD_100MS
+ *
+ * @brief Helper macro to encode model publication period in units of 100ms
+ *
+ * @param steps Number of 100ms steps.
+ *
+ * @return Encoded value that can be assigned to bt_mesh_cfg_mod_pub.period
+ */
+#define BT_MESH_PUB_PERIOD_100MS(steps) ((steps) & BIT_MASK(6))
+
+/** @def BT_MESH_PUB_PERIOD_SEC
+ *
+ * @brief Helper macro to encode model publication period in units of 1 second
+ *
+ * @param steps Number of 1 second steps.
+ *
+ * @return Encoded value that can be assigned to bt_mesh_cfg_mod_pub.period
+ */
+#define BT_MESH_PUB_PERIOD_SEC(steps) (((steps) & BIT_MASK(6)) | (1 << 6))
+
+/** @def BT_MESH_PUB_PERIOD_10SEC
+ *
+ * @brief Helper macro to encode model publication period in units of 10
+ * seconds
+ *
+ * @param steps Number of 10 second steps.
+ *
+ * @return Encoded value that can be assigned to bt_mesh_cfg_mod_pub.period
+ */
+#define BT_MESH_PUB_PERIOD_10SEC(steps) (((steps) & BIT_MASK(6)) | (2 << 6))
+
+/** @def BT_MESH_PUB_PERIOD_10MIN
+ *
+ * @brief Helper macro to encode model publication period in units of 10
+ * minutes
+ *
+ * @param steps Number of 10 minute steps.
+ *
+ * @return Encoded value that can be assigned to bt_mesh_cfg_mod_pub.period
+ */
+#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;
+ bool cred_flag;
+ u8_t ttl;
+ u8_t period;
+ u8_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_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(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_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(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_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(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_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(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_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(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_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(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_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(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_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);
+
+struct bt_mesh_cfg_hb_sub {
+ u16_t src;
+ u16_t dst;
+ u8_t period;
+ u8_t count;
+ u8_t min;
+ u8_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_get(u16_t net_idx, u16_t addr,
+ struct bt_mesh_cfg_hb_sub *sub, u8_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;
+};
+
+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_get(u16_t net_idx, u16_t addr,
+ struct bt_mesh_cfg_hb_pub *pub, u8_t *status);
+
+s32_t bt_mesh_cfg_cli_timeout_get(void);
+void bt_mesh_cfg_cli_timeout_set(s32_t timeout);
+
+#ifdef __cplusplus
+}
+#endif
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_CFG_CLI_H */
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
new file mode 100644
index 00000000..14d8a295
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/cfg_srv.h
@@ -0,0 +1,78 @@
+/** @file
+ * @brief Bluetooth Mesh Configuration Server Model APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_CFG_SRV_H
+#define __BT_MESH_CFG_SRV_H
+
+/**
+ * @brief Bluetooth Mesh
+ * @defgroup bt_mesh_cfg_srv Bluetooth Mesh Configuration Server Model
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+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) \
+ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_op, NULL, \
+ srv_data, &bt_mesh_cfg_srv_cb)
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_CFG_SRV_H */
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
new file mode 100644
index 00000000..e37fcfbc
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/glue.h
@@ -0,0 +1,502 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _MESH_GLUE_
+#define _MESH_GLUE_
+
+#include <assert.h>
+#include <errno.h>
+
+#include "syscfg/syscfg.h"
+#include "logcfg/logcfg.h"
+#include "modlog/modlog.h"
+#include "nimble/nimble_npl.h"
+
+#include "os/os_mbuf.h"
+#include "os/queue.h"
+
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "host/ble_uuid.h"
+#include "../src/ble_sm_priv.h"
+#include "../src/ble_hs_hci_priv.h"
+
+#include "tinycrypt/aes.h"
+#include "tinycrypt/constants.h"
+#include "tinycrypt/utils.h"
+#include "tinycrypt/cmac_mode.h"
+#include "tinycrypt/ecc_dh.h"
+
+#if MYNEWT_VAL(BLE_MESH_SETTINGS)
+#include "config/config.h"
+#endif
+
+#ifdef __cplusplus
+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
+ * elements which is then passed to bt_le_adv_start().
+ *
+ * @param _type Type of advertising data field
+ * @param _data Pointer to the data field payload
+ * @param _data_len Number of bytes behind the _data pointer
+ */
+#define BT_DATA(_type, _data, _data_len) \
+ { \
+ .type = (_type), \
+ .data_len = (_data_len), \
+ .data = (const u8_t *)(_data), \
+ }
+
+/** @brief Helper to declare elements of bt_data arrays
+ *
+ * This macro is mainly for creating an array of struct bt_data
+ * elements which is then passed to bt_le_adv_start().
+ *
+ * @param _type Type of advertising data field
+ * @param _bytes Variable number of single-byte parameters
+ */
+#define BT_DATA_BYTES(_type, _bytes...) \
+ BT_DATA(_type, ((u8_t []) { _bytes }), \
+ sizeof((u8_t []) { _bytes }))
+
+/* EIR/AD data type definitions */
+#define BT_DATA_FLAGS 0x01 /* AD flags */
+#define BT_DATA_UUID16_SOME 0x02 /* 16-bit UUID, more available */
+#define BT_DATA_UUID16_ALL 0x03 /* 16-bit UUID, all listed */
+#define BT_DATA_UUID32_SOME 0x04 /* 32-bit UUID, more available */
+#define BT_DATA_UUID32_ALL 0x05 /* 32-bit UUID, all listed */
+#define BT_DATA_UUID128_SOME 0x06 /* 128-bit UUID, more available */
+#define BT_DATA_UUID128_ALL 0x07 /* 128-bit UUID, all listed */
+#define BT_DATA_NAME_SHORTENED 0x08 /* Shortened name */
+#define BT_DATA_NAME_COMPLETE 0x09 /* Complete name */
+#define BT_DATA_TX_POWER 0x0a /* Tx Power */
+#define BT_DATA_SOLICIT16 0x14 /* Solicit UUIDs, 16-bit */
+#define BT_DATA_SOLICIT128 0x15 /* Solicit UUIDs, 128-bit */
+#define BT_DATA_SVC_DATA16 0x16 /* Service data, 16-bit UUID */
+#define BT_DATA_GAP_APPEARANCE 0x19 /* GAP appearance */
+#define BT_DATA_SOLICIT32 0x1f /* Solicit UUIDs, 32-bit */
+#define BT_DATA_SVC_DATA32 0x20 /* Service data, 32-bit UUID */
+#define BT_DATA_SVC_DATA128 0x21 /* Service data, 128-bit UUID */
+#define BT_DATA_URI 0x24 /* URI */
+#define BT_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */
+#define BT_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */
+#define BT_DATA_MESH_BEACON 0x2b /* Mesh Beacon */
+
+#define BT_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */
+
+#define BT_LE_AD_LIMITED 0x01 /* Limited Discoverable */
+#define BT_LE_AD_GENERAL 0x02 /* General Discoverable */
+#define BT_LE_AD_NO_BREDR 0x04 /* BR/EDR not supported */
+
+#define sys_put_be16(a,b) put_be16(b, a)
+#define sys_put_le16(a,b) put_le16(b, a)
+#define sys_put_be32(a,b) put_be32(b, a)
+#define sys_get_be16(a) get_be16(a)
+#define sys_get_le16(a) get_le16(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)
+#define sys_be32_to_cpu(a) be32toh(a)
+#define sys_be16_to_cpu(a) be16toh(a)
+#define sys_le16_to_cpu(a) le16toh(a)
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+#define CODE_UNREACHABLE __builtin_unreachable()
+#define __ASSERT(code, str) \
+ do { \
+ if (!(code)) BT_ERR(str); \
+ assert(code); \
+ } while (0);
+
+#define __ASSERT_NO_MSG(test) __ASSERT(test, "")
+
+/* Mesh is designed to not use mbuf chains */
+#if BT_DBG_ENABLED
+#define ASSERT_NOT_CHAIN(om) assert(SLIST_NEXT(om, om_next) == NULL)
+#else
+#define ASSERT_NOT_CHAIN(om) (void)(om)
+#endif
+
+#define __packed __attribute__((__packed__))
+
+#define MSEC_PER_SEC (1000)
+#define K_MSEC(ms) (ms)
+#define K_SECONDS(s) K_MSEC((s) * MSEC_PER_SEC)
+#define K_MINUTES(m) K_SECONDS((m) * 60)
+#define K_HOURS(h) K_MINUTES((h) * 60)
+
+#ifndef BIT
+#define BIT(n) (1UL << (n))
+#endif
+
+#define BIT_MASK(n) (BIT(n) - 1)
+
+#define BT_GAP_ADV_FAST_INT_MIN_1 0x0030 /* 30 ms */
+#define BT_GAP_ADV_FAST_INT_MAX_1 0x0060 /* 60 ms */
+#define BT_GAP_ADV_FAST_INT_MIN_2 0x00a0 /* 100 ms */
+#define BT_GAP_ADV_FAST_INT_MAX_2 0x00f0 /* 150 ms */
+#define BT_GAP_ADV_SLOW_INT_MIN 0x0640 /* 1 s */
+#define BT_GAP_ADV_SLOW_INT_MAX 0x0780 /* 1.2 s */
+
+#ifndef MESH_LOG_MODULE
+#define MESH_LOG_MODULE BLE_MESH_LOG
+#endif
+
+#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
+#define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
+
+#define BLE_MESH_LOG(lvl, ...) CAT(MESH_LOG_MODULE, CAT(_, lvl))(__VA_ARGS__)
+
+#define BT_DBG(fmt, ...) BLE_MESH_LOG(DEBUG, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
+#define BT_INFO(fmt, ...) BLE_MESH_LOG(INFO, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
+#define BT_WARN(fmt, ...) BLE_MESH_LOG(WARN, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
+#define BT_ERR(fmt, ...) BLE_MESH_LOG(ERROR, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
+#define BT_GATT_ERR(_att_err) (-(_att_err))
+
+typedef ble_addr_t bt_addr_le_t;
+
+#define k_fifo_init(queue) ble_npl_eventq_init(queue)
+#define net_buf_simple_tailroom(buf) OS_MBUF_TRAILINGSPACE(buf)
+#define net_buf_tailroom(buf) net_buf_simple_tailroom(buf)
+#define net_buf_headroom(buf) ((buf)->om_data - &(buf)->om_databuf[buf->om_pkthdr_len])
+#define net_buf_simple_headroom(buf) net_buf_headroom(buf)
+#define net_buf_simple_tail(buf) ((buf)->om_data + (buf)->om_len)
+
+struct net_buf_simple_state {
+ /** Offset of the data pointer from the beginning of the storage */
+ u16_t offset;
+ /** Length of data */
+ u16_t len;
+};
+
+static inline struct os_mbuf * NET_BUF_SIMPLE(uint16_t size)
+{
+ struct os_mbuf *buf;
+
+ buf = os_msys_get(size, 0);
+ assert(buf);
+
+ return buf;
+}
+
+#define K_NO_WAIT (0)
+#define K_FOREVER (-1)
+
+#if MYNEWT_VAL(BLE_EXT_ADV)
+#define BT_MESH_ADV_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES))
+
+#if MYNEWT_VAL(BLE_MESH_PROXY)
+/* Note that BLE_MULTI_ADV_INSTANCES contains number of additional instances.
+ * Instance 0 is always there
+ */
+#if MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) < 1
+#error "Mesh needs at least BLE_MULTI_ADV_INSTANCES set to 1"
+#endif
+#define BT_MESH_ADV_GATT_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) - 1)
+#endif /* BLE_MESH_PROXY */
+#endif /* BLE_EXT_ADV */
+
+/* This is by purpose */
+static inline void net_buf_simple_init(struct os_mbuf *buf,
+ size_t reserve_head)
+{
+ /* This is called in Zephyr after init.
+ * Note in Mynewt case we don't care abour reserved head*/
+ buf->om_data = &buf->om_databuf[buf->om_pkthdr_len] + reserve_head;
+ buf->om_len = 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);
+uint16_t net_buf_simple_pull_le16(struct os_mbuf *om);
+uint16_t net_buf_simple_pull_be16(struct os_mbuf *om);
+uint32_t net_buf_simple_pull_be32(struct os_mbuf *om);
+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_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_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);
+uint8_t *net_buf_simple_push(struct os_mbuf *om, uint8_t len);
+void net_buf_reserve(struct os_mbuf *om, size_t reserve);
+
+#define net_buf_add_mem(a,b,c) os_mbuf_append(a,b,c)
+#define net_buf_simple_add_mem(a,b,c) os_mbuf_append(a,b,c)
+#define net_buf_add_u8(a,b) net_buf_simple_add_u8(a,b)
+#define net_buf_add(a,b) net_buf_simple_add(a,b)
+
+#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_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)
+#define net_buf_skip(a, b) net_buf_simple_pull_mem(a, b)
+
+#define BT_GATT_CCC_NOTIFY BLE_GATT_CHR_PROP_NOTIFY
+
+/** 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;
+};
+
+struct bt_pub_key_cb {
+ /** @brief Callback type for Public Key generation.
+ *
+ * Used to notify of the local public key or that the local key is not
+ * available (either because of a failure to read it or because it is
+ * being regenerated).
+ *
+ * @param key The local public key, or NULL in case of no key.
+ */
+ void (*func)(const u8_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);
+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);
+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,
+ const struct bt_data *sd, size_t sd_len);
+int bt_le_adv_stop(bool proxy);
+
+struct k_delayed_work {
+ struct ble_npl_callout 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);
+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);
+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);
+void k_delayed_work_add_arg(struct k_delayed_work *w, void *arg);
+uint32_t k_delayed_work_remaining_get(struct k_delayed_work *w);
+
+static inline void net_buf_simple_save(struct os_mbuf *buf,
+ struct net_buf_simple_state *state)
+{
+ state->offset = net_buf_simple_headroom(buf);
+ state->len = buf->om_len;
+}
+
+static inline void net_buf_simple_restore(struct os_mbuf *buf,
+ struct net_buf_simple_state *state)
+{
+ buf->om_data = &buf->om_databuf[buf->om_pkthdr_len] + state->offset;
+ buf->om_len = state->len;
+}
+
+static inline void sys_memcpy_swap(void *dst, const void *src, size_t length)
+{
+ __ASSERT(((src < dst && (src + length) <= dst) ||
+ (src > dst && (dst + length) <= src)),
+ "Source and destination buffers must not overlap");
+
+ src += length - 1;
+
+ for (; length > 0; length--) {
+ *((u8_t *)dst++) = *((u8_t *)src--);
+ }
+}
+
+#define popcount(x) __builtin_popcount(x)
+
+static inline unsigned int find_lsb_set(u32_t op)
+{
+ return __builtin_ffs(op);
+}
+
+static inline unsigned int find_msb_set(u32_t op)
+{
+ if (!op)
+ return 0;
+
+ 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
+
+/* 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 printk console_printf
+
+#define CONTAINER_OF(ptr, type, field) \
+ ((type *)(((char *)(ptr)) - offsetof(type, field)))
+
+
+#define k_sem ble_npl_sem
+
+static inline void k_sem_init(struct k_sem *sem, unsigned int initial_count,
+ unsigned int limit)
+{
+ ble_npl_sem_init(sem, initial_count);
+}
+
+static inline int k_sem_take(struct k_sem *sem, s32_t timeout)
+{
+ uint32_t ticks;
+
+ ble_npl_time_ms_to_ticks(timeout, &ticks);
+ return - ble_npl_sem_pend(sem, ticks);
+}
+
+static inline void k_sem_give(struct k_sem *sem)
+{
+ ble_npl_sem_release(sem);
+}
+
+/* Helpers to access the storage array, since we don't have access to its
+ * type at this point anymore.
+ */
+
+#define BUF_SIZE(pool) (pool->omp_pool->mp_block_size)
+
+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;
+
+ return (buf_ptr - pool_start) / BUF_SIZE(pool);
+}
+
+/* XXX: We should not use os_mbuf_pkthdr chains to represent a list of
+ * packets, this is a hack. For now this is not an issue, because mesh
+ * does not use os_mbuf chains. We should change this in the future.
+ */
+STAILQ_HEAD(net_buf_slist_t, os_mbuf_pkthdr);
+
+void net_buf_slist_init(struct net_buf_slist_t *list);
+bool net_buf_slist_is_empty(struct net_buf_slist_t *list);
+struct os_mbuf *net_buf_slist_peek_head(struct net_buf_slist_t *list);
+struct os_mbuf *net_buf_slist_peek_next(struct os_mbuf *buf);
+struct os_mbuf *net_buf_slist_get(struct net_buf_slist_t *list);
+void net_buf_slist_put(struct net_buf_slist_t *list, struct os_mbuf *buf);
+void net_buf_slist_remove(struct net_buf_slist_t *list, struct os_mbuf *prev,
+ struct os_mbuf *cur);
+void net_buf_slist_merge_slist(struct net_buf_slist_t *list,
+ struct net_buf_slist_t *list_to_append);
+#define NET_BUF_SLIST_FOR_EACH_NODE(head, var) STAILQ_FOREACH(var, head, omp_next)
+
+#if MYNEWT_VAL(BLE_MESH_SETTINGS)
+
+#define settings_load conf_load
+int settings_bytes_from_str(char *val_str, void *vp, int *len);
+char *settings_str_from_bytes(const void *vp, int vp_len,
+ char *buf, int buf_len);
+
+#define snprintk snprintf
+#define BT_SETTINGS_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1)
+#define settings_save_one conf_save_one
+
+#else
+
+static inline int
+settings_load(void)
+{
+ return 0;
+}
+
+#endif /* MYNEWT_VAL(MYNEWT_VAL_BLE_MESH_SETTINGS) */
+
+#define BUILD_ASSERT(cond) _Static_assert(cond, "")
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MESH_GLUE_ */
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
new file mode 100644
index 00000000..8ab8d6d5
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_cli.h
@@ -0,0 +1,81 @@
+/** @file
+ * @brief Bluetooth Mesh Health Client Model APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_HEALTH_CLI_H
+#define __BT_MESH_HEALTH_CLI_H
+
+/**
+ * @brief Bluetooth Mesh
+ * @defgroup bt_mesh_health_cli Bluetooth Mesh Health Client Model
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Mesh Health Client Model Context */
+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,
+ size_t fault_count);
+
+ struct k_sem op_sync;
+ u32_t op_pending;
+ void *op_param;
+};
+
+extern const struct bt_mesh_model_op bt_mesh_health_cli_op[];
+extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb;
+
+#define BT_MESH_MODEL_HEALTH_CLI(cli_data) \
+ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_op, \
+ NULL, cli_data, &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_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_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_period_get(u16_t net_idx, u16_t addr, u16_t app_idx,
+ u8_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_attention_get(u16_t net_idx, u16_t addr, u16_t app_idx,
+ u8_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);
+
+s32_t bt_mesh_health_cli_timeout_get(void);
+void bt_mesh_health_cli_timeout_set(s32_t timeout);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_HEALTH_CLI_H */
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
new file mode 100644
index 00000000..83982376
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/health_srv.h
@@ -0,0 +1,100 @@
+/** @file
+ * @brief Bluetooth Mesh Health Server Model APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_HEALTH_SRV_H
+#define __BT_MESH_HEALTH_SRV_H
+
+/**
+ * @brief Mesh Bluetooth Mesh Health Server Model
+ * @defgroup bt_mesh_health_srv
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+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);
+
+ /* 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);
+
+ /* Clear registered faults */
+ int (*fault_clear)(struct bt_mesh_model *model, u16_t company_id);
+
+ /* Run a specific test */
+ int (*fault_test)(struct bt_mesh_model *model, u8_t test_id,
+ u16_t company_id);
+
+ /* Attention on */
+ void (*attn_on)(struct bt_mesh_model *model);
+
+ /* Attention off */
+ void (*attn_off)(struct bt_mesh_model *model);
+};
+
+/** @def BT_MESH_HEALTH_FAULT_MSG
+ *
+ * A helper to define a health fault message.
+ *
+ * @param max_faults Maximum number of faults the element can have.
+ *
+ * @return a New net_buf_simple of the needed size.
+ */
+#define BT_MESH_HEALTH_FAULT_MSG(max_faults) \
+ NET_BUF_SIMPLE(1 + 3 + (max_faults))
+
+/** Mesh Health Server Model Context */
+struct bt_mesh_health_srv {
+ struct bt_mesh_model *model;
+
+ /* Optional callback struct */
+ const struct bt_mesh_health_srv_cb *cb;
+
+ /* Attention Timer state */
+ struct k_delayed_work attn_timer;
+};
+
+int bt_mesh_fault_update(struct bt_mesh_elem *elem);
+
+extern const struct bt_mesh_model_op bt_mesh_health_srv_op[];
+extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb;
+
+/** @def BT_MESH_MODEL_HEALTH_SRV
+ *
+ * Define a new health server model. Note that this API needs to be
+ * repeated for each element that the application wants to have a
+ * health server model on. Each instance also needs a unique
+ * bt_mesh_health_srv and bt_mesh_model_pub context.
+ *
+ * @param srv Pointer to a unique struct bt_mesh_health_srv.
+ * @param pub Pointer to a unique struct bt_mesh_model_pub.
+ *
+ * @return New mesh model instance.
+ */
+#define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \
+ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_op, \
+ pub, srv, &bt_mesh_health_srv_cb)
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_HEALTH_SRV_H */
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
new file mode 100644
index 00000000..4a5bedba
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/main.h
@@ -0,0 +1,441 @@
+/** @file
+ * @brief Bluetooth Mesh Profile APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_MAIN_H
+#define __BT_MESH_MAIN_H
+
+/**
+ * @brief Bluetooth Mesh Provisioning
+ * @defgroup bt_mesh_prov Bluetooth Mesh Provisioning
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ BT_MESH_NO_OUTPUT = 0,
+ BT_MESH_BLINK = BIT(0),
+ BT_MESH_BEEP = BIT(1),
+ BT_MESH_VIBRATE = BIT(2),
+ BT_MESH_DISPLAY_NUMBER = BIT(3),
+ BT_MESH_DISPLAY_STRING = BIT(4),
+} bt_mesh_output_action_t;
+
+typedef enum {
+ BT_MESH_NO_INPUT = 0,
+ BT_MESH_PUSH = BIT(0),
+ BT_MESH_TWIST = BIT(1),
+ BT_MESH_ENTER_NUMBER = BIT(2),
+ BT_MESH_ENTER_STRING = BIT(3),
+} bt_mesh_input_action_t;
+
+typedef enum {
+ BT_MESH_PROV_ADV = BIT(0),
+ BT_MESH_PROV_GATT = BIT(1),
+} bt_mesh_prov_bearer_t;
+
+typedef enum {
+ BT_MESH_PROV_OOB_OTHER = BIT(0),
+ BT_MESH_PROV_OOB_URI = BIT(1),
+ BT_MESH_PROV_OOB_2D_CODE = BIT(2),
+ BT_MESH_PROV_OOB_BAR_CODE = BIT(3),
+ BT_MESH_PROV_OOB_NFC = BIT(4),
+ BT_MESH_PROV_OOB_NUMBER = BIT(5),
+ BT_MESH_PROV_OOB_STRING = BIT(6),
+ /* 7 - 10 are reserved */
+ BT_MESH_PROV_OOB_ON_BOX = BIT(11),
+ BT_MESH_PROV_OOB_IN_BOX = BIT(12),
+ BT_MESH_PROV_OOB_ON_PAPER = BIT(13),
+ BT_MESH_PROV_OOB_IN_MANUAL = BIT(14),
+ BT_MESH_PROV_OOB_ON_DEV = BIT(15),
+} bt_mesh_prov_oob_info_t;
+
+/** Provisioning properties & capabilities. */
+struct bt_mesh_prov {
+ /** The UUID that's used when advertising as unprovisioned */
+ const u8_t *uuid;
+
+ /** Optional URI. This will be advertised separately from the
+ * unprovisioned beacon, however the unprovisioned beacon will
+ * contain a hash of it so the two can be associated by the
+ * provisioner.
+ */
+ const char *uri;
+
+ /** Out of Band information field. */
+ bt_mesh_prov_oob_info_t oob_info;
+
+ /** Static OOB value */
+ const u8_t *static_val;
+ /** Static OOB value length */
+ u8_t static_val_len;
+
+ /** Maximum size of Output OOB supported */
+ u8_t output_size;
+ /** Supported Output OOB Actions */
+ u16_t output_actions;
+
+ /* Maximum size of Input OOB supported */
+ u8_t input_size;
+ /** Supported Input OOB Actions */
+ u16_t input_actions;
+
+ /** @brief Output of a number is requested.
+ *
+ * This callback notifies the application that it should
+ * output the given number using the given action.
+ *
+ * @param act Action for outputting the number.
+ * @param num Number to be outputted.
+ *
+ * @return Zero on success or negative error code otherwise
+ */
+ int (*output_number)(bt_mesh_output_action_t act, u32_t num);
+
+ /** @brief Output of a string is requested.
+ *
+ * This callback notifies the application that it should
+ * display the given string to the user.
+ *
+ * @param str String to be displayed.
+ *
+ * @return Zero on success or negative error code otherwise
+ */
+ int (*output_string)(const char *str);
+
+ /** @brief Input is requested.
+ *
+ * This callback notifies the application that it should
+ * request input from the user using the given action. The
+ * requested input will either be a string or a number, and
+ * the application needs to consequently call the
+ * bt_mesh_input_string() or bt_mesh_input_number() functions
+ * once the data has been acquired from the user.
+ *
+ * @param act Action for inputting data.
+ * @param num Maximum size of the inputted data.
+ *
+ * @return Zero on success or negative error code otherwise
+ */
+ int (*input)(bt_mesh_input_action_t act, u8_t size);
+
+ /** @brief The other device finished their OOB input.
+ *
+ * This callback notifies the application that it should stop
+ * displaying its output OOB value, as the other party finished their
+ * OOB input.
+ */
+ void (*input_complete)(void);
+
+ /** @brief Unprovisioned beacon has been received.
+ *
+ * This callback notifies the application that an unprovisioned
+ * beacon has been received.
+ *
+ * @param uuid UUID
+ * @param oob_info OOB Information
+ * @param uri_hash Pointer to URI Hash value. NULL if no hash was
+ * present in the beacon.
+ */
+ void (*unprovisioned_beacon)(u8_t uuid[16],
+ bt_mesh_prov_oob_info_t oob_info,
+ u32_t *uri_hash);
+
+ /** @brief Provisioning link has been opened.
+ *
+ * This callback notifies the application that a provisioning
+ * link has been opened on the given provisioning bearer.
+ *
+ * @param bearer Provisioning bearer.
+ */
+ void (*link_open)(bt_mesh_prov_bearer_t bearer);
+
+ /** @brief Provisioning link has been closed.
+ *
+ * This callback notifies the application that a provisioning
+ * link has been closed on the given provisioning bearer.
+ *
+ * @param bearer Provisioning bearer.
+ */
+ void (*link_close)(bt_mesh_prov_bearer_t bearer);
+
+ /** @brief Provisioning is complete.
+ *
+ * This callback notifies the application that provisioning has
+ * been successfully completed, and that the local node has been
+ * assigned the specified NetKeyIndex and primary element address.
+ *
+ * @param net_idx NetKeyIndex given during provisioning.
+ * @param addr Primary element address.
+ */
+ void (*complete)(u16_t net_idx, u16_t addr);
+
+ /** @brief A new node has been added to the provisioning database.
+ *
+ * This callback notifies the application that provisioning has
+ * been successfully completed, and that a node has been assigned
+ * the specified NetKeyIndex and primary element address.
+ *
+ * @param net_idx NetKeyIndex given during provisioning.
+ * @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);
+
+ /** @brief Node has been reset.
+ *
+ * This callback notifies the application that the local node
+ * has been reset and needs to be reprovisioned. The node will
+ * not automatically advertise as unprovisioned, rather the
+ * bt_mesh_prov_enable() API needs to be called to enable
+ * unprovisioned advertising on one or more provisioning bearers.
+ */
+ void (*reset)(void);
+};
+
+/** @brief Provide provisioning input OOB string.
+ *
+ * This is intended to be called after the bt_mesh_prov input callback
+ * has been called with BT_MESH_ENTER_STRING as the action.
+ *
+ * @param str String.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_input_string(const char *str);
+
+/** @brief Provide provisioning input OOB number.
+ *
+ * This is intended to be called after the bt_mesh_prov input callback
+ * has been called with BT_MESH_ENTER_NUMBER as the action.
+ *
+ * @param num Number.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_input_number(u32_t num);
+
+/** @brief Enable specific provisioning bearers
+ *
+ * Enable one or more provisioning bearers.
+ *
+ * @param bearers Bit-wise or of provisioning bearers.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers);
+
+/** @brief Disable specific provisioning bearers
+ *
+ * Disable one or more provisioning bearers.
+ *
+ * @param bearers Bit-wise or of provisioning bearers.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers);
+
+/**
+ * @}
+ */
+
+/**
+ * @brief Bluetooth Mesh
+ * @defgroup bt_mesh Bluetooth Mesh
+ * @ingroup bluetooth
+ * @{
+ */
+
+/* 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)
+#define BT_MESH_FEAT_FRIEND BIT(2)
+#define BT_MESH_FEAT_LOW_POWER BIT(3)
+#define BT_MESH_FEAT_SUPPORTED (BT_MESH_FEAT_RELAY | \
+ BT_MESH_FEAT_PROXY | \
+ BT_MESH_FEAT_FRIEND | \
+ BT_MESH_FEAT_LOW_POWER)
+
+/** @brief Initialize Mesh support
+ *
+ * After calling this API, the node will not automatically advertise as
+ * unprovisioned, rather the bt_mesh_prov_enable() API needs to be called
+ * to enable unprovisioned advertising on one or more provisioning bearers.
+ *
+ * @param own_addr_type Node address type
+ * @param prov Node provisioning information.
+ * @param comp Node Composition.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_init(u8_t own_addr_type,
+ const struct bt_mesh_prov *prov,
+ const struct bt_mesh_comp *comp);
+
+/** @brief Reset the state of the local Mesh node.
+ *
+ * Resets the state of the node, which means that it needs to be
+ * reprovisioned to become an active node in a Mesh network again.
+ *
+ * After calling this API, the node will not automatically advertise as
+ * unprovisioned, rather the bt_mesh_prov_enable() API needs to be called
+ * to enable unprovisioned advertising on one or more provisioning bearers.
+ *
+ */
+void bt_mesh_reset(void);
+
+/** @brief Suspend the Mesh network temporarily.
+ *
+ * This API can be used for power saving purposes, but the user should be
+ * aware that leaving the local node suspended for a long period of time
+ * may cause it to become permanently disconnected from the Mesh network.
+ * If at all possible, the Friendship feature should be used instead, to
+ * make the node into a Low Power Node.
+ *
+ * @return 0 on success, or (negative) error code on failure.
+ */
+int bt_mesh_suspend(void);
+
+/** @brief Resume a suspended Mesh network.
+ *
+ * This API resumes the local node, after it has been suspended using the
+ * bt_mesh_suspend() API.
+ *
+ * @return 0 on success, or (negative) error code on failure.
+ */
+int bt_mesh_resume(void);
+
+/** @brief Provision the local Mesh Node.
+ *
+ * This API should normally not be used directly by the application. The
+ * only exception is for testing purposes where manual provisioning is
+ * desired without an actual external provisioner.
+ *
+ * @param net_key Network Key
+ * @param net_idx Network Key Index
+ * @param flags Provisioning Flags
+ * @param iv_index IV Index
+ * @param addr Primary element address
+ * @param dev_key Device Key
+ *
+ * @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]);
+
+/** @brief Provision a Mesh Node using PB-ADV
+ *
+ * @param uuid UUID
+ * @param net_idx Network Key Index
+ * @param addr Address to assign to remote device. If addr is 0, the lowest
+ * available address will be chosen.
+ * @param attention_duration The attention duration to be send to remote device
+ *
+ * @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);
+
+/** @brief Check if the local node has been provisioned.
+ *
+ * This API can be used to check if the local node has been provisioned
+ * or not. It can e.g. be helpful to determine if there was a stored
+ * network in flash, i.e. if the network was restored after calling
+ * settings_load().
+ *
+ * @return True if the node is provisioned. False otherwise.
+ */
+bool bt_mesh_is_provisioned(void);
+
+/** @brief Toggle the IV Update test mode
+ *
+ * This API is only available if the IV Update test mode has been enabled
+ * in Kconfig. It is needed for passing most of the IV Update qualification
+ * test cases.
+ *
+ * @param enable true to enable IV Update test mode, false to disable it.
+ */
+void bt_mesh_iv_update_test(bool enable);
+
+/** @brief Toggle the IV Update state
+ *
+ * This API is only available if the IV Update test mode has been enabled
+ * in Kconfig. It is needed for passing most of the IV Update qualification
+ * test cases.
+ *
+ * @return true if IV Update In Progress state was entered, false otherwise.
+ */
+bool bt_mesh_iv_update(void);
+
+/** @brief Toggle the Low Power feature of the local device
+ *
+ * Enables or disables the Low Power feature of the local device. This is
+ * exposed as a run-time feature, since the device might want to change
+ * this e.g. based on being plugged into a stable power source or running
+ * from a battery power source.
+ *
+ * @param enable true to enable LPN functionality, false to disable it.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_lpn_set(bool enable);
+
+/** @brief Send out a Friend Poll message.
+ *
+ * Send a Friend Poll message to the Friend of this node. If there is no
+ * established Friendship the function will return an error.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_lpn_poll(void);
+
+/** @brief Register a callback for Friendship changes.
+ *
+ * Registers a callback that will be called whenever Friendship gets
+ * established or is lost.
+ *
+ * @param cb Function to call when the Friendship status changes.
+ */
+void bt_mesh_lpn_set_cb(void (*cb)(u16_t friend_addr, bool established));
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_MAIN_H */
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
new file mode 100644
index 00000000..9ba63ef0
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/mesh.h
@@ -0,0 +1,26 @@
+/** @file
+ * @brief Bluetooth Mesh Profile APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_H
+#define __BT_MESH_H
+
+#include <stddef.h>
+#include "syscfg/syscfg.h"
+#include "os/os_mbuf.h"
+
+#include "glue.h"
+#include "access.h"
+#include "main.h"
+#include "cfg_srv.h"
+#include "health_srv.h"
+#include "cfg_cli.h"
+#include "health_cli.h"
+#include "proxy.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
new file mode 100644
index 00000000..f2e77a47
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_cli.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef __MODEL_CLI_H__
+#define __MODEL_CLI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_mesh_gen_model_cli {
+ struct bt_mesh_model *model;
+
+ struct k_sem op_sync;
+ u32_t op_pending;
+ void *op_param;
+};
+
+extern const struct bt_mesh_model_op gen_onoff_cli_op[];
+extern const struct bt_mesh_model_cb bt_mesh_gen_onoff_cli_cb;
+
+#define BT_MESH_MODEL_GEN_ONOFF_CLI(cli_data, pub) \
+ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_ONOFF_CLI, gen_onoff_cli_op, pub,\
+ cli_data, &bt_mesh_gen_onoff_cli_cb)
+
+extern const struct bt_mesh_model_op gen_level_cli_op[];
+extern const struct bt_mesh_model_cb bt_mesh_gen_level_cli_cb;
+
+#define BT_MESH_MODEL_GEN_LEVEL_CLI(cli_data, pub) \
+ 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MODEL_CLI_H__ */
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
new file mode 100644
index 00000000..e498ad34
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/model_srv.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef __MODEL_SRV_H__
+#define __MODEL_SRV_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+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);
+};
+
+extern const struct bt_mesh_model_op gen_onoff_srv_op[];
+extern const struct bt_mesh_model_cb gen_onoff_srv_cb;
+
+#define BT_MESH_MODEL_GEN_ONOFF_SRV(srv, pub) \
+ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_ONOFF_SRV, \
+ gen_onoff_srv_op, pub, srv, &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);
+};
+
+extern const struct bt_mesh_model_op gen_level_srv_op[];
+extern const struct bt_mesh_model_cb gen_level_srv_cb;
+
+#define BT_MESH_MODEL_GEN_LEVEL_SRV(srv, pub) \
+ BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_LEVEL_SRV, \
+ gen_level_srv_op, pub, srv, &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);
+};
+
+extern const struct bt_mesh_model_op light_lightness_srv_op[];
+extern const struct bt_mesh_model_cb light_lightness_srv_cb;
+
+#define BT_MESH_MODEL_LIGHT_LIGHTNESS_SRV(srv, pub) \
+ 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));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MODEL_SRV_H__ */
diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/porting.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/porting.h
new file mode 100644
index 00000000..1667a8a0
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/porting.h
@@ -0,0 +1,27 @@
+/** @file
+ * @brief Bluetooth Mesh Porting APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_PORTING_H
+#define __BT_MESH_PORTING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void mesh_adv_thread(void *args);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_PORTING_H */
diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/proxy.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/proxy.h
new file mode 100644
index 00000000..63bbfa3e
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/proxy.h
@@ -0,0 +1,43 @@
+/** @file
+ * @brief Bluetooth Mesh Proxy APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_PROXY_H
+#define __BT_MESH_PROXY_H
+
+/**
+ * @brief Bluetooth Mesh Proxy
+ * @defgroup bt_mesh_proxy Bluetooth Mesh Proxy
+ * @ingroup bt_mesh
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enable advertising with Node Identity.
+ *
+ * This API requires that GATT Proxy support has been enabled. Once called
+ * each subnet will start advertising using Node Identity for the next
+ * 60 seconds.
+ *
+ * @return 0 on success, or (negative) error code on failure.
+ */
+int bt_mesh_proxy_identity_enable(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_PROXY_H */
diff --git a/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/slist.h b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/slist.h
new file mode 100644
index 00000000..8a858f83
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/slist.h
@@ -0,0 +1,468 @@
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/**
+ * @file
+ *
+ * @brief Single-linked list implementation
+ *
+ * Single-linked list implementation using inline macros/functions.
+ * This API is not thread safe, and thus if a list is used across threads,
+ * calls to functions must be protected with synchronization primitives.
+ */
+
+#ifndef __SLIST_H__
+#define __SLIST_H__
+
+#include <stddef.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct _snode {
+ struct _snode *next;
+};
+
+typedef struct _snode sys_snode_t;
+
+struct _slist {
+ sys_snode_t *head;
+ sys_snode_t *tail;
+};
+
+typedef struct _slist sys_slist_t;
+
+/**
+ * @brief Provide the primitive to iterate on a list
+ * Note: the loop is unsafe and thus __sn should not be removed
+ *
+ * User _MUST_ add the loop statement curly braces enclosing its own code:
+ *
+ * SYS_SLIST_FOR_EACH_NODE(l, n) {
+ * <user code>
+ * }
+ *
+ * This and other SYS_SLIST_*() macros are not thread safe.
+ *
+ * @param __sl A pointer on a sys_slist_t to iterate on
+ * @param __sn A sys_snode_t pointer to peek each node of the list
+ */
+#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \
+ for (__sn = sys_slist_peek_head(__sl); __sn; \
+ __sn = sys_slist_peek_next(__sn))
+
+/**
+ * @brief Provide the primitive to iterate on a list, from a node in the list
+ * Note: the loop is unsafe and thus __sn should not be removed
+ *
+ * User _MUST_ add the loop statement curly braces enclosing its own code:
+ *
+ * SYS_SLIST_ITERATE_FROM_NODE(l, n) {
+ * <user code>
+ * }
+ *
+ * Like SYS_SLIST_FOR_EACH_NODE(), but __dn already contains a node in the list
+ * where to start searching for the next entry from. If NULL, it starts from
+ * the head.
+ *
+ * This and other SYS_SLIST_*() macros are not thread safe.
+ *
+ * @param __sl A pointer on a sys_slist_t to iterate on
+ * @param __sn A sys_snode_t pointer to peek each node of the list
+ * it contains the starting node, or NULL to start from the head
+ */
+#define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \
+ for (__sn = __sn ? sys_slist_peek_next_no_check(__sn) \
+ : sys_slist_peek_head(__sl); \
+ __sn; \
+ __sn = sys_slist_peek_next(__sn))
+
+/**
+ * @brief Provide the primitive to safely iterate on a list
+ * Note: __sn can be removed, it will not break the loop.
+ *
+ * User _MUST_ add the loop statement curly braces enclosing its own code:
+ *
+ * SYS_SLIST_FOR_EACH_NODE_SAFE(l, n, s) {
+ * <user code>
+ * }
+ *
+ * This and other SYS_SLIST_*() macros are not thread safe.
+ *
+ * @param __sl A pointer on a sys_slist_t to iterate on
+ * @param __sn A sys_snode_t pointer to peek each node of the list
+ * @param __sns A sys_snode_t pointer for the loop to run safely
+ */
+#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
+ for (__sn = sys_slist_peek_head(__sl), \
+ __sns = sys_slist_peek_next(__sn); \
+ __sn; __sn = __sns, \
+ __sns = sys_slist_peek_next(__sn))
+
+/*
+ * @brief Provide the primitive to resolve the container of a list node
+ * Note: it is safe to use with NULL pointer nodes
+ *
+ * @param __ln A pointer on a sys_node_t to get its container
+ * @param __cn Container struct type pointer
+ * @param __n The field name of sys_node_t within the container struct
+ */
+#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \
+ ((__ln) ? CONTAINER_OF((__ln), __typeof__(*(__cn)), __n) : NULL)
+/*
+ * @brief Provide the primitive to peek container of the list head
+ *
+ * @param __sl A pointer on a sys_slist_t to peek
+ * @param __cn Container struct type pointer
+ * @param __n The field name of sys_node_t within the container struct
+ */
+#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
+ SYS_SLIST_CONTAINER(sys_slist_peek_head(__sl), __cn, __n)
+
+/*
+ * @brief Provide the primitive to peek container of the list tail
+ *
+ * @param __sl A pointer on a sys_slist_t to peek
+ * @param __cn Container struct type pointer
+ * @param __n The field name of sys_node_t within the container struct
+ */
+#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
+ SYS_SLIST_CONTAINER(sys_slist_peek_tail(__sl), __cn, __n)
+
+/*
+ * @brief Provide the primitive to peek the next container
+ *
+ * @param __cn Container struct type pointer
+ * @param __n The field name of sys_node_t within the container struct
+ */
+
+#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
+ ((__cn) ? SYS_SLIST_CONTAINER(sys_slist_peek_next(&((__cn)->__n)), \
+ __cn, __n) : NULL)
+
+/**
+ * @brief Provide the primitive to iterate on a list under a container
+ * Note: the loop is unsafe and thus __cn should not be detached
+ *
+ * User _MUST_ add the loop statement curly braces enclosing its own code:
+ *
+ * SYS_SLIST_FOR_EACH_CONTAINER(l, c, n) {
+ * <user code>
+ * }
+ *
+ * @param __sl A pointer on a sys_slist_t to iterate on
+ * @param __cn A pointer to peek each entry of the list
+ * @param __n The field name of sys_node_t within the container struct
+ */
+#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
+ for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n); __cn; \
+ __cn = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n))
+
+/**
+ * @brief Provide the primitive to safely iterate on a list under a container
+ * Note: __cn can be detached, it will not break the loop.
+ *
+ * User _MUST_ add the loop statement curly braces enclosing its own code:
+ *
+ * SYS_SLIST_FOR_EACH_NODE_SAFE(l, c, cn, n) {
+ * <user code>
+ * }
+ *
+ * @param __sl A pointer on a sys_slist_t to iterate on
+ * @param __cn A pointer to peek each entry of the list
+ * @param __cns A pointer for the loop to run safely
+ * @param __n The field name of sys_node_t within the container struct
+ */
+#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
+ for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n), \
+ __cns = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n); __cn; \
+ __cn = __cns, __cns = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n))
+
+/**
+ * @brief Initialize a list
+ *
+ * @param list A pointer on the list to initialize
+ */
+static inline void sys_slist_init(sys_slist_t *list)
+{
+ list->head = NULL;
+ list->tail = NULL;
+}
+
+#define SYS_SLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
+
+/**
+ * @brief Test if the given list is empty
+ *
+ * @param list A pointer on the list to test
+ *
+ * @return a boolean, true if it's empty, false otherwise
+ */
+static inline bool sys_slist_is_empty(sys_slist_t *list)
+{
+ return (!list->head);
+}
+
+/**
+ * @brief Peek the first node from the list
+ *
+ * @param list A point on the list to peek the first node from
+ *
+ * @return A pointer on the first node of the list (or NULL if none)
+ */
+static inline sys_snode_t *sys_slist_peek_head(sys_slist_t *list)
+{
+ return list->head;
+}
+
+/**
+ * @brief Peek the last node from the list
+ *
+ * @param list A point on the list to peek the last node from
+ *
+ * @return A pointer on the last node of the list (or NULL if none)
+ */
+static inline sys_snode_t *sys_slist_peek_tail(sys_slist_t *list)
+{
+ return list->tail;
+}
+
+/**
+ * @brief Peek the next node from current node, node is not NULL
+ *
+ * Faster then sys_slist_peek_next() if node is known not to be NULL.
+ *
+ * @param node A pointer on the node where to peek the next node
+ *
+ * @return a pointer on the next node (or NULL if none)
+ */
+static inline sys_snode_t *sys_slist_peek_next_no_check(sys_snode_t *node)
+{
+ return node->next;
+}
+
+/**
+ * @brief Peek the next node from current node
+ *
+ * @param node A pointer on the node where to peek the next node
+ *
+ * @return a pointer on the next node (or NULL if none)
+ */
+static inline sys_snode_t *sys_slist_peek_next(sys_snode_t *node)
+{
+ return node ? sys_slist_peek_next_no_check(node) : NULL;
+}
+
+/**
+ * @brief Prepend a node to the given list
+ *
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param node A pointer on the node to prepend
+ */
+static inline void sys_slist_prepend(sys_slist_t *list,
+ sys_snode_t *node)
+{
+ node->next = list->head;
+ list->head = node;
+
+ if (!list->tail) {
+ list->tail = list->head;
+ }
+}
+
+/**
+ * @brief Append a node to the given list
+ *
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param node A pointer on the node to append
+ */
+static inline void sys_slist_append(sys_slist_t *list,
+ sys_snode_t *node)
+{
+ node->next = NULL;
+
+ if (!list->tail) {
+ list->tail = node;
+ list->head = node;
+ } else {
+ list->tail->next = node;
+ list->tail = node;
+ }
+}
+
+/**
+ * @brief Append a list to the given list
+ *
+ * Append a singly-linked, NULL-terminated list consisting of nodes containing
+ * the pointer to the next node as the first element of a node, to @a list.
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param head A pointer to the first element of the list to append
+ * @param tail A pointer to the last element of the list to append
+ */
+static inline void sys_slist_append_list(sys_slist_t *list,
+ void *head, void *tail)
+{
+ if (!list->tail) {
+ list->head = (sys_snode_t *)head;
+ list->tail = (sys_snode_t *)tail;
+ } else {
+ list->tail->next = (sys_snode_t *)head;
+ list->tail = (sys_snode_t *)tail;
+ }
+}
+
+/**
+ * @brief merge two slists, appending the second one to the first
+ *
+ * When the operation is completed, the appending list is empty.
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param list_to_append A pointer to the list to append.
+ */
+static inline void sys_slist_merge_slist(sys_slist_t *list,
+ sys_slist_t *list_to_append)
+{
+ sys_slist_append_list(list, list_to_append->head,
+ list_to_append->tail);
+ sys_slist_init(list_to_append);
+}
+
+/**
+ * @brief Insert a node to the given list
+ *
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param prev A pointer on the previous node
+ * @param node A pointer on the node to insert
+ */
+static inline void sys_slist_insert(sys_slist_t *list,
+ sys_snode_t *prev,
+ sys_snode_t *node)
+{
+ if (!prev) {
+ sys_slist_prepend(list, node);
+ } else if (!prev->next) {
+ sys_slist_append(list, node);
+ } else {
+ node->next = prev->next;
+ prev->next = node;
+ }
+}
+
+/**
+ * @brief Fetch and remove the first node of the given list
+ *
+ * List must be known to be non-empty.
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ *
+ * @return A pointer to the first node of the list
+ */
+static inline sys_snode_t *sys_slist_get_not_empty(sys_slist_t *list)
+{
+ sys_snode_t *node = list->head;
+
+ list->head = node->next;
+ if (list->tail == node) {
+ list->tail = list->head;
+ }
+
+ return node;
+}
+
+/**
+ * @brief Fetch and remove the first node of the given list
+ *
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ *
+ * @return A pointer to the first node of the list (or NULL if empty)
+ */
+static inline sys_snode_t *sys_slist_get(sys_slist_t *list)
+{
+ return sys_slist_is_empty(list) ? NULL : sys_slist_get_not_empty(list);
+}
+
+/**
+ * @brief Remove a node
+ *
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param prev_node A pointer on the previous node
+ * (can be NULL, which means the node is the list's head)
+ * @param node A pointer on the node to remove
+ */
+static inline void sys_slist_remove(sys_slist_t *list,
+ sys_snode_t *prev_node,
+ sys_snode_t *node)
+{
+ if (!prev_node) {
+ list->head = node->next;
+
+ /* Was node also the tail? */
+ if (list->tail == node) {
+ list->tail = list->head;
+ }
+ } else {
+ prev_node->next = node->next;
+
+ /* Was node the tail? */
+ if (list->tail == node) {
+ list->tail = prev_node;
+ }
+ }
+
+ node->next = NULL;
+}
+
+/**
+ * @brief Find and remove a node from a list
+ *
+ * This and other sys_slist_*() functions are not thread safe.
+ *
+ * @param list A pointer on the list to affect
+ * @param node A pointer on the node to remove from the list
+ *
+ * @return true if node was removed
+ */
+static inline bool sys_slist_find_and_remove(sys_slist_t *list,
+ sys_snode_t *node)
+{
+ sys_snode_t *prev = NULL;
+ sys_snode_t *test;
+
+ SYS_SLIST_FOR_EACH_NODE(list, test) {
+ if (test == node) {
+ sys_slist_remove(list, prev, node);
+ return true;
+ }
+
+ prev = test;
+ }
+
+ return false;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SLIST_H__ */
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
new file mode 100644
index 00000000..4c2b2a61
--- /dev/null
+++ b/src/libs/mynewt-nimble/nimble/host/mesh/include/mesh/testing.h
@@ -0,0 +1,105 @@
+/**
+ * @file testing.h
+ * @brief Internal API for Bluetooth testing.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef __BT_TESTING_H
+#define __BT_TESTING_H
+
+#include "slist.h"
+#include "glue.h"
+#include "access.h"
+
+/**
+ * @brief Bluetooth testing
+ * @defgroup bt_test_cb Bluetooth testing callbacks
+ * @ingroup bluetooth
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @brief Bluetooth Testing callbacks structure.
+ *
+ * Callback structure to be used for Bluetooth testing purposes.
+ * 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,
+ 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_trans_incomp_timer_exp)(void);
+
+ sys_snode_t node;
+};
+
+/** Register callbacks for Bluetooth testing purposes
+ *
+ * @param cb bt_test_cb callback structure
+ */
+void bt_test_cb_register(struct bt_test_cb *cb);
+
+/** Unregister callbacks for Bluetooth testing purposes
+ *
+ * @param cb bt_test_cb callback structure
+ */
+void bt_test_cb_unregister(struct bt_test_cb *cb);
+
+/** Send Friend Subscription List Add message.
+ *
+ * Used by Low Power node to send the group address for which messages are to
+ * be stored by Friend node.
+ *
+ * @param group Group address
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_test_mesh_lpn_group_add(u16_t group);
+
+/** Send Friend Subscription List Remove message.
+ *
+ * Used by Low Power node to remove the group addresses from Friend node
+ * subscription list. Messages sent to those addresses will not be stored
+ * by Friend node.
+ *
+ * @param groups Group addresses
+ * @param groups_count Group addresses count
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+int bt_test_mesh_lpn_group_remove(u16_t *groups, size_t groups_count);
+
+/** Clear replay protection list cache.
+ *
+ * @return Zero on success or (negative) error code otherwise.
+ */
+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);
+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);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BT_TESTING_H */