Prvni ulozeni z chegewara githubu

This commit is contained in:
2023-02-25 16:13:53 +01:00
commit 01eb80dfe2
3279 changed files with 638407 additions and 0 deletions

View File

@ -0,0 +1,182 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_BLE_API_H_
#define _ESP_BLE_MESH_BLE_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** This enum value is the event of BLE operations */
typedef enum {
ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT, /*!< Start BLE advertising completion event */
ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT, /*!< Stop BLE advertising completion event */
ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT, /*!< Start BLE scanning completion event */
ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT, /*!< Stop BLE scanning completion event */
ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT, /*!< Scanning BLE advertising packets event */
ESP_BLE_MESH_BLE_EVT_MAX,
} esp_ble_mesh_ble_cb_event_t;
/** BLE operation callback parameters */
typedef union {
/**
* @brief ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of starting BLE advertising */
uint8_t index; /*!< Index of the BLE advertising */
} start_ble_advertising_comp; /*!< Event parameters of ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of stopping BLE advertising */
uint8_t index; /*!< Index of the BLE advertising */
} stop_ble_advertising_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of starting BLE scanning */
} start_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of stopping BLE scanning */
} stop_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
*/
struct {
uint8_t addr[6]; /*!< Device address */
uint8_t addr_type; /*!< Device address type */
uint8_t adv_type; /*!< Advertising data type */
uint8_t *data; /*!< Advertising data */
uint16_t length; /*!< Advertising data length */
int8_t rssi; /*!< RSSI of the advertising packet */
} scan_ble_adv_pkt; /*!< Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT */
} esp_ble_mesh_ble_cb_param_t;
/**
* @brief BLE scanning callback function type
*
* @param event: BLE scanning callback event type
* @param param: BLE scanning callback parameter
*/
typedef void (* esp_ble_mesh_ble_cb_t)(esp_ble_mesh_ble_cb_event_t event,
esp_ble_mesh_ble_cb_param_t *param);
/**
* @brief Register BLE scanning callback.
*
* @param[in] callback: Pointer to the BLE scaning callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback);
/** Count for sending BLE advertising packet infinitely */
#define ESP_BLE_MESH_BLE_ADV_INFINITE 0xFFFF
/*!< This enum value is the priority of BLE advertising packet */
typedef enum {
ESP_BLE_MESH_BLE_ADV_PRIO_LOW,
ESP_BLE_MESH_BLE_ADV_PRIO_HIGH,
} esp_ble_mesh_ble_adv_priority_t;
/** Context of BLE advertising parameters. */
typedef struct {
uint16_t interval; /*!< BLE advertising interval */
uint8_t adv_type; /*!< BLE advertising type */
uint8_t own_addr_type; /*!< Own address type */
uint8_t peer_addr_type; /*!< Peer address type */
uint8_t peer_addr[BD_ADDR_LEN]; /*!< Peer address */
uint16_t duration; /*!< Duration is milliseconds */
uint16_t period; /*!< Period in milliseconds */
uint16_t count; /*!< Number of advertising duration */
uint8_t priority:2; /*!< Priority of BLE advertising packet */
} esp_ble_mesh_ble_adv_param_t;
/** Context of BLE advertising data. */
typedef struct {
uint8_t adv_data_len; /*!< Advertising data length */
uint8_t adv_data[31]; /*!< Advertising data */
uint8_t scan_rsp_data_len; /*!< Scan response data length */
uint8_t scan_rsp_data[31]; /*!< Scan response data */
} esp_ble_mesh_ble_adv_data_t;
/**
* @brief This function is called to start BLE advertising with the corresponding data
* and parameters while BLE Mesh is working at the same time.
*
* @note 1. When this function is called, the BLE advertising packet will be posted to
* the BLE mesh adv queue in the mesh stack and waited to be sent.
* 2. In the BLE advertising parameters, the "duration" means the time used for
* sending the BLE advertising packet each time, it shall not be smaller than the
* advertising interval. When the packet is sent successfully, it will be posted
* to the adv queue again after the "period" time if the "count" is bigger than 0.
* The "count" means how many durations the packet will be sent after it is sent
* successfully for the first time. And if the "count" is set to 0xFFFF, which
* means the packet will be sent infinitely.
* 3. The "priority" means the priority of BLE advertising packet compared with
* BLE Mesh packets. Currently two options (i.e. low/high) are provided. If the
* "priority" is high, the BLE advertising packet will be posted to the front of
* adv queue. Otherwise it will be posted to the back of adv queue.
*
* @param[in] param: Pointer to the BLE advertising parameters
* @param[in] data: Pointer to the BLE advertising data and scan response data
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t *param,
const esp_ble_mesh_ble_adv_data_t *data);
/**
* @brief This function is called to stop BLE advertising with the corresponding index.
*
* @param[in] index: Index of BLE advertising
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_stop_ble_advertising(uint8_t index);
/** Context of BLE scanning parameters. */
typedef struct {
uint32_t duration; /*!< Duration used to scan normal BLE advertising packets */
} esp_ble_mesh_ble_scan_param_t;
/**
* @brief This function is called to start scanning normal BLE advertising packets
* and notifying the packets to the application layer.
*
* @param[in] param: Pointer to the BLE scanning parameters
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param);
/**
* @brief This function is called to stop notifying normal BLE advertising packets
* to the application layer.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_stop_ble_scanning(void);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_BLE_API_H_ */

View File

@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_COMMON_API_H_
#define _ESP_BLE_MESH_COMMON_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize BLE Mesh module.
* This API initializes provisioning capabilities and composition data information.
*
* @note After calling this API, the device needs to call esp_ble_mesh_prov_enable()
* to enable provisioning functionality again.
*
* @param[in] prov: Pointer to the device provisioning capabilities. This pointer must
* remain valid during the lifetime of the BLE Mesh device.
* @param[in] comp: Pointer to the device composition data information. This pointer
* must remain valid during the lifetime of the BLE Mesh device.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp);
/**
* @brief De-initialize BLE Mesh module.
*
* @note This function shall be invoked after esp_ble_mesh_client_model_deinit().
*
* @param[in] param: Pointer to the structure of BLE Mesh deinit parameters.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_COMMON_API_H_ */

View File

@ -0,0 +1,207 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_LOCAL_DATA_OPERATION_API_H_
#define _ESP_BLE_MESH_LOCAL_DATA_OPERATION_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Get the model publish period, the unit is ms.
*
* @param[in] model: Model instance pointer.
*
* @return Publish period value on success, 0 or (negative) error code from errno.h on failure.
*
*/
int32_t esp_ble_mesh_get_model_publish_period(esp_ble_mesh_model_t *model);
/**
* @brief Get the address of the primary element.
*
* @return Address of the primary element on success, or
* ESP_BLE_MESH_ADDR_UNASSIGNED on failure which means the device has not been provisioned.
*
*/
uint16_t esp_ble_mesh_get_primary_element_address(void);
/**
* @brief Check if the model has subscribed to the given group address.
* Note: E.g., once a status message is received and the destination address
* is a group address, the model uses this API to check if it is successfully subscribed
* to the given group address.
*
* @param[in] model: Pointer to the model.
* @param[in] group_addr: Group address.
*
* @return Pointer to the group address within the Subscription List of the model on success, or
* NULL on failure which means the model has not subscribed to the given group address.
* Note: With the pointer to the group address returned, you can reset the group address
* to 0x0000 in order to unsubscribe the model from the group.
*
*/
uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model,
uint16_t group_addr);
/**
* @brief Find the BLE Mesh element pointer via the element address.
*
* @param[in] element_addr: Element address.
*
* @return Pointer to the element on success, or NULL on failure.
*
*/
esp_ble_mesh_elem_t *esp_ble_mesh_find_element(uint16_t element_addr);
/**
* @brief Get the number of elements that have been registered.
*
* @return Number of elements.
*
*/
uint8_t esp_ble_mesh_get_element_count(void);
/**
* @brief Find the Vendor specific model with the given element,
* the company ID and the Vendor Model ID.
*
* @param[in] element: Element to which the model belongs.
* @param[in] company_id: A 16-bit company identifier assigned by the Bluetooth SIG.
* @param[in] model_id: A 16-bit vendor-assigned model identifier.
*
* @return Pointer to the Vendor Model on success, or NULL on failure which means the Vendor Model is not found.
*
*/
esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *element,
uint16_t company_id, uint16_t model_id);
/**
* @brief Find the SIG model with the given element and Model id.
*
* @param[in] element: Element to which the model belongs.
* @param[in] model_id: SIG model identifier.
*
* @return Pointer to the SIG Model on success, or NULL on failure which means the SIG Model is not found.
*
*/
esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element,
uint16_t model_id);
/**
* @brief Get the Composition data which has been registered.
*
* @return Pointer to the Composition data on success, or NULL on failure which means the Composition data is not initialized.
*
*/
const esp_ble_mesh_comp_t *esp_ble_mesh_get_composition_data(void);
/**
* @brief A local model of node or Provisioner subscribes a group address.
*
* @note This function shall not be invoked before node is provisioned or Provisioner is enabled.
*
* @param[in] element_addr: Unicast address of the element to which the model belongs.
* @param[in] company_id: A 16-bit company identifier.
* @param[in] model_id: A 16-bit model identifier.
* @param[in] group_addr: The group address to be subscribed.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_model_subscribe_group_addr(uint16_t element_addr, uint16_t company_id,
uint16_t model_id, uint16_t group_addr);
/**
* @brief A local model of node or Provisioner unsubscribes a group address.
*
* @note This function shall not be invoked before node is provisioned or Provisioner is enabled.
*
* @param[in] element_addr: Unicast address of the element to which the model belongs.
* @param[in] company_id: A 16-bit company identifier.
* @param[in] model_id: A 16-bit model identifier.
* @param[in] group_addr: The subscribed group address.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_model_unsubscribe_group_addr(uint16_t element_addr, uint16_t company_id,
uint16_t model_id, uint16_t group_addr);
/**
* @brief This function is called by Node to get the local NetKey.
*
* @param[in] net_idx: NetKey index.
*
* @return NetKey on success, or NULL on failure.
*
*/
const uint8_t *esp_ble_mesh_node_get_local_net_key(uint16_t net_idx);
/**
* @brief This function is called by Node to get the local AppKey.
*
* @param[in] app_idx: AppKey index.
*
* @return AppKey on success, or NULL on failure.
*
*/
const uint8_t *esp_ble_mesh_node_get_local_app_key(uint16_t app_idx);
/**
* @brief This function is called by Node to add a local NetKey.
*
* @param[in] net_key: NetKey to be added.
* @param[in] net_idx: NetKey Index.
*
* @note This function can only be called after the device is provisioned.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
/**
* @brief This function is called by Node to add a local AppKey.
*
* @param[in] app_key: AppKey to be added.
* @param[in] net_idx: NetKey Index.
* @param[in] app_idx: AppKey Index.
*
* @note The net_idx must be an existing one.
* This function can only be called after the device is provisioned.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_add_local_app_key(const uint8_t app_key[16], uint16_t net_idx, uint16_t app_idx);
/**
* @brief This function is called by Node to bind AppKey to model locally.
*
* @param[in] element_addr: Node local element address
* @param[in] company_id: Node local company id
* @param[in] model_id: Node local model id
* @param[in] app_idx: Node local appkey index
*
* @note If going to bind app_key with local vendor model, the company_id
* shall be set to 0xFFFF.
* This function can only be called after the device is provisioned.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_bind_app_key_to_local_model(uint16_t element_addr, uint16_t company_id,
uint16_t model_id, uint16_t app_idx);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_LOCAL_DATA_OPERATION_API_H_ */

View File

@ -0,0 +1,61 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_LOW_POWER_API_H_
#define _ESP_BLE_MESH_LOW_POWER_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enable BLE Mesh device LPN functionality.
*
* @note This API enables LPN functionality. Once called, the proper
* Friend Request will be sent.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_lpn_enable(void);
/**
* @brief Disable BLE Mesh device LPN functionality.
*
* @param[in] force: when disabling LPN functionality, use this flag to indicate
* whether directly clear corresponding information or just
* send friend clear to disable it if friendship has already
* been established.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_lpn_disable(bool force);
/**
* @brief LPN tries to poll messages from the Friend Node.
*
* @note The Friend Poll message is sent by a Low Power node to ask the Friend
* node to send a message that it has stored for the Low Power node.
* Users can call this API to send Friend Poll message manually. If this
* API is not invoked, the bottom layer of the Low Power node will send
* Friend Poll before the PollTimeout timer expires.
* If the corresponding Friend Update is received and MD is set to 0,
* which means there are no messages for the Low Power node, then the
* Low Power node will stop scanning.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_lpn_poll(void);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_LOW_POWER_API_H_ */

View File

@ -0,0 +1,648 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_NETWORKING_API_H_
#define _ESP_BLE_MESH_NETWORKING_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief: event, event code of user-defined model events; param, parameters of user-defined model events */
typedef void (* esp_ble_mesh_model_cb_t)(esp_ble_mesh_model_cb_event_t event,
esp_ble_mesh_model_cb_param_t *param);
/**
* @brief Register BLE Mesh callback for user-defined models' operations.
* This callback can report the following events generated for the user-defined models:
* - Call back the messages received by user-defined client and server models to the
* application layer;
* - If users call esp_ble_mesh_server/client_model_send, this callback notifies the
* application layer of the send_complete event;
* - If user-defined client model sends a message that requires response, and the response
* message is received after the timer expires, the response message will be reported
* to the application layer as published by a peer device;
* - If the user-defined client model fails to receive the response message during a specified
* period of time, a timeout event will be reported to the application layer.
*
* @note The client models (i.e. Config Client model, Health Client model, Generic
* Client models, Sensor Client model, Scene Client model and Lighting Client models)
* that have been realized internally have their specific register functions.
* For example, esp_ble_mesh_register_config_client_callback is the register
* function for Config Client Model.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb_t callback);
/**
* @brief Add the message opcode to the beginning of the model message
* before sending or publishing the model message.
*
* @note This API is only used to set the opcode of the message.
*
* @param[in] data: Pointer to the message data.
* @param[in] opcode: The message opcode.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode);
/**
* @brief Initialize the user-defined client model. All user-defined client models
* shall call this function to initialize the client model internal data.
* Node: Before calling this API, the op_pair_size and op_pair variabled within
* the user_data(defined using esp_ble_mesh_client_t_) of the client model
* need to be initialized.
*
* @param[in] model: BLE Mesh Client model to which the message belongs.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
/**
* @brief De-initialize the user-defined client model.
*
* @note This function shall be invoked before esp_ble_mesh_deinit() is called.
*
* @param[in] model: Pointer of the Client model.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
/**
* @brief Send server model messages(such as server model status messages).
*
* @param[in] model: BLE Mesh Server Model to which the message belongs.
* @param[in] ctx: Message context, includes keys, TTL, etc.
* @param[in] opcode: Message opcode.
* @param[in] length: Message length (exclude the message opcode).
* @param[in] data: Parameters of Access Payload (exclude the message opcode) to be sent.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
esp_ble_mesh_msg_ctx_t *ctx,
uint32_t opcode,
uint16_t length, uint8_t *data);
/**
* @brief Send client model message (such as model get, set, etc).
*
* @param[in] model: BLE Mesh Client Model to which the message belongs.
* @param[in] ctx: Message context, includes keys, TTL, etc.
* @param[in] opcode: Message opcode.
* @param[in] length: Message length (exclude the message opcode).
* @param[in] data: Parameters of the Access Payload (exclude the message opcode) to be sent.
* @param[in] msg_timeout: Time to get response to the message (in milliseconds).
* @param[in] need_rsp: TRUE if the opcode requires the peer device to reply, FALSE otherwise.
* @param[in] device_role: Role of the device (Node/Provisioner) that sends the message.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model,
esp_ble_mesh_msg_ctx_t *ctx,
uint32_t opcode,
uint16_t length, uint8_t *data,
int32_t msg_timeout, bool need_rsp,
esp_ble_mesh_dev_role_t device_role);
/**
* @brief Send a model publication message.
*
* @note Before calling this function, the user needs to ensure that the model
* publication message (@ref esp_ble_mesh_model_pub_t.msg) contains a valid
* message to be sent. And if users want to update the publishing message,
* this API should be called in ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT
* with the message updated.
*
*
* @param[in] model: Mesh (client) Model publishing the message.
* @param[in] opcode: Message opcode.
* @param[in] length: Message length (exclude the message opcode).
* @param[in] data: Parameters of the Access Payload (exclude the message opcode) to be sent.
* @param[in] device_role: Role of the device (node/provisioner) publishing the message of the type esp_ble_mesh_dev_role_t.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcode,
uint16_t length, uint8_t *data,
esp_ble_mesh_dev_role_t device_role);
/**
* @brief Update a server model state value. If the model publication
* state is set properly (e.g. publish address is set to a valid
* address), it will publish corresponding status message.
*
* @note Currently this API is used to update bound state value, not
* for all server model states.
*
* @param[in] model: Server model which is going to update the state.
* @param[in] type: Server model state type.
* @param[in] value: Server model state value.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model,
esp_ble_mesh_server_state_type_t type,
esp_ble_mesh_server_state_value_t *value);
/**
* @brief Reset the provisioning procedure of the local BLE Mesh node.
*
* @note All provisioning information in this node will be deleted and the node
* needs to be reprovisioned. The API function esp_ble_mesh_node_prov_enable()
* needs to be called to start a new provisioning procedure.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_local_reset(void);
/**
* @brief This function is called to set the node (provisioned device) name.
*
* @param[in] index: Index of the node in the node queue.
* @param[in] name: Name (end by '\0') to be set for the node.
*
* @note index is obtained from the parameters of ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_node_name(uint16_t index, const char *name);
/**
* @brief This function is called to get the node (provisioned device) name.
*
* @param[in] index: Index of the node in the node queue.
*
* @note index is obtained from the parameters of ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT.
*
* @return Node name on success, or NULL on failure.
*
*/
const char *esp_ble_mesh_provisioner_get_node_name(uint16_t index);
/**
* @brief This function is called to get the node (provisioned device) index.
*
* @param[in] name: Name of the node (end by '\0').
*
* @return Node index on success, or an invalid value (0xFFFF) on failure.
*
*/
uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name);
/**
* @brief This function is called to store the Composition Data of the node.
*
* @param[in] unicast_addr: Element address of the node
* @param[in] data: Pointer of Composition Data
* @param[in] length: Length of Composition Data
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr,
uint8_t *data, uint16_t length);
/**
* @brief This function is called to get the provisioned node information
* with the node device uuid.
*
* @param[in] uuid: Device UUID of the node
*
* @return Pointer of the node info struct or NULL on failure.
*
*/
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
/**
* @brief This function is called to get the provisioned node information
* with the node unicast address.
*
* @param[in] unicast_addr: Unicast address of the node
*
* @return Pointer of the node info struct or NULL on failure.
*
*/
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
/**
* @brief This function is called to get the provisioned node information
* with the node name.
*
* @param[in] name: Name of the node (end by '\0').
*
* @return Pointer of the node info struct or NULL on failure.
*
*/
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_name(const char *name);
/**
* @brief This function is called by Provisioner to get provisioned node count.
*
* @return Number of the provisioned nodes.
*
*/
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
/**
* @brief This function is called by Provisioner to get the entry of the node table.
*
* @note After invoking the function to get the entry of nodes, users can use the "for"
* loop combined with the macro CONFIG_BLE_MESH_MAX_PROV_NODES to get each node's
* information. Before trying to read the node's information, users need to check
* if the node exists, i.e. if the *(esp_ble_mesh_node_t **node) is NULL.
* For example:
* ```
* const esp_ble_mesh_node_t **entry = esp_ble_mesh_provisioner_get_node_table_entry();
* for (int i = 0; i < CONFIG_BLE_MESH_MAX_PROV_NODES; i++) {
* const esp_ble_mesh_node_t *node = entry[i];
* if (node) {
* ......
* }
* }
* ```
*
* @return Pointer to the start of the node table.
*
*/
const esp_ble_mesh_node_t **esp_ble_mesh_provisioner_get_node_table_entry(void);
/**
* @brief This function is called to delete the provisioned node information
* with the node device uuid.
*
* @param[in] uuid: Device UUID of the node
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16]);
/**
* @brief This function is called to delete the provisioned node information
* with the node unicast address.
*
* @param[in] unicast_addr: Unicast address of the node
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_delete_node_with_addr(uint16_t unicast_addr);
/**
* @brief This function is called to add a local AppKey for Provisioner.
*
* @param[in] app_key: The app key to be set for the local BLE Mesh stack.
* @param[in] net_idx: The network key index.
* @param[in] app_idx: The app key index.
*
* @note app_key: If set to NULL, app_key will be generated internally.
* net_idx: Should be an existing one.
* app_idx: If it is going to be generated internally, it should be set to
* 0xFFFF, and the new app_idx will be reported via an event.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
uint16_t net_idx, uint16_t app_idx);
/**
* @brief This function is used to update a local AppKey for Provisioner.
*
* @param[in] app_key: Value of the AppKey.
* @param[in] net_idx: Corresponding NetKey Index.
* @param[in] app_idx: The AppKey Index
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16],
uint16_t net_idx, uint16_t app_idx);
/**
* @brief This function is called by Provisioner to get the local app key value.
*
* @param[in] net_idx: Network key index.
* @param[in] app_idx: Application key index.
*
* @return App key on success, or NULL on failure.
*
*/
const uint8_t *esp_ble_mesh_provisioner_get_local_app_key(uint16_t net_idx, uint16_t app_idx);
/**
* @brief This function is called by Provisioner to bind own model with proper app key.
*
* @param[in] element_addr: Provisioner local element address
* @param[in] app_idx: Provisioner local appkey index
* @param[in] model_id: Provisioner local model id
* @param[in] company_id: Provisioner local company id
*
* @note company_id: If going to bind app_key with local vendor model, company_id
* should be set to 0xFFFF.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_addr, uint16_t app_idx,
uint16_t model_id, uint16_t company_id);
/**
* @brief This function is called by Provisioner to add local network key.
*
* @param[in] net_key: The network key to be added to the Provisioner local BLE Mesh stack.
* @param[in] net_idx: The network key index.
*
* @note net_key: If set to NULL, net_key will be generated internally.
* net_idx: If it is going to be generated internally, it should be set to
* 0xFFFF, and the new net_idx will be reported via an event.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
/**
* @brief This function is called by Provisioner to update a local network key.
*
* @param[in] net_key: Value of the NetKey.
* @param[in] net_idx: The NetKey Index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
/**
* @brief This function is called by Provisioner to get the local network key value.
*
* @param[in] net_idx: Network key index.
*
* @return Network key on success, or NULL on failure.
*
*/
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
/**
* @brief This function is called by Provisioner to enable or disable receiving
* heartbeat messages.
*
* @note If enabling receiving heartbeat message successfully, the filter will
* be an empty rejectlist by default, which means all heartbeat messages
* received by the Provisioner will be reported to the application layer.
*
* @param[in] enable: Enable or disable receiving heartbeat messages.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_recv_heartbeat(bool enable);
/**
* @brief This function is called by Provisioner to set the heartbeat filter type.
*
* @note 1. If the filter type is not the same with the current value, then all the
* filter entries will be cleaned.
* 2. If the previous type is rejectlist, and changed to acceptlist, then the
* filter will be an empty acceptlist, which means no heartbeat messages
* will be reported. Users need to add SRC or DST into the filter entry,
* then heartbeat messages from the SRC or to the DST will be reported.
*
* @param[in] type: Heartbeat filter type (acceptlist or rejectlist).
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_heartbeat_filter_type(uint8_t type);
/**
* @brief This function is called by Provisioner to add or remove a heartbeat filter entry.
*
* @note 1. If the operation is "ADD", the "hb_src" can be set to the SRC (can only be a
* unicast address) of heartbeat messages, and the "hb_dst" can be set to the
* DST (unicast address or group address), at least one of them needs to be set.
* - If only one of them is set, the filter entry will only use the configured
* SRC or DST to filter heartbeat messages.
* - If both of them are set, the SRC and DST will both be used to decide if a
* heartbeat message will be handled.
* - If SRC or DST already exists in some filter entry, then the corresponding
* entry will be cleaned firstly, then a new entry will be allocated to store
* the information.
* 2. If the operation is "REMOVE", the "hb_src" can be set to the SRC (can only be
* a unicast address) of heartbeat messages, and the "hb_dst" can be set to the
* DST (unicast address or group address), at least one of them needs to be set.
* - The filter entry with the same SRC or DST will be removed.
*
* @param[in] op: Add or REMOVE
* @param[in] info: Heartbeat filter entry information, including:
* hb_src - Heartbeat source address;
* hb_dst - Heartbeat destination address;
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_heartbeat_filter_info(uint8_t op, esp_ble_mesh_heartbeat_filter_info_t *info);
/**
* @brief This function is called by Provisioner to directly erase the mesh
* information from nvs namespace.
*
* @note This function can be invoked when the mesh stack is not initialized
* or has been de-initialized.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_direct_erase_settings(void);
/**
* @brief This function is called by Provisioner to open a nvs namespace
* for storing mesh information.
*
* @note Before open another nvs namespace, the previously opened nvs
* namespace must be closed firstly.
*
* @param[in] index: Settings index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_open_settings_with_index(uint8_t index);
/**
* @brief This function is called by Provisioner to open a nvs namespace
* for storing mesh information.
*
* @note Before open another nvs namespace, the previously opened nvs
* namespace must be closed firstly.
*
* @param[in] uid: Settings user id.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_open_settings_with_uid(const char *uid);
/**
* @brief This function is called by Provisioner to close a nvs namespace
* which is opened previously for storing mesh information.
*
* @note 1. Before closing the nvs namespace, it must be open.
* 2. When the function is invoked, the Provisioner functionality
* will be disabled firstly, and:
* a) If the "erase" flag is set to false, the mesh information
* will be cleaned (e.g. removing NetKey, AppKey, nodes, etc)
* from the mesh stack.
* b) If the "erase" flag is set to true, the mesh information
* stored in the nvs namespace will also be erased besides
* been cleaned from the mesh stack.
* 3. If Provisioner tries to work properly again, we can invoke the
* open function to open a new nvs namespace or a previously added
* one, and restore the mesh information from it if not erased.
* 4. The working process shall be as following:
* a) Open settings A
* b) Start to provision and control nodes
* c) Close settings A
* d) Open settings B
* e) Start to provision and control other nodes
* f) Close settings B
* g) ......
*
* @param[in] index: Settings index.
* @param[in] erase: Indicate if erasing mesh information.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_close_settings_with_index(uint8_t index, bool erase);
/**
* @brief This function is called by Provisioner to close a nvs namespace
* which is opened previously for storing mesh information.
*
* @note 1. Before closing the nvs namespace, it must be open.
* 2. When the function is invoked, the Provisioner functionality
* will be disabled firstly, and:
* a) If the "erase" flag is set to false, the mesh information
* will be cleaned (e.g. removing NetKey, AppKey, nodes, etc)
* from the mesh stack.
* b) If the "erase" flag is set to true, the mesh information
* stored in the nvs namespace will also be erased besides
* been cleaned from the mesh stack.
* 3. If Provisioner tries to work properly again, we can invoke the
* open function to open a new nvs namespace or a previously added
* one, and restore the mesh information from it if not erased.
* 4. The working process shall be as following:
* a) Open settings A
* b) Start to provision and control nodes
* c) Close settings A
* d) Open settings B
* e) Start to provision and control other nodes
* f) Close settings B
* g) ......
*
* @param[in] uid: Settings user id.
* @param[in] erase: Indicate if erasing mesh information.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_close_settings_with_uid(const char *uid, bool erase);
/**
* @brief This function is called by Provisioner to erase the mesh information
* and settings user id from a nvs namespace.
*
* @note When this function is called, the nvs namespace must not be open.
* This function is used to erase the mesh information and settings
* user id which are not used currently.
*
* @param[in] index: Settings index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_index(uint8_t index);
/**
* @brief This function is called by Provisioner to erase the mesh information
* and settings user id from a nvs namespace.
*
* @note When this function is called, the nvs namespace must not be open.
* This function is used to erase the mesh information and settings
* user id which are not used currently.
*
* @param[in] uid: Settings user id.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_uid(const char *uid);
/**
* @brief This function is called by Provisioner to get settings user id.
*
* @param[in] index: Settings index.
*
* @return Setting user id on success or NULL on failure.
*
*/
const char *esp_ble_mesh_provisioner_get_settings_uid(uint8_t index);
/**
* @brief This function is called by Provisioner to get settings index.
*
* @param[in] uid: Settings user id.
*
* @return Settings index.
*
*/
uint8_t esp_ble_mesh_provisioner_get_settings_index(const char *uid);
/**
* @brief This function is called by Provisioner to get the number of free
* settings user id.
*
* @return Number of free settings user id.
*
*/
uint8_t esp_ble_mesh_provisioner_get_free_settings_count(void);
/**
* @brief This function is called to get fast provisioning application key.
*
* @param[in] net_idx: Network key index.
* @param[in] app_idx: Application key index.
*
* @return Application key on success, or NULL on failure.
*
*/
const uint8_t *esp_ble_mesh_get_fast_prov_app_key(uint16_t net_idx, uint16_t app_idx);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_NETWORKING_API_H_ */

View File

@ -0,0 +1,394 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_PROVISIONING_API_H_
#define _ESP_BLE_MESH_PROVISIONING_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief: event, event code of provisioning events; param, parameters of provisioning events */
typedef void (* esp_ble_mesh_prov_cb_t)(esp_ble_mesh_prov_cb_event_t event,
esp_ble_mesh_prov_cb_param_t *param);
/**
* @brief Register BLE Mesh provisioning callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb_t callback);
/**
* @brief Check if a device has been provisioned.
*
* @return TRUE if the device is provisioned, FALSE if the device is unprovisioned.
*
*/
bool esp_ble_mesh_node_is_provisioned(void);
/**
* @brief Enable specific provisioning bearers to get the device ready for provisioning.
*
* @note PB-ADV: send unprovisioned device beacon.
* PB-GATT: send connectable advertising packets.
*
* @param bearers: Bit-wise OR of provisioning bearers.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_prov_enable(esp_ble_mesh_prov_bearer_t bearers);
/**
* @brief Disable specific provisioning bearers to make a device inaccessible for provisioning.
*
* @param bearers: Bit-wise OR of provisioning bearers.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers);
/**
* @brief Unprovisioned device set own oob public key & private key pair.
*
* @note In order to avoid suffering brute-forcing attack (CVE-2020-26559).
* The Bluetooth SIG recommends that potentially vulnerable mesh provisioners
* use an out-of-band mechanism to exchange the public keys.
* So as an unprovisioned device, it should use this function to input
* the Public Key exchanged through the out-of-band mechanism.
*
* @param[in] pub_key_x: Unprovisioned device's Public Key X
* @param[in] pub_key_y: Unprovisioned device's Public Key Y
* @param[in] private_key: Unprovisioned device's Private Key
*
* @return ESP_OK on success or error code otherwise.
*/
esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_key_y[32],
uint8_t private_key[32]);
/**
* @brief Provide provisioning input OOB number.
*
* @note This is intended to be called if the user has received ESP_BLE_MESH_NODE_PROV_INPUT_EVT
* with ESP_BLE_MESH_ENTER_NUMBER as the action.
*
* @param[in] number: Number input by device.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_input_number(uint32_t number);
/**
* @brief Provide provisioning input OOB string.
*
* @note This is intended to be called if the user has received ESP_BLE_MESH_NODE_PROV_INPUT_EVT
* with ESP_BLE_MESH_ENTER_STRING as the action.
*
* @param[in] string: String input by device.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_node_input_string(const char *string);
/**
* @brief Using this function, an unprovisioned device can set its own device name,
* which will be broadcasted in its advertising data.
*
* @param[in] name: Unprovisioned device name
*
* @note This API applicable to PB-GATT mode only by setting the name to the scan response data,
* it doesn't apply to PB-ADV mode.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name);
/**
* @brief Provisioner inputs unprovisioned device's oob public key.
*
* @note In order to avoid suffering brute-forcing attack (CVE-2020-26559).
* The Bluetooth SIG recommends that potentially vulnerable mesh provisioners
* use an out-of-band mechanism to exchange the public keys.
*
* @param[in] link_idx: The provisioning link index
* @param[in] pub_key_x: Unprovisioned device's Public Key X
* @param[in] pub_key_y: Unprovisioned device's Public Key Y
*
* @return ESP_OK on success or error code otherwise.
*/
esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pub_key_x[32],
uint8_t pub_key_y[32]);
/**
* @brief Provide provisioning input OOB string.
*
* This is intended to be called after the esp_ble_mesh_prov_t prov_input_num
* callback has been called with ESP_BLE_MESH_ENTER_STRING as the action.
*
* @param[in] string: String input by Provisioner.
* @param[in] link_idx: The provisioning link index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link_idx);
/**
* @brief Provide provisioning input OOB number.
*
* This is intended to be called after the esp_ble_mesh_prov_t prov_input_num
* callback has been called with ESP_BLE_MESH_ENTER_NUMBER as the action.
*
* @param[in] number: Number input by Provisioner.
* @param[in] link_idx: The provisioning link index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_input_number(uint32_t number, uint8_t link_idx);
/**
* @brief Enable one or more provisioning bearers.
*
* @param[in] bearers: Bit-wise OR of provisioning bearers.
*
* @note PB-ADV: Enable BLE scan.
* PB-GATT: Initialize corresponding BLE Mesh Proxy info.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_prov_enable(esp_ble_mesh_prov_bearer_t bearers);
/**
* @brief Disable one or more provisioning bearers.
*
* @param[in] bearers: Bit-wise OR of provisioning bearers.
*
* @note PB-ADV: Disable BLE scan.
* PB-GATT: Break any existing BLE Mesh Provisioning connections.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t bearers);
/**
* @brief Add unprovisioned device info to the unprov_dev queue.
*
* @param[in] add_dev: Pointer to a struct containing the device information
* @param[in] flags: Flags indicate several operations on the device information
* - Remove device information from queue after device has been provisioned (BIT0)
* - Start provisioning immediately after device is added to queue (BIT1)
* - Device can be removed if device queue is full (BIT2)
*
* @return ESP_OK on success or error code otherwise.
*
* @note: 1. Currently address type only supports public address and static random address.
* 2. If device UUID and/or device address as well as address type already exist in the
* device queue, but the bearer is different from the existing one, add operation
* will also be successful and it will update the provision bearer supported by
* the device.
* 3. For example, if the Provisioner wants to add an unprovisioned device info before
* receiving its unprovisioned device beacon or Mesh Provisioning advertising packets,
* the Provisioner can use this API to add the device info with each one or both of
* device UUID and device address added. When the Provisioner gets the device's
* advertising packets, it will start provisioning the device internally.
* - In this situation, the Provisioner can set bearers with each one or both of
* ESP_BLE_MESH_PROV_ADV and ESP_BLE_MESH_PROV_GATT enabled, and cannot set flags
* with ADD_DEV_START_PROV_NOW_FLAG enabled.
* 4. Another example is when the Provisioner receives the unprovisioned device's beacon or
* Mesh Provisioning advertising packets, the advertising packets will be reported on to
* the application layer using the callback registered by the function
* esp_ble_mesh_register_prov_callback. And in the callback, the Provisioner
* can call this API to start provisioning the device.
* - If the Provisioner uses PB-ADV to provision, either one or both of device UUID and
* device address can be added, bearers shall be set with ESP_BLE_MESH_PROV_ADV
* enabled and the flags shall be set with ADD_DEV_START_PROV_NOW_FLAG enabled.
* - If the Provisioner uses PB-GATT to provision, both the device UUID and device
* address need to be added, bearers shall be set with ESP_BLE_MESH_PROV_GATT enabled,
* and the flags shall be set with ADD_DEV_START_PROV_NOW_FLAG enabled.
* - If the Provisioner just wants to store the unprovisioned device info when receiving
* its advertising packets and start to provision it the next time (e.g. after receiving
* its advertising packets again), then it can add the device info with either one or both
* of device UUID and device address included. Bearers can be set with either one or both
* of ESP_BLE_MESH_PROV_ADV and ESP_BLE_MESH_PROV_GATT enabled (recommend to enable the
* bearer which will receive its advertising packets, because if the other bearer is
* enabled, the Provisioner is not aware if the device supports the bearer), and flags
* cannot be set with ADD_DEV_START_PROV_NOW_FLAG enabled.
* - Note: ESP_BLE_MESH_PROV_ADV, ESP_BLE_MESH_PROV_GATT and ADD_DEV_START_PROV_NOW_FLAG
* can not be enabled at the same time.
*
*/
esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t *add_dev,
esp_ble_mesh_dev_add_flag_t flags);
/** @brief Provision an unprovisioned device and assign a fixed unicast address for it in advance.
*
* @param[in] uuid: Device UUID of the unprovisioned device
* @param[in] addr: Device address of the unprovisioned device
* @param[in] addr_type: Device address type of the unprovisioned device
* @param[in] bearer: Provisioning bearer going to be used by Provisioner
* @param[in] oob_info: OOB info of the unprovisioned device
* @param[in] unicast_addr: Unicast address going to be allocated for the unprovisioned device
*
* @return Zero on success or (negative) error code otherwise.
*
* @note: 1. Currently address type only supports public address and static random address.
* 2. Bearer must be equal to ESP_BLE_MESH_PROV_ADV or ESP_BLE_MESH_PROV_GATT, since
* Provisioner will start to provision a device immediately once this function is
* invoked. And the input bearer must be identical with the one within the parameters
* of the ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT event.
* 3. If this function is used by a Provisioner to provision devices, the application
* should take care of the assigned unicast address and avoid overlap of the unicast
* addresses of different nodes.
* 4. Recommend to use only one of the functions "esp_ble_mesh_provisioner_add_unprov_dev"
* and "esp_ble_mesh_provisioner_prov_device_with_addr" by a Provisioner.
*/
esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16],
esp_ble_mesh_bd_addr_t addr,
esp_ble_mesh_addr_type_t addr_type,
esp_ble_mesh_prov_bearer_t bearer,
uint16_t oob_info, uint16_t unicast_addr);
/**
* @brief Delete device from queue, and reset current provisioning link with the device.
*
* @note If the device is in the queue, remove it from the queue; if the device is
* being provisioned, terminate the provisioning procedure. Either one of the
* device address or device UUID can be used as input.
*
* @param[in] del_dev: Pointer to a struct containing the device information.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_dev);
/**
* @brief Callback for Provisioner that received advertising packets from unprovisioned devices which are
* not in the unprovisioned device queue.
*
* Report on the unprovisioned device beacon and mesh provisioning service adv data to application.
*
* @param[in] addr: Pointer to the unprovisioned device address.
* @param[in] addr_type: Unprovisioned device address type.
* @param[in] adv_type: Adv packet type(ADV_IND or ADV_NONCONN_IND).
* @param[in] dev_uuid: Unprovisioned device UUID pointer.
* @param[in] oob_info: OOB information of the unprovisioned device.
* @param[in] bearer: Adv packet received from PB-GATT or PB-ADV bearer.
*
*/
typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_ble_mesh_bd_addr_t addr, const esp_ble_mesh_addr_type_t addr_type,
const uint8_t adv_type, const uint8_t *dev_uuid,
uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer);
/**
* @brief This function is called by Provisioner to set the part of the device UUID
* to be compared before starting to provision.
*
* @param[in] match_val: Value to be compared with the part of the device UUID.
* @param[in] match_len: Length of the compared match value.
* @param[in] offset: Offset of the device UUID to be compared (based on zero).
* @param[in] prov_after_match: Flag used to indicate whether provisioner should start to provision
* the device immediately if the part of the UUID matches.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, uint8_t match_len,
uint8_t offset, bool prov_after_match);
/**
* @brief This function is called by Provisioner to set provisioning data information
* before starting to provision.
*
* @param[in] prov_data_info: Pointer to a struct containing net_idx or flags or iv_index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_info_t *prov_data_info);
/**
* @brief This function is called by Provisioner to set static oob value used for provisioning.
*
* @note The Bluetooth SIG recommends that mesh implementations enforce a randomly selected
* AuthValue using all of the available bits, where permitted by the implementation.
* A large entropy helps ensure that a brute-force of the AuthValue, even a static
* AuthValue, cannot normally be completed in a reasonable time (CVE-2020-26557).
*
* AuthValues selected using a cryptographically secure random or pseudorandom number
* generator and having the maximum permitted entropy (128-bits) will be most difficult
* to brute-force. AuthValues with reduced entropy or generated in a predictable manner
* will not grant the same level of protection against this vulnerability. Selecting a
* new AuthValue with each provisioning attempt can also make it more difficult to launch
* a brute-force attack by requiring the attacker to restart the search with each
* provisioning attempt (CVE-2020-26556).
*
* @param[in] value: Pointer to the static oob value.
* @param[in] length: Length of the static oob value.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_static_oob_value(const uint8_t *value, uint8_t length);
/**
* @brief This function is called by Provisioner to set own Primary element address.
*
* @note This API must be invoked when BLE Mesh initialization is completed successfully,
* and can be invoked before Provisioner functionality is enabled.
* Once this API is invoked successfully, the prov_unicast_addr value in the struct
* esp_ble_mesh_prov_t will be ignored, and Provisioner will use this address as its
* own primary element address.
* And if the unicast address going to assigned for the next unprovisioned device is
* smaller than the input address + element number of Provisioner, then the address
* for the next unprovisioned device will be recalculated internally.
*
* @param[in] addr: Unicast address of the Primary element of Provisioner.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_set_primary_elem_addr(uint16_t addr);
/**
* @brief This function is called to set provisioning data information before starting
* fast provisioning.
*
* @param[in] fast_prov_info: Pointer to a struct containing unicast address range, net_idx, etc.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_prov_info);
/**
* @brief This function is called to start/suspend/exit fast provisioning.
*
* @param[in] action: fast provisioning action (i.e. enter, suspend, exit).
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t action);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_PROVISIONING_API_H_ */

View File

@ -0,0 +1,118 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_PROXY_API_H_
#define _ESP_BLE_MESH_PROXY_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enable advertising with Node Identity.
*
* @note This API requires that GATT Proxy support be enabled. Once called,
* each subnet starts advertising using Node Identity for the next 60
* seconds, and after 60s Network ID will be advertised.
* Under normal conditions, the BLE Mesh Proxy Node Identity and
* Network ID advertising will be enabled automatically by BLE Mesh
* stack after the device is provisioned.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_identity_enable(void);
/**
* @brief Enable BLE Mesh GATT Proxy Service.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_gatt_enable(void);
/**
* @brief Disconnect the BLE Mesh GATT Proxy connection if there is any, and
* disable the BLE Mesh GATT Proxy Service.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_gatt_disable(void);
/**
* @brief Proxy Client creates a connection with the Proxy Server.
*
* @param[in] addr: Device address of the Proxy Server.
* @param[in] addr_type: Device address type(public or static random).
* @param[in] net_idx: NetKey Index related with Network ID in the Mesh Proxy
* advertising packet.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_connect(esp_ble_mesh_bd_addr_t addr,
esp_ble_mesh_addr_type_t addr_type,
uint16_t net_idx);
/**
* @brief Proxy Client terminates a connection with the Proxy Server.
*
* @param[in] conn_handle: Proxy connection handle.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle);
/**
* @brief Proxy Client sets the filter type of the Proxy Server.
*
* @param[in] conn_handle: Proxy connection handle.
* @param[in] net_idx: Corresponding NetKey Index.
* @param[in] filter_type: whitelist or blacklist.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, uint16_t net_idx,
esp_ble_mesh_proxy_filter_type_t filter_type);
/**
* @brief Proxy Client adds address to the Proxy Server filter list.
*
* @param[in] conn_handle: Proxy connection handle.
* @param[in] net_idx: Corresponding NetKey Index.
* @param[in] addr: Pointer to the filter address.
* @param[in] addr_num: Number of the filter address.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, uint16_t net_idx,
uint16_t *addr, uint16_t addr_num);
/**
* @brief Proxy Client removes address from the Proxy Server filter list.
*
* @param[in] conn_handle: Proxy connection handle.
* @param[in] net_idx: Corresponding NetKey Index.
* @param[in] addr: Pointer to the filter address.
* @param[in] addr_num: Number of the filter address.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, uint16_t net_idx,
uint16_t *addr, uint16_t addr_num);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_PROXY_API_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,817 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_CONFIG_MODEL_API_H_
#define _ESP_BLE_MESH_CONFIG_MODEL_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @def ESP_BLE_MESH_MODEL_CFG_SRV
*
* @brief Define a new Config Server Model.
*
* @note The Config Server Model can only be included by a Primary Element.
*
* @param srv_data Pointer to a unique Config Server Model user_data.
*
* @return New Config Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_CFG_SRV(srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_CONFIG_SRV, \
NULL, NULL, srv_data)
/** @def ESP_BLE_MESH_MODEL_CFG_CLI
*
* @brief Define a new Config Client Model.
*
* @note The Config Client Model can only be included by a Primary Element.
*
* @param cli_data Pointer to a unique struct esp_ble_mesh_client_t.
*
* @return New Config Client Model instance.
*/
#define ESP_BLE_MESH_MODEL_CFG_CLI(cli_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_CONFIG_CLI, \
NULL, NULL, cli_data)
/** Configuration Server Model context */
typedef struct esp_ble_mesh_cfg_srv {
esp_ble_mesh_model_t *model; /*!< Pointer to Configuration Server Model */
uint8_t net_transmit; /*!< Network Transmit state */
uint8_t relay; /*!< Relay Mode state */
uint8_t relay_retransmit; /*!< Relay Retransmit state */
uint8_t beacon; /*!< Secure Network Beacon state */
uint8_t gatt_proxy; /*!< GATT Proxy state */
uint8_t friend_state; /*!< Friend state */
uint8_t default_ttl; /*!< Default TTL */
/** Heartbeat Publication */
struct {
struct k_delayed_work timer; /*!< Heartbeat Publication timer */
uint16_t dst; /*!< Destination address for Heartbeat messages */
uint16_t count; /*!< Number of Heartbeat messages to be sent */
uint8_t period; /*!< Period for sending Heartbeat messages */
uint8_t ttl; /*!< TTL to be used when sending Heartbeat messages */
uint16_t feature; /*!< Bit field indicating features that trigger Heartbeat messages when changed */
uint16_t net_idx; /*!< NetKey Index used by Heartbeat Publication */
} heartbeat_pub;
/** Heartbeat Subscription */
struct {
int64_t expiry; /*!< Timestamp when Heartbeat subscription period is expired */
uint16_t src; /*!< Source address for Heartbeat messages */
uint16_t dst; /*!< Destination address for Heartbeat messages */
uint16_t count; /*!< Number of Heartbeat messages received */
uint8_t min_hops; /*!< Minimum hops when receiving Heartbeat messages */
uint8_t max_hops; /*!< Maximum hops when receiving Heartbeat messages */
/** Optional heartbeat subscription tracking function */
esp_ble_mesh_cb_t heartbeat_recv_cb;
} heartbeat_sub;
} esp_ble_mesh_cfg_srv_t;
/** Parameters of Config Composition Data Get. */
typedef struct {
uint8_t page; /*!< Page number of the Composition Data. */
} esp_ble_mesh_cfg_composition_data_get_t;
/** Parameters of Config Model Publication Get. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_pub_get_t;
/** Parameters of Config SIG Model Subscription Get. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_id; /*!< The model id */
} esp_ble_mesh_cfg_sig_model_sub_get_t;
/** Parameters of Config Vendor Model Subscription Get. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_vnd_model_sub_get_t;
/** Parameters of Config AppKey Get. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
} esp_ble_mesh_cfg_app_key_get_t;
/** Parameters of Config Node Identity Get. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
} esp_ble_mesh_cfg_node_identity_get_t;
/** Parameters of Config SIG Model App Get. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_id; /*!< The model id */
} esp_ble_mesh_cfg_sig_model_app_get_t;
/** Parameters of Config Vendor Model App Get. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_vnd_model_app_get_t;
/** Parameters of Config Key Refresh Phase Get. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
} esp_ble_mesh_cfg_kr_phase_get_t;
/** Parameters of Config Low Power Node PollTimeout Get. */
typedef struct {
uint16_t lpn_addr; /*!< The unicast address of the Low Power node */
} esp_ble_mesh_cfg_lpn_polltimeout_get_t;
/** Parameters of Config Beacon Set. */
typedef struct {
uint8_t beacon; /*!< New Secure Network Beacon state */
} esp_ble_mesh_cfg_beacon_set_t;
/** Parameters of Config Default TTL Set. */
typedef struct {
uint8_t ttl; /*!< The default TTL state value */
} esp_ble_mesh_cfg_default_ttl_set_t;
/** Parameters of Config Friend Set. */
typedef struct {
uint8_t friend_state; /*!< The friend state value */
} esp_ble_mesh_cfg_friend_set_t;
/** Parameters of Config GATT Proxy Set. */
typedef struct {
uint8_t gatt_proxy; /*!< The GATT Proxy state value */
} esp_ble_mesh_cfg_gatt_proxy_set_t;
/** Parameters of Config Relay Set. */
typedef struct {
uint8_t relay; /*!< The relay value */
uint8_t relay_retransmit; /*!< The relay retransmit value */
} esp_ble_mesh_cfg_relay_set_t;
/** Parameters of Config NetKey Add. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint8_t net_key[16]; /*!< The network key value */
} esp_ble_mesh_cfg_net_key_add_t;
/** Parameters of Config AppKey Add. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint16_t app_idx; /*!< The app key index */
uint8_t app_key[16]; /*!< The app key value */
} esp_ble_mesh_cfg_app_key_add_t;
/** Parameters of Config Model App Bind. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_app_idx; /*!< Index of the app key to bind with the model */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_app_bind_t;
/** Parameters of Config Model Publication Set. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t publish_addr; /*!< Value of the publish address */
uint16_t publish_app_idx; /*!< Index of the application key */
bool cred_flag; /*!< Value of the Friendship Credential Flag */
uint8_t publish_ttl; /*!< Default TTL value for the publishing messages */
uint8_t publish_period; /*!< Period for periodic status publishing */
uint8_t publish_retransmit; /*!< Number of retransmissions and number of 50-millisecond steps between retransmissions */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_pub_set_t;
/** Parameters of Config Model Subscription Add. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t sub_addr; /*!< The address to be added to the Subscription List */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_add_t;
/** Parameters of Config Model Subscription Delete. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t sub_addr; /*!< The address to be removed from the Subscription List */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_delete_t;
/** Parameters of Config Model Subscription Overwrite. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t sub_addr; /*!< The address to be added to the Subscription List */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_overwrite_t;
/** Parameters of Config Model Subscription Virtual Address Add. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint8_t label_uuid[16]; /*!< The Label UUID of the virtual address to be added to the Subscription List */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_va_add_t;
/** Parameters of Config Model Subscription Virtual Address Delete. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint8_t label_uuid[16]; /*!< The Label UUID of the virtual address to be removed from the Subscription List */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_va_delete_t;
/** Parameters of Config Model Subscription Virtual Address Overwrite. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint8_t label_uuid[16]; /*!< The Label UUID of the virtual address to be added to the Subscription List */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_va_overwrite_t;
/** Parameters of Config Model Publication Virtual Address Set. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint8_t label_uuid[16]; /*!< Value of the Label UUID publish address */
uint16_t publish_app_idx; /*!< Index of the application key */
bool cred_flag; /*!< Value of the Friendship Credential Flag */
uint8_t publish_ttl; /*!< Default TTL value for the publishing messages */
uint8_t publish_period; /*!< Period for periodic status publishing */
uint8_t publish_retransmit; /*!< Number of retransmissions and number of 50-millisecond steps between retransmissions */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_pub_va_set_t;
/** Parameters of Config Model Subscription Delete All. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_sub_delete_all_t;
/** Parameters of Config NetKey Update. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint8_t net_key[16]; /*!< The network key value */
} esp_ble_mesh_cfg_net_key_update_t;
/** Parameters of Config NetKey Delete. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
} esp_ble_mesh_cfg_net_key_delete_t;
/** Parameters of Config AppKey Update. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint16_t app_idx; /*!< The app key index */
uint8_t app_key[16]; /*!< The app key value */
} esp_ble_mesh_cfg_app_key_update_t;
/** Parameters of Config AppKey Delete. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint16_t app_idx; /*!< The app key index */
} esp_ble_mesh_cfg_app_key_delete_t;
/** Parameters of Config Node Identity Set. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint8_t identity; /*!< New Node Identity state */
} esp_ble_mesh_cfg_node_identity_set_t;
/** Parameters of Config Model App Unbind. */
typedef struct {
uint16_t element_addr; /*!< The element address */
uint16_t model_app_idx; /*!< Index of the app key to bind with the model */
uint16_t model_id; /*!< The model id */
uint16_t company_id; /*!< The company id, if not a vendor model, shall set to 0xFFFF */
} esp_ble_mesh_cfg_model_app_unbind_t;
/** Parameters of Config Key Refresh Phase Set. */
typedef struct {
uint16_t net_idx; /*!< The network key index */
uint8_t transition; /*!< New Key Refresh Phase Transition */
} esp_ble_mesh_cfg_kr_phase_set_t;
/** Parameters of Config Network Transmit Set. */
typedef struct {
uint8_t net_transmit; /*!< Network Transmit State */
} esp_ble_mesh_cfg_net_transmit_set_t;
/** Parameters of Config Model Heartbeat Publication Set. */
typedef struct {
uint16_t dst; /*!< Destination address for Heartbeat messages */
uint8_t count; /*!< Number of Heartbeat messages to be sent */
uint8_t period; /*!< Period for sending Heartbeat messages */
uint8_t ttl; /*!< TTL to be used when sending Heartbeat messages */
uint16_t feature; /*!< Bit field indicating features that trigger Heartbeat messages when changed */
uint16_t net_idx; /*!< NetKey Index */
} esp_ble_mesh_cfg_heartbeat_pub_set_t;
/** Parameters of Config Model Heartbeat Subscription Set. */
typedef struct {
uint16_t src; /*!< Source address for Heartbeat messages */
uint16_t dst; /*!< Destination address for Heartbeat messages */
uint8_t period; /*!< Period for receiving Heartbeat messages */
} esp_ble_mesh_cfg_heartbeat_sub_set_t;
/**
* @brief For ESP_BLE_MESH_MODEL_OP_BEACON_GET
* ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET
* ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET
* ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET
* ESP_BLE_MESH_MODEL_OP_RELAY_GET
* ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET
* ESP_BLE_MESH_MODEL_OP_FRIEND_GET
* ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET
* ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET
* the get_state parameter in the esp_ble_mesh_config_client_get_state function should not be set to NULL.
*/
typedef union {
esp_ble_mesh_cfg_model_pub_get_t model_pub_get; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET. */
esp_ble_mesh_cfg_composition_data_get_t comp_data_get; /*!< For ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET. */
esp_ble_mesh_cfg_sig_model_sub_get_t sig_model_sub_get; /*!< For ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET */
esp_ble_mesh_cfg_vnd_model_sub_get_t vnd_model_sub_get; /*!< For ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET */
esp_ble_mesh_cfg_app_key_get_t app_key_get; /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_GET. */
esp_ble_mesh_cfg_node_identity_get_t node_identity_get; /*!< For ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET. */
esp_ble_mesh_cfg_sig_model_app_get_t sig_model_app_get; /*!< For ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET */
esp_ble_mesh_cfg_vnd_model_app_get_t vnd_model_app_get; /*!< For ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET */
esp_ble_mesh_cfg_kr_phase_get_t kr_phase_get; /*!< For ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET */
esp_ble_mesh_cfg_lpn_polltimeout_get_t lpn_pollto_get; /*!< For ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET */
} esp_ble_mesh_cfg_client_get_state_t;
/**
* @brief For ESP_BLE_MESH_MODEL_OP_BEACON_SET
* ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET
* ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET
* ESP_BLE_MESH_MODEL_OP_RELAY_SET
* ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET
* ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD
* ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD
* ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE
* ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE
* ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE
* ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE
* ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD
* ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD
* ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND
* ESP_BLE_MESH_MODEL_OP_NODE_RESET
* ESP_BLE_MESH_MODEL_OP_FRIEND_SET
* ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET
* ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET
* the set_state parameter in the esp_ble_mesh_config_client_set_state function should not be set to NULL.
*/
typedef union {
esp_ble_mesh_cfg_beacon_set_t beacon_set; /*!< For ESP_BLE_MESH_MODEL_OP_BEACON_SET */
esp_ble_mesh_cfg_default_ttl_set_t default_ttl_set; /*!< For ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET */
esp_ble_mesh_cfg_friend_set_t friend_set; /*!< For ESP_BLE_MESH_MODEL_OP_FRIEND_SET */
esp_ble_mesh_cfg_gatt_proxy_set_t gatt_proxy_set; /*!< For ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET */
esp_ble_mesh_cfg_relay_set_t relay_set; /*!< For ESP_BLE_MESH_MODEL_OP_RELAY_SET */
esp_ble_mesh_cfg_net_key_add_t net_key_add; /*!< For ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD */
esp_ble_mesh_cfg_app_key_add_t app_key_add; /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD */
esp_ble_mesh_cfg_model_app_bind_t model_app_bind; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND */
esp_ble_mesh_cfg_model_pub_set_t model_pub_set; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET */
esp_ble_mesh_cfg_model_sub_add_t model_sub_add; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD */
esp_ble_mesh_cfg_model_sub_delete_t model_sub_delete; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE */
esp_ble_mesh_cfg_model_sub_overwrite_t model_sub_overwrite; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE */
esp_ble_mesh_cfg_model_sub_va_add_t model_sub_va_add; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD */
esp_ble_mesh_cfg_model_sub_va_delete_t model_sub_va_delete; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE */
esp_ble_mesh_cfg_model_sub_va_overwrite_t model_sub_va_overwrite; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE */
esp_ble_mesh_cfg_heartbeat_pub_set_t heartbeat_pub_set; /*!< For ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET */
esp_ble_mesh_cfg_heartbeat_sub_set_t heartbeat_sub_set; /*!< For ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET */
esp_ble_mesh_cfg_model_pub_va_set_t model_pub_va_set; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET */
esp_ble_mesh_cfg_model_sub_delete_all_t model_sub_delete_all; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL */
esp_ble_mesh_cfg_net_key_update_t net_key_update; /*!< For ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE */
esp_ble_mesh_cfg_net_key_delete_t net_key_delete; /*!< For ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE */
esp_ble_mesh_cfg_app_key_update_t app_key_update; /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE */
esp_ble_mesh_cfg_app_key_delete_t app_key_delete; /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE */
esp_ble_mesh_cfg_node_identity_set_t node_identity_set; /*!< For ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET */
esp_ble_mesh_cfg_model_app_unbind_t model_app_unbind; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND */
esp_ble_mesh_cfg_kr_phase_set_t kr_phase_set; /*!< For ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET */
esp_ble_mesh_cfg_net_transmit_set_t net_transmit_set; /*!< For ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET */
} esp_ble_mesh_cfg_client_set_state_t;
/** Parameter of Config Beacon Status */
typedef struct {
uint8_t beacon; /*!< Secure Network Beacon state value */
} esp_ble_mesh_cfg_beacon_status_cb_t;
/** Parameters of Config Composition Data Status */
typedef struct {
uint8_t page; /*!< Page number of the Composition Data */
struct net_buf_simple *composition_data; /*!< Pointer to Composition Data for the identified page */
} esp_ble_mesh_cfg_comp_data_status_cb_t;
/** Parameter of Config Default TTL Status */
typedef struct {
uint8_t default_ttl; /*!< Default TTL state value */
} esp_ble_mesh_cfg_default_ttl_status_cb_t;
/** Parameter of Config GATT Proxy Status */
typedef struct {
uint8_t gatt_proxy; /*!< GATT Proxy state value */
} esp_ble_mesh_cfg_gatt_proxy_status_cb_t;
/** Parameters of Config Relay Status */
typedef struct {
uint8_t relay; /*!< Relay state value */
uint8_t retransmit; /*!< Relay retransmit value(number of retransmissions and number of 10-millisecond steps between retransmissions) */
} esp_ble_mesh_cfg_relay_status_cb_t;
/** Parameters of Config Model Publication Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t element_addr; /*!< Address of the element */
uint16_t publish_addr; /*!< Value of the publish address */
uint16_t app_idx; /*!< Index of the application key */
bool cred_flag; /*!< Value of the Friendship Credential Flag */
uint8_t ttl; /*!< Default TTL value for the outgoing messages */
uint8_t period; /*!< Period for periodic status publishing */
uint8_t transmit; /*!< Number of retransmissions and number of 50-millisecond steps between retransmissions */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_cfg_model_pub_status_cb_t;
/** Parameters of Config Model Subscription Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t element_addr; /*!< Address of the element */
uint16_t sub_addr; /*!< Value of the address */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_cfg_model_sub_status_cb_t;
/** Parameters of Config NetKey Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t net_idx; /*!< Index of the NetKey */
} esp_ble_mesh_cfg_net_key_status_cb_t;
/** Parameters of Config AppKey Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t net_idx; /*!< Index of the NetKey */
uint16_t app_idx; /*!< Index of the application key */
} esp_ble_mesh_cfg_app_key_status_cb_t;
/** Parameters of Config Model App Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t element_addr; /*!< Address of the element */
uint16_t app_idx; /*!< Index of the application key */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_cfg_mod_app_status_cb_t;
/** Parameter of Config Friend Status */
typedef struct {
uint8_t friend_state; /*!< Friend state value */
} esp_ble_mesh_cfg_friend_status_cb_t;
/** Parameters of Config Heartbeat Publication Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t dst; /*!< Destination address for Heartbeat messages */
uint8_t count; /*!< Number of Heartbeat messages remaining to be sent */
uint8_t period; /*!< Period for sending Heartbeat messages */
uint8_t ttl; /*!< TTL to be used when sending Heartbeat messages */
uint16_t features; /*!< Features that trigger Heartbeat messages when changed */
uint16_t net_idx; /*!< Index of the NetKey */
} esp_ble_mesh_cfg_hb_pub_status_cb_t;
/** Parameters of Config Heartbeat Subscription Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t src; /*!< Source address for Heartbeat messages */
uint16_t dst; /*!< Destination address for Heartbeat messages */
uint8_t period; /*!< Remaining Period for processing Heartbeat messages */
uint8_t count; /*!< Number of Heartbeat messages received */
uint8_t min_hops; /*!< Minimum hops when receiving Heartbeat messages */
uint8_t max_hops; /*!< Maximum hops when receiving Heartbeat messages */
} esp_ble_mesh_cfg_hb_sub_status_cb_t;
/** Parameters of Config Network Transmit Status */
typedef struct {
uint8_t net_trans_count: 3; /*!< Number of transmissions for each Network PDU originating from the node */
uint8_t net_trans_step : 5; /*!< Maximum hops when receiving Heartbeat messages */
} esp_ble_mesh_cfg_net_trans_status_cb_t;
/** Parameters of Config SIG/Vendor Subscription List */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t element_addr; /*!< Address of the element */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
struct net_buf_simple *sub_addr; /*!< A block of all addresses from the Subscription List */
} esp_ble_mesh_cfg_model_sub_list_cb_t;
/** Parameter of Config NetKey List */
typedef struct {
struct net_buf_simple *net_idx; /*!< A list of NetKey Indexes known to the node */
} esp_ble_mesh_cfg_net_key_list_cb_t;
/** Parameters of Config AppKey List */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t net_idx; /*!< NetKey Index of the NetKey that the AppKeys are bound to */
struct net_buf_simple *app_idx; /*!< A list of AppKey indexes that are bound to the NetKey identified by NetKeyIndex */
} esp_ble_mesh_cfg_app_key_list_cb_t;
/** Parameters of Config Node Identity Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t net_idx; /*!< Index of the NetKey */
uint8_t identity; /*!< Node Identity state */
} esp_ble_mesh_cfg_node_id_status_cb_t;
/** Parameters of Config SIG/Vendor Model App List */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t element_addr; /*!< Address of the element */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
struct net_buf_simple *app_idx; /*!< All AppKey indexes bound to the Model */
} esp_ble_mesh_cfg_model_app_list_cb_t;
/** Parameters of Config Key Refresh Phase Status */
typedef struct {
uint8_t status; /*!< Status Code for the request message */
uint16_t net_idx; /*!< Index of the NetKey */
uint8_t phase; /*!< Key Refresh Phase state */
} esp_ble_mesh_cfg_kr_phase_status_cb_t;
/** Parameters of Config Low Power Node PollTimeout Status */
typedef struct {
uint16_t lpn_addr; /*!< The unicast address of the Low Power node */
int32_t poll_timeout; /*!< The current value of the PollTimeout timer of the Low Power node */
} esp_ble_mesh_cfg_lpn_pollto_status_cb_t;
/**
* @brief Configuration Client Model received message union
*/
typedef union {
esp_ble_mesh_cfg_beacon_status_cb_t beacon_status; /*!< The beacon status value */
esp_ble_mesh_cfg_comp_data_status_cb_t comp_data_status; /*!< The composition data status value */
esp_ble_mesh_cfg_default_ttl_status_cb_t default_ttl_status; /*!< The default_ttl status value */
esp_ble_mesh_cfg_gatt_proxy_status_cb_t gatt_proxy_status; /*!< The gatt_proxy status value */
esp_ble_mesh_cfg_relay_status_cb_t relay_status; /*!< The relay status value */
esp_ble_mesh_cfg_model_pub_status_cb_t model_pub_status; /*!< The model publication status value */
esp_ble_mesh_cfg_model_sub_status_cb_t model_sub_status; /*!< The model subscription status value */
esp_ble_mesh_cfg_net_key_status_cb_t netkey_status; /*!< The netkey status value */
esp_ble_mesh_cfg_app_key_status_cb_t appkey_status; /*!< The appkey status value */
esp_ble_mesh_cfg_mod_app_status_cb_t model_app_status; /*!< The model app status value */
esp_ble_mesh_cfg_friend_status_cb_t friend_status; /*!< The friend status value */
esp_ble_mesh_cfg_hb_pub_status_cb_t heartbeat_pub_status; /*!< The heartbeat publication status value */
esp_ble_mesh_cfg_hb_sub_status_cb_t heartbeat_sub_status; /*!< The heartbeat subscription status value */
esp_ble_mesh_cfg_net_trans_status_cb_t net_transmit_status; /*!< The network transmit status value */
esp_ble_mesh_cfg_model_sub_list_cb_t model_sub_list; /*!< The model subscription list value */
esp_ble_mesh_cfg_net_key_list_cb_t netkey_list; /*!< The network key index list value */
esp_ble_mesh_cfg_app_key_list_cb_t appkey_list; /*!< The application key index list value */
esp_ble_mesh_cfg_node_id_status_cb_t node_identity_status; /*!< The node identity status value */
esp_ble_mesh_cfg_model_app_list_cb_t model_app_list; /*!< The model application key index list value */
esp_ble_mesh_cfg_kr_phase_status_cb_t kr_phase_status; /*!< The key refresh phase status value */
esp_ble_mesh_cfg_lpn_pollto_status_cb_t lpn_timeout_status; /*!< The low power node poll timeout status value */
} esp_ble_mesh_cfg_client_common_cb_param_t;
/** Configuration Client Model callback parameters */
typedef struct {
int error_code; /*!< Appropriate error code */
esp_ble_mesh_client_common_param_t *params; /*!< The client common parameters */
esp_ble_mesh_cfg_client_common_cb_param_t status_cb; /*!< The config status message callback values */
} esp_ble_mesh_cfg_client_cb_param_t;
/** This enum value is the event of Configuration Client Model */
typedef enum {
ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT,
ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT,
ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT,
ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT,
ESP_BLE_MESH_CFG_CLIENT_EVT_MAX,
} esp_ble_mesh_cfg_client_cb_event_t;
/**
* @brief Configuration Server model related context.
*/
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint16_t pub_addr; /*!< Publish Address */
uint16_t app_idx; /*!< AppKey Index */
bool cred_flag; /*!< Friendship Credential Flag */
uint8_t pub_ttl; /*!< Publish TTL */
uint8_t pub_period; /*!< Publish Period */
uint8_t pub_retransmit; /*!< Publish Retransmit */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_mod_pub_set_t;
/** Parameters of Config Model Subscription Add */
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint16_t sub_addr; /*!< Subscription Address */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_model_sub_add_t;
/** Parameters of Config Model Subscription Delete */
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint16_t sub_addr; /*!< Subscription Address */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_model_sub_delete_t;
/** Parameters of Config NetKey Add */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
uint8_t net_key[16]; /*!< NetKey */
} esp_ble_mesh_state_change_cfg_netkey_add_t;
/** Parameters of Config NetKey Update */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
uint8_t net_key[16]; /*!< NetKey */
} esp_ble_mesh_state_change_cfg_netkey_update_t;
/** Parameter of Config NetKey Delete */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
} esp_ble_mesh_state_change_cfg_netkey_delete_t;
/** Parameters of Config AppKey Add */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
uint16_t app_idx; /*!< AppKey Index */
uint8_t app_key[16]; /*!< AppKey */
} esp_ble_mesh_state_change_cfg_appkey_add_t;
/** Parameters of Config AppKey Update */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
uint16_t app_idx; /*!< AppKey Index */
uint8_t app_key[16]; /*!< AppKey */
} esp_ble_mesh_state_change_cfg_appkey_update_t;
/** Parameters of Config AppKey Delete */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
uint16_t app_idx; /*!< AppKey Index */
} esp_ble_mesh_state_change_cfg_appkey_delete_t;
/** Parameters of Config Model App Bind */
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint16_t app_idx; /*!< AppKey Index */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_model_app_bind_t;
/** Parameters of Config Model App Unbind */
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint16_t app_idx; /*!< AppKey Index */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_model_app_unbind_t;
/** Parameters of Config Key Refresh Phase Set */
typedef struct {
uint16_t net_idx; /*!< NetKey Index */
uint8_t kr_phase; /*!< New Key Refresh Phase Transition */
} esp_ble_mesh_state_change_cfg_kr_phase_set_t;
/**
* @brief Configuration Server model state change value union
*/
typedef union {
/**
* The recv_op in ctx can be used to decide which state is changed.
*/
esp_ble_mesh_state_change_cfg_mod_pub_set_t mod_pub_set; /*!< Config Model Publication Set */
esp_ble_mesh_state_change_cfg_model_sub_add_t mod_sub_add; /*!< Config Model Subscription Add */
esp_ble_mesh_state_change_cfg_model_sub_delete_t mod_sub_delete; /*!< Config Model Subscription Delete */
esp_ble_mesh_state_change_cfg_netkey_add_t netkey_add; /*!< Config NetKey Add */
esp_ble_mesh_state_change_cfg_netkey_update_t netkey_update; /*!< Config NetKey Update */
esp_ble_mesh_state_change_cfg_netkey_delete_t netkey_delete; /*!< Config NetKey Delete */
esp_ble_mesh_state_change_cfg_appkey_add_t appkey_add; /*!< Config AppKey Add */
esp_ble_mesh_state_change_cfg_appkey_update_t appkey_update; /*!< Config AppKey Update */
esp_ble_mesh_state_change_cfg_appkey_delete_t appkey_delete; /*!< Config AppKey Delete */
esp_ble_mesh_state_change_cfg_model_app_bind_t mod_app_bind; /*!< Config Model App Bind */
esp_ble_mesh_state_change_cfg_model_app_unbind_t mod_app_unbind; /*!< Config Model App Unbind */
esp_ble_mesh_state_change_cfg_kr_phase_set_t kr_phase_set; /*!< Config Key Refresh Phase Set */
} esp_ble_mesh_cfg_server_state_change_t;
/**
* @brief Configuration Server model callback value union
*/
typedef union {
esp_ble_mesh_cfg_server_state_change_t state_change; /*!< ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT */
} esp_ble_mesh_cfg_server_cb_value_t;
/** Configuration Server model callback parameters */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the server model structure */
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received message */
esp_ble_mesh_cfg_server_cb_value_t value; /*!< Value of the received configuration messages */
} esp_ble_mesh_cfg_server_cb_param_t;
/** This enum value is the event of Configuration Server model */
typedef enum {
ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT,
ESP_BLE_MESH_CFG_SERVER_EVT_MAX,
} esp_ble_mesh_cfg_server_cb_event_t;
/**
* @brief Bluetooth Mesh Config Client and Server Model functions.
*/
/**
* @brief Configuration Client Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_cfg_client_cb_t)(esp_ble_mesh_cfg_client_cb_event_t event,
esp_ble_mesh_cfg_client_cb_param_t *param);
/**
* @brief Configuration Server Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_cfg_server_cb_t)(esp_ble_mesh_cfg_server_cb_event_t event,
esp_ble_mesh_cfg_server_cb_param_t *param);
/**
* @brief Register BLE Mesh Config Client Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_cb_t callback);
/**
* @brief Register BLE Mesh Config Server Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_cb_t callback);
/**
* @brief Get the value of Config Server Model states using the Config Client Model get messages.
*
* @note If you want to find the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_opcode_config_client_get_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] get_state: Pointer to a union, each kind of opcode corresponds to one structure inside.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_get_state_t *get_state);
/**
* @brief Set the value of the Configuration Server Model states using the Config Client Model set messages.
*
* @note If you want to find the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_opcode_config_client_set_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] set_state: Pointer to a union, each kind of opcode corresponds to one structure inside.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_cfg_client_set_state_t *set_state);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_CONFIG_MODEL_API_H_ */

View File

@ -0,0 +1,406 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_BLE_MESH_HEALTH_MODEL_API_H_
#define _ESP_BLE_MESH_HEALTH_MODEL_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @def ESP_BLE_MESH_MODEL_HEALTH_SRV
*
* @brief Define a new Health Server Model.
*
* @note The Health Server Model can only be included by a Primary Element.
*
* @param srv Pointer to the unique struct esp_ble_mesh_health_srv_t.
* @param pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
*
* @return New Health Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_HEALTH_SRV(srv, pub) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_HEALTH_SRV, \
NULL, pub, srv)
/** @def ESP_BLE_MESH_MODEL_HEALTH_CLI
*
* @brief Define a new Health Client Model.
*
* @note This API needs to be called for each element on which
* the application needs to have a Health Client Model.
*
* @param cli_data Pointer to the unique struct esp_ble_mesh_client_t.
*
* @return New Health Client Model instance.
*/
#define ESP_BLE_MESH_MODEL_HEALTH_CLI(cli_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_HEALTH_CLI, \
NULL, NULL, cli_data)
/** @def ESP_BLE_MESH_HEALTH_PUB_DEFINE
*
* A helper to define a health publication context
*
* @param _name Name given to the publication context variable.
* @param _max Maximum number of faults the element can have.
* @param _role Role of the device which contains the model.
*/
#define ESP_BLE_MESH_HEALTH_PUB_DEFINE(_name, _max, _role) \
ESP_BLE_MESH_MODEL_PUB_DEFINE(_name, (1 + 3 + (_max)), _role)
/**
* SIG identifier of Health Fault Test.
* 0x01 ~ 0xFF: Vendor Specific Test.
*/
#define ESP_BLE_MESH_HEALTH_STANDARD_TEST 0x00
/**
* Fault values of Health Fault Test.
* 0x33 ~ 0x7F: Reserved for Future Use.
* 0x80 ~ 0xFF: Vendor Specific Warning/Error.
*/
#define ESP_BLE_MESH_NO_FAULT 0x00
#define ESP_BLE_MESH_BATTERY_LOW_WARNING 0x01
#define ESP_BLE_MESH_BATTERY_LOW_ERROR 0x02
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_LOW_WARNING 0x03
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_LOW_ERROR 0x04
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_HIGH_WARNING 0x05
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_HIGH_ERROR 0x06
#define ESP_BLE_MESH_POWER_SUPPLY_INTERRUPTED_WARNING 0x07
#define ESP_BLE_MESH_POWER_SUPPLY_INTERRUPTED_ERROR 0x08
#define ESP_BLE_MESH_NO_LOAD_WARNING 0x09
#define ESP_BLE_MESH_NO_LOAD_ERROR 0x0A
#define ESP_BLE_MESH_OVERLOAD_WARNING 0x0B
#define ESP_BLE_MESH_OVERLOAD_ERROR 0x0C
#define ESP_BLE_MESH_OVERHEAT_WARNING 0x0D
#define ESP_BLE_MESH_OVERHEAT_ERROR 0x0E
#define ESP_BLE_MESH_CONDENSATION_WARNING 0x0F
#define ESP_BLE_MESH_CONDENSATION_ERROR 0x10
#define ESP_BLE_MESH_VIBRATION_WARNING 0x11
#define ESP_BLE_MESH_VIBRATION_ERROR 0x12
#define ESP_BLE_MESH_CONFIGURATION_WARNING 0x13
#define ESP_BLE_MESH_CONFIGURATION_ERROR 0x14
#define ESP_BLE_MESH_ELEMENT_NOT_CALIBRATED_WARNING 0x15
#define ESP_BLE_MESH_ELEMENT_NOT_CALIBRATED_ERROR 0x16
#define ESP_BLE_MESH_MEMORY_WARNING 0x17
#define ESP_BLE_MESH_MEMORY_ERROR 0x18
#define ESP_BLE_MESH_SELF_TEST_WARNING 0x19
#define ESP_BLE_MESH_SELF_TEST_ERROR 0x1A
#define ESP_BLE_MESH_INPUT_TOO_LOW_WARNING 0x1B
#define ESP_BLE_MESH_INPUT_TOO_LOW_ERROR 0x1C
#define ESP_BLE_MESH_INPUT_TOO_HIGH_WARNING 0x1D
#define ESP_BLE_MESH_INPUT_TOO_HIGH_ERROR 0x1E
#define ESP_BLE_MESH_INPUT_NO_CHANGE_WARNING 0x1F
#define ESP_BLE_MESH_INPUT_NO_CHANGE_ERROR 0x20
#define ESP_BLE_MESH_ACTUATOR_BLOCKED_WARNING 0x21
#define ESP_BLE_MESH_ACTUATOR_BLOCKED_ERROR 0x22
#define ESP_BLE_MESH_HOUSING_OPENED_WARNING 0x23
#define ESP_BLE_MESH_HOUSING_OPENED_ERROR 0x24
#define ESP_BLE_MESH_TAMPER_WARNING 0x25
#define ESP_BLE_MESH_TAMPER_ERROR 0x26
#define ESP_BLE_MESH_DEVICE_MOVED_WARNING 0x27
#define ESP_BLE_MESH_DEVICE_MOVED_ERROR 0x28
#define ESP_BLE_MESH_DEVICE_DROPPED_WARNING 0x29
#define ESP_BLE_MESH_DEVICE_DROPPED_ERROR 0x2A
#define ESP_BLE_MESH_OVERFLOW_WARNING 0x2B
#define ESP_BLE_MESH_OVERFLOW_ERROR 0x2C
#define ESP_BLE_MESH_EMPTY_WARNING 0x2D
#define ESP_BLE_MESH_EMPTY_ERROR 0x2E
#define ESP_BLE_MESH_INTERNAL_BUS_WARNING 0x2F
#define ESP_BLE_MESH_INTERNAL_BUS_ERROR 0x30
#define ESP_BLE_MESH_MECHANISM_JAMMED_WARNING 0x31
#define ESP_BLE_MESH_MECHANISM_JAMMED_ERROR 0x32
/** ESP BLE Mesh Health Server callback */
typedef struct {
/** Clear health registered faults. Initialized by the stack. */
esp_ble_mesh_cb_t fault_clear;
/** Run a specific health test. Initialized by the stack. */
esp_ble_mesh_cb_t fault_test;
/** Health attention on callback. Initialized by the stack. */
esp_ble_mesh_cb_t attention_on;
/** Health attention off callback. Initialized by the stack. */
esp_ble_mesh_cb_t attention_off;
} esp_ble_mesh_health_srv_cb_t;
#define ESP_BLE_MESH_HEALTH_FAULT_ARRAY_SIZE 32
/** ESP BLE Mesh Health Server test Context */
typedef struct {
uint8_t id_count; /*!< Number of Health self-test ID */
const uint8_t *test_ids; /*!< Array of Health self-test IDs */
uint16_t company_id; /*!< Company ID used to identify the Health Fault state */
uint8_t prev_test_id; /*!< Current test ID of the health fault test */
uint8_t current_faults[ESP_BLE_MESH_HEALTH_FAULT_ARRAY_SIZE]; /*!< Array of current faults */
uint8_t registered_faults[ESP_BLE_MESH_HEALTH_FAULT_ARRAY_SIZE]; /*!< Array of registered faults */
} __attribute__((packed)) esp_ble_mesh_health_test_t;
/** ESP BLE Mesh Health Server Model Context */
typedef struct {
/** Pointer to Health Server Model */
esp_ble_mesh_model_t *model;
/** Health callback struct */
esp_ble_mesh_health_srv_cb_t health_cb;
/** Attention Timer state */
struct k_delayed_work attention_timer;
/** Attention Timer start flag */
bool attention_timer_start;
/** Health Server fault test */
esp_ble_mesh_health_test_t health_test;
} esp_ble_mesh_health_srv_t;
/** Parameter of Health Fault Get */
typedef struct {
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
} esp_ble_mesh_health_fault_get_t;
/** Parameter of Health Attention Set */
typedef struct {
uint8_t attention; /*!< Value of the Attention Timer state */
} esp_ble_mesh_health_attention_set_t;
/** Parameter of Health Period Set */
typedef struct {
uint8_t fast_period_divisor; /*!< Divider for the Publish Period */
} esp_ble_mesh_health_period_set_t;
/** Parameter of Health Fault Test */
typedef struct {
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
uint8_t test_id; /*!< ID of a specific test to be performed */
} esp_ble_mesh_health_fault_test_t;
/** Parameter of Health Fault Clear */
typedef struct {
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
} esp_ble_mesh_health_fault_clear_t;
/**
* @brief For ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET
* ESP_BLE_MESH_MODEL_OP_ATTENTION_GET
* ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET
* the get_state parameter in the esp_ble_mesh_health_client_get_state function should not be set to NULL.
*/
typedef union {
esp_ble_mesh_health_fault_get_t fault_get; /*!< For ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET. */
} esp_ble_mesh_health_client_get_state_t;
/**
* @brief For ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR
* ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK
* ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST
* ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK
* ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET
* ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK
* ESP_BLE_MESH_MODEL_OP_ATTENTION_SET
* ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK
* the set_state parameter in the esp_ble_mesh_health_client_set_state function should not be set to NULL.
*/
typedef union {
esp_ble_mesh_health_attention_set_t attention_set; /*!< For ESP_BLE_MESH_MODEL_OP_ATTENTION_SET or ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK. */
esp_ble_mesh_health_period_set_t period_set; /*!< For ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET or ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK. */
esp_ble_mesh_health_fault_test_t fault_test; /*!< For ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST or ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK. */
esp_ble_mesh_health_fault_clear_t fault_clear; /*!< For ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR or ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK. */
} esp_ble_mesh_health_client_set_state_t;
/** Parameters of Health Current Status */
typedef struct {
uint8_t test_id; /*!< ID of a most recently performed test */
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
struct net_buf_simple *fault_array; /*!< FaultArray field contains a sequence of 1-octet fault values */
} esp_ble_mesh_health_current_status_cb_t;
/** Parameters of Health Fault Status */
typedef struct {
uint8_t test_id; /*!< ID of a most recently performed test */
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
struct net_buf_simple *fault_array; /*!< FaultArray field contains a sequence of 1-octet fault values */
} esp_ble_mesh_health_fault_status_cb_t;
/** Parameter of Health Period Status */
typedef struct {
uint8_t fast_period_divisor; /*!< Divider for the Publish Period */
} esp_ble_mesh_health_period_status_cb_t;
/** Parameter of Health Attention Status */
typedef struct {
uint8_t attention; /*!< Value of the Attention Timer state */
} esp_ble_mesh_health_attention_status_cb_t;
/**
* @brief Health Client Model received message union
*/
typedef union {
esp_ble_mesh_health_current_status_cb_t current_status; /*!< The health current status value */
esp_ble_mesh_health_fault_status_cb_t fault_status; /*!< The health fault status value */
esp_ble_mesh_health_period_status_cb_t period_status; /*!< The health period status value */
esp_ble_mesh_health_attention_status_cb_t attention_status; /*!< The health attention status value */
} esp_ble_mesh_health_client_common_cb_param_t;
/** Health Client Model callback parameters */
typedef struct {
int error_code; /*!< Appropriate error code */
esp_ble_mesh_client_common_param_t *params; /*!< The client common parameters. */
esp_ble_mesh_health_client_common_cb_param_t status_cb; /*!< The health message status callback values */
} esp_ble_mesh_health_client_cb_param_t;
/** This enum value is the event of Health Client Model */
typedef enum {
ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT,
ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT,
ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT,
ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT,
ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX,
} esp_ble_mesh_health_client_cb_event_t;
/** Parameter of publishing Health Current Status completion event */
typedef struct {
int error_code; /*!< The result of publishing Health Current Status */
esp_ble_mesh_elem_t *element; /*!< Pointer to the element which contains the Health Server Model */
} esp_ble_mesh_health_fault_update_comp_cb_t;
/** Parameters of Health Fault Clear event */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
} esp_ble_mesh_health_fault_clear_cb_t;
/** Parameters of Health Fault Test event */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
uint8_t test_id; /*!< ID of a specific test to be performed */
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
} esp_ble_mesh_health_fault_test_cb_t;
/** Parameter of Health Attention On event */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
uint8_t time; /*!< Duration of attention timer on (in seconds) */
} esp_ble_mesh_health_attention_on_cb_t;
/** Parameter of Health Attention Off event */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
} esp_ble_mesh_health_attention_off_cb_t;
/**
* @brief Health Server Model callback parameters union
*/
typedef union {
esp_ble_mesh_health_fault_update_comp_cb_t fault_update_comp; /*!< ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT */
esp_ble_mesh_health_fault_clear_cb_t fault_clear; /*!< ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT */
esp_ble_mesh_health_fault_test_cb_t fault_test; /*!< ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT */
esp_ble_mesh_health_attention_on_cb_t attention_on; /*!< ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT */
esp_ble_mesh_health_attention_off_cb_t attention_off; /*!< ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT */
} esp_ble_mesh_health_server_cb_param_t;
/** This enum value is the event of Health Server Model */
typedef enum {
ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT,
ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT,
ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT,
ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT,
ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT,
ESP_BLE_MESH_HEALTH_SERVER_EVT_MAX,
} esp_ble_mesh_health_server_cb_event_t;
/**
* @brief Bluetooth Mesh Health Client and Server Model function.
*/
/**
* @brief Health Client Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_health_client_cb_t)(esp_ble_mesh_health_client_cb_event_t event,
esp_ble_mesh_health_client_cb_param_t *param);
/**
* @brief Health Server Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_health_server_cb_t)(esp_ble_mesh_health_server_cb_event_t event,
esp_ble_mesh_health_server_cb_param_t *param);
/**
* @brief Register BLE Mesh Health Model callback, the callback will report Health Client & Server Model events.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_health_client_callback(esp_ble_mesh_health_client_cb_t callback);
/**
* @brief Register BLE Mesh Health Server Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_server_cb_t callback);
/**
* @brief This function is called to get the Health Server states using the Health Client Model get messages.
*
* @note If you want to find the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_opcode_health_client_get_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] get_state: Pointer to a union, each kind of opcode corresponds to one structure inside.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_get_state_t *get_state);
/**
* @brief This function is called to set the Health Server states using the Health Client Model set messages.
*
* @note If you want to find the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_opcode_health_client_set_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] set_state: Pointer to a union, each kind of opcode corresponds to one structure inside.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_health_client_set_state_t *set_state);
/**
* @brief This function is called by the Health Server Model to update the context of its Health Current status.
*
* @param[in] element: The element to which the Health Server Model belongs.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_HEALTH_MODEL_API_H_ */

View File

@ -0,0 +1,709 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Sensor Client Model APIs.
*/
#ifndef _ESP_BLE_MESH_SENSOR_MODEL_API_H_
#define _ESP_BLE_MESH_SENSOR_MODEL_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @def ESP_BLE_MESH_MODEL_SENSOR_CLI
*
* @brief Define a new Sensor Client Model.
*
* @note This API needs to be called for each element on which
* the application needs to have a Sensor Client Model.
*
* @param cli_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param cli_data Pointer to the unique struct esp_ble_mesh_client_t.
*
* @return New Sensor Client Model instance.
*/
#define ESP_BLE_MESH_MODEL_SENSOR_CLI(cli_pub, cli_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_CLI, \
NULL, cli_pub, cli_data)
/**
* @brief Bluetooth Mesh Sensor Client Model Get and Set parameters structure.
*/
/** Parameters of Sensor Descriptor Get */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID of a sensor (optional) */
} esp_ble_mesh_sensor_descriptor_get_t;
/** Parameter of Sensor Cadence Get */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_sensor_cadence_get_t;
/** Parameters of Sensor Cadence Set */
typedef struct {
uint16_t property_id; /*!< Property ID for the sensor */
uint8_t fast_cadence_period_divisor : 7, /*!< Divisor for the publish period */
status_trigger_type : 1; /*!< The unit and format of the Status Trigger Delta fields */
struct net_buf_simple *status_trigger_delta_down; /*!< Delta down value that triggers a status message */
struct net_buf_simple *status_trigger_delta_up; /*!< Delta up value that triggers a status message */
uint8_t status_min_interval; /*!< Minimum interval between two consecutive Status messages */
struct net_buf_simple *fast_cadence_low; /*!< Low value for the fast cadence range */
struct net_buf_simple *fast_cadence_high; /*!< Fast value for the fast cadence range */
} esp_ble_mesh_sensor_cadence_set_t;
/** Parameter of Sensor Settings Get */
typedef struct {
uint16_t sensor_property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_sensor_settings_get_t;
/** Parameters of Sensor Setting Get */
typedef struct {
uint16_t sensor_property_id; /*!< Property ID of a sensor */
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
} esp_ble_mesh_sensor_setting_get_t;
/** Parameters of Sensor Setting Set */
typedef struct {
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
struct net_buf_simple *sensor_setting_raw; /*!< Raw value for the setting */
} esp_ble_mesh_sensor_setting_set_t;
/** Parameters of Sensor Get */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID for the sensor (optional) */
} esp_ble_mesh_sensor_get_t;
/** Parameters of Sensor Column Get */
typedef struct {
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value_x; /*!< Raw value identifying a column */
} esp_ble_mesh_sensor_column_get_t;
/** Parameters of Sensor Series Get */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value_x1; /*!< Raw value identifying a starting column (optional) */
struct net_buf_simple *raw_value_x2; /*!< Raw value identifying an ending column (C.1) */
} esp_ble_mesh_sensor_series_get_t;
/**
* @brief Sensor Client Model get message union
*/
typedef union {
esp_ble_mesh_sensor_descriptor_get_t descriptor_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET */
esp_ble_mesh_sensor_cadence_get_t cadence_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET */
esp_ble_mesh_sensor_settings_get_t settings_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET */
esp_ble_mesh_sensor_setting_get_t setting_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_GET */
esp_ble_mesh_sensor_get_t sensor_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_GET */
esp_ble_mesh_sensor_column_get_t column_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET */
esp_ble_mesh_sensor_series_get_t series_get; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET */
} esp_ble_mesh_sensor_client_get_state_t;
/**
* @brief Sensor Client Model set message union
*/
typedef union {
esp_ble_mesh_sensor_cadence_set_t cadence_set; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET & ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK */
esp_ble_mesh_sensor_setting_set_t setting_set; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET & ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK */
} esp_ble_mesh_sensor_client_set_state_t;
/**
* @brief Bluetooth Mesh Sensor Client Model Get and Set callback parameters structure.
*/
/** Parameter of Sensor Descriptor Status */
typedef struct {
struct net_buf_simple *descriptor; /*!< Sequence of 8-octet sensor descriptors (optional) */
} esp_ble_mesh_sensor_descriptor_status_cb_t;
/** Parameters of Sensor Cadence Status */
typedef struct {
uint16_t property_id; /*!< Property for the sensor */
struct net_buf_simple *sensor_cadence_value; /*!< Value of sensor cadence state */
} esp_ble_mesh_sensor_cadence_status_cb_t;
/** Parameters of Sensor Settings Status */
typedef struct {
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
struct net_buf_simple *sensor_setting_property_ids; /*!< A sequence of N sensor setting property IDs (optional) */
} esp_ble_mesh_sensor_settings_status_cb_t;
/** Parameters of Sensor Setting Status */
typedef struct {
bool op_en; /*!< Indicate id optional parameters are included */
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
uint8_t sensor_setting_access; /*!< Read/Write access rights for the setting (optional) */
struct net_buf_simple *sensor_setting_raw; /*!< Raw value for the setting */
} esp_ble_mesh_sensor_setting_status_cb_t;
/** Parameter of Sensor Status */
typedef struct {
struct net_buf_simple *marshalled_sensor_data; /*!< Value of sensor data state (optional) */
} esp_ble_mesh_sensor_status_cb_t;
/** Parameters of Sensor Column Status */
typedef struct {
uint16_t property_id; /*!< Property identifying a sensor and the Y axis */
struct net_buf_simple *sensor_column_value; /*!< Left values of sensor column status */
} esp_ble_mesh_sensor_column_status_cb_t;
/** Parameters of Sensor Series Status */
typedef struct {
uint16_t property_id; /*!< Property identifying a sensor and the Y axis */
struct net_buf_simple *sensor_series_value; /*!< Left values of sensor series status */
} esp_ble_mesh_sensor_series_status_cb_t;
/**
* @brief Sensor Client Model received message union
*/
typedef union {
esp_ble_mesh_sensor_descriptor_status_cb_t descriptor_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS */
esp_ble_mesh_sensor_cadence_status_cb_t cadence_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS */
esp_ble_mesh_sensor_settings_status_cb_t settings_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS */
esp_ble_mesh_sensor_setting_status_cb_t setting_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS */
esp_ble_mesh_sensor_status_cb_t sensor_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS */
esp_ble_mesh_sensor_column_status_cb_t column_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS */
esp_ble_mesh_sensor_series_status_cb_t series_status; /*!< For ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS */
} esp_ble_mesh_sensor_client_status_cb_t;
/** Sensor Client Model callback parameters */
typedef struct {
int error_code; /*!< 0: success,
* otherwise failure. For the error code values please refer to errno.h file.
* A negative sign is added to the standard error codes in errno.h. */
esp_ble_mesh_client_common_param_t *params; /*!< The client common parameters. */
esp_ble_mesh_sensor_client_status_cb_t status_cb; /*!< The sensor status message callback values */
} esp_ble_mesh_sensor_client_cb_param_t;
/** This enum value is the event of Sensor Client Model */
typedef enum {
ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT,
ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT,
ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT,
ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT,
ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX,
} esp_ble_mesh_sensor_client_cb_event_t;
/**
* @brief Bluetooth Mesh Sensor Client Model function.
*/
/**
* @brief Sensor Client Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_sensor_client_cb_t)(esp_ble_mesh_sensor_client_cb_event_t event,
esp_ble_mesh_sensor_client_cb_param_t *param);
/**
* @brief Register BLE Mesh Sensor Client Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_client_cb_t callback);
/**
* @brief Get the value of Sensor Server Model states using the Sensor Client Model get messages.
*
* @note If you want to know the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_sensor_message_opcode_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] get_state: Pointer to sensor get message value.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_sensor_client_get_state_t *get_state);
/**
* @brief Set the value of Sensor Server Model states using the Sensor Client Model set messages.
*
* @note If you want to know the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_sensor_message_opcode_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] set_state: Pointer to sensor set message value.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_sensor_client_set_state_t *set_state);
/**
* @brief Sensor Server Models related context.
*/
/** @def ESP_BLE_MESH_MODEL_SENSOR_SRV
*
* @brief Define a new Sensor Server Model.
*
* @note 1. The Sensor Server model is a root model. When this model is present
* on an element, the corresponding Sensor Setup Server model shall
* also be present.
* 2. This model shall support model publication and model subscription.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_sensor_srv_t.
*
* @return New Sensor Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SENSOR_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_SENSOR_SETUP_SRV
*
* @brief Define a new Sensor Setup Server Model.
*
* @note 1. The Sensor Setup Server model extends the Sensor Server model.
* 2. This model shall support model publication and model subscription.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_sensor_setup_srv_t.
*
* @return New Sensor Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SENSOR_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, \
NULL, srv_pub, srv_data)
#define ESP_BLE_MESH_INVALID_SENSOR_PROPERTY_ID 0x0000 /*!< Invalid Sensor Property ID */
#define ESP_BLE_MESH_SENSOR_PROPERTY_ID_LEN 0x02 /*!< Length of Sensor Property ID */
#define ESP_BLE_MESH_SENSOR_DESCRIPTOR_LEN 0x08 /*!< Length of Sensor Descriptor state */
#define ESP_BLE_MESH_SENSOR_UNSPECIFIED_POS_TOLERANCE 0x000 /*!< Unspecified Sensor Positive Tolerance */
#define ESP_BLE_MESH_SENSOR_UNSPECIFIED_NEG_TOLERANCE 0x000 /*!< Unspecified Sensor Negative Tolerance */
#define ESP_BLE_MESH_SENSOR_NOT_APPL_MEASURE_PERIOD 0x00 /*!< Not applicable Sensor Measurement Period */
#define ESP_BLE_MESH_SENSOR_NOT_APPL_UPDATE_INTERVAL 0x00 /*!< Not applicable Sensor Update Interval */
#define ESP_BLE_MESH_INVALID_SENSOR_SETTING_PROPERTY_ID 0x0000 /*!< Invalid Sensor Setting Property ID */
#define ESP_BLE_MESH_SENSOR_SETTING_PROPERTY_ID_LEN 0x02 /*!< Length of Sensor Setting Property ID */
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_LEN 0x01 /*!< Length of Sensor Setting Access */
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_READ 0x01 /*!< Sensor Setting Access - Read */
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_READ_WRITE 0x03 /*!< Sensor Setting Access - Read & Write */
#define ESP_BLE_MESH_SENSOR_DIVISOR_TRIGGER_TYPE_LEN 0x01 /*!< Length of Sensor Divisor Trigger Type */
#define ESP_BLE_MESH_SENSOR_STATUS_MIN_INTERVAL_LEN 0x01 /*!< Length of Sensor Status Min Interval */
#define ESP_BLE_MESH_SENSOR_PERIOD_DIVISOR_MAX_VALUE 15 /*!< Maximum value of Sensor Period Divisor */
#define ESP_BLE_MESH_SENSOR_STATUS_MIN_INTERVAL_MAX 26 /*!< Maximum value of Sensor Status Min Interval */
/**
* Sensor Status Trigger Type - Format Type of the characteristic
* that the Sensor Property ID state references
*/
#define ESP_BLE_MESH_SENSOR_STATUS_TRIGGER_TYPE_CHAR 0
/** Sensor Status Trigger Type - Format Type "uint16" */
#define ESP_BLE_MESH_SENSOR_STATUS_TRIGGER_TYPE_UINT16 1
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A 0x00 /*!< Sensor Data Format A */
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B 0x01 /*!< Sensor Data Format B */
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID_LEN 0x02 /*!< MPID length of Sensor Data Format A */
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID_LEN 0x03 /*!< MPID length of Sensor Data Format B */
/**
* Zero length of Sensor Data.
*
* Note:
* The Length field is a 1-based uint7 value (valid range 0x00x7F,
* representing range of 1127). The value 0x7F represents a length
* of zero.
*/
#define ESP_BLE_MESH_SENSOR_DATA_ZERO_LEN 0x7F
/** @def ESP_BLE_MESH_GET_SENSOR_DATA_FORMAT
*
* @brief Get format of the sensor data.
*
* @note Multiple sensor data may be concatenated. Make sure the _data pointer is
* updated before getting the format of the corresponding sensor data.
*
* @param _data Pointer to the start of the sensor data.
*
* @return Format of the sensor data.
*/
#define ESP_BLE_MESH_GET_SENSOR_DATA_FORMAT(_data) (((_data)[0]) & BIT_MASK(1))
/** @def ESP_BLE_MESH_GET_SENSOR_DATA_LENGTH
*
* @brief Get length of the sensor data.
*
* @note Multiple sensor data may be concatenated. Make sure the _data pointer is
* updated before getting the length of the corresponding sensor data.
*
* @param _data Pointer to the start of the sensor data.
* @param _fmt Format of the sensor data.
*
* @return Length (zero-based) of the sensor data.
*/
#define ESP_BLE_MESH_GET_SENSOR_DATA_LENGTH(_data, _fmt) \
(((_fmt) == ESP_BLE_MESH_SENSOR_DATA_FORMAT_A) ? ((((_data)[0]) >> 1) & BIT_MASK(4)) : ((((_data)[0]) >> 1) & BIT_MASK(7)))
/** @def ESP_BLE_MESH_GET_SENSOR_DATA_PROPERTY_ID
*
* @brief Get Sensor Property ID of the sensor data.
*
* @note Multiple sensor data may be concatenated. Make sure the _data pointer is
* updated before getting Sensor Property ID of the corresponding sensor data.
*
* @param _data Pointer to the start of the sensor data.
* @param _fmt Format of the sensor data.
*
* @return Sensor Property ID of the sensor data.
*/
#define ESP_BLE_MESH_GET_SENSOR_DATA_PROPERTY_ID(_data, _fmt) \
(((_fmt) == ESP_BLE_MESH_SENSOR_DATA_FORMAT_A) ? ((((_data)[1]) << 3) | (((_data)[0]) >> 5)) : ((((_data)[2]) << 8) | ((_data)[1])))
/** @def ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID
*
* @brief Generate a MPID value for sensor data with Format A.
*
* @note 1. The Format field is 0b0 and indicates that Format A is used.
* 2. The Length field is a 1-based uint4 value (valid range 0x00xF,
* representing range of 116).
* 3. The Property ID is an 11-bit bit field representing 11 LSb of a Property ID.
* 4. This format may be used for Property Values that are not longer than 16
* octets and for Property IDs less than 0x0800.
*
* @param _len Length of Sensor Raw value.
* @param _id Sensor Property ID.
*
* @return 2-octet MPID value for sensor data with Format A.
*
*/
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID(_len, _id) \
((((_id) & BIT_MASK(11)) << 5) | (((_len) & BIT_MASK(4)) << 1) | ESP_BLE_MESH_SENSOR_DATA_FORMAT_A)
/** @def ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID
*
* @brief Generate a MPID value for sensor data with Format B.
*
* @note 1. The Format field is 0b1 and indicates Format B is used.
* 2. The Length field is a 1-based uint7 value (valid range 0x00x7F, representing
* range of 1127). The value 0x7F represents a length of zero.
* 3. The Property ID is a 16-bit bit field representing a Property ID.
* 4. This format may be used for Property Values not longer than 128 octets and for
* any Property IDs. Property values longer than 128 octets are not supported by
* the Sensor Status message.
* 5. Exclude the generated 1-octet value, the 2-octet Sensor Property ID
*
* @param _len Length of Sensor Raw value.
* @param _id Sensor Property ID.
*
* @return 3-octet MPID value for sensor data with Format B.
*
*/
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID(_len, _id) \
(((_id) << 8) | (((_len) & BIT_MASK(7)) << 1) | ESP_BLE_MESH_SENSOR_DATA_FORMAT_B)
/** This enum value is value of Sensor Sampling Function */
enum esp_ble_mesh_sensor_sample_func {
ESP_BLE_MESH_SAMPLE_FUNC_UNSPECIFIED,
ESP_BLE_MESH_SAMPLE_FUNC_INSTANTANEOUS,
ESP_BLE_MESH_SAMPLE_FUNC_ARITHMETIC_MEAN,
ESP_BLE_MESH_SAMPLE_FUNC_RMS,
ESP_BLE_MESH_SAMPLE_FUNC_MAXIMUM,
ESP_BLE_MESH_SAMPLE_FUNC_MINIMUM,
ESP_BLE_MESH_SAMPLE_FUNC_ACCUMULATED,
ESP_BLE_MESH_SAMPLE_FUNC_COUNT,
};
/** Parameters of Sensor Descriptor state */
typedef struct {
uint32_t positive_tolerance : 12, /*!< The value of Sensor Positive Tolerance field */
negative_tolerance : 12, /*!< The value of Sensor Negative Tolerance field */
sampling_function : 8; /*!< The value of Sensor Sampling Function field */
uint8_t measure_period; /*!< The value of Sensor Measurement Period field */
uint8_t update_interval; /*!< The value of Sensor Update Interval field */
} esp_ble_mesh_sensor_descriptor_t;
/** Parameters of Sensor Setting state */
typedef struct {
uint16_t property_id; /*!< The value of Sensor Setting Property ID field */
uint8_t access; /*!< The value of Sensor Setting Access field */
struct net_buf_simple *raw; /*!< The value of Sensor Setting Raw field */
} esp_ble_mesh_sensor_setting_t;
/** Parameters of Sensor Cadence state */
typedef struct {
uint8_t period_divisor : 7, /*!< The value of Fast Cadence Period Divisor field */
trigger_type : 1; /*!< The value of Status Trigger Type field */
/**
* Note:
* The parameter "size" in trigger_delta_down, trigger_delta_up, fast_cadence_low &
* fast_cadence_high indicates the exact length of these four parameters, and they
* are associated with the Sensor Property ID. Users need to initialize the "size"
* precisely.
*/
struct net_buf_simple *trigger_delta_down; /*!< The value of Status Trigger Delta Down field */
struct net_buf_simple *trigger_delta_up; /*!< The value of Status Trigger Delta Up field */
uint8_t min_interval; /*!< The value of Status Min Interval field */
struct net_buf_simple *fast_cadence_low; /*!< The value of Fast Cadence Low field */
struct net_buf_simple *fast_cadence_high; /*!< The value of Fast Cadence High field */
} esp_ble_mesh_sensor_cadence_t;
/** Parameters of Sensor Data state */
typedef struct {
/**
* Format A: The Length field is a 1-based uint4 value (valid range 0x00xF,
* representing range of 1 16).
* Format B: The Length field is a 1-based uint7 value (valid range 0x00x7F,
* representing range of 1 127). The value 0x7F represents a
* length of zero.
*/
uint8_t format : 1, /*!< The value of the Sensor Data format */
length : 7; /*!< The value of the Sensor Data length */
struct net_buf_simple *raw_value; /*!< The value of Sensor Data raw value */
} esp_ble_mesh_sensor_data_t;
/** Parameters of Sensor Series Column state */
typedef struct {
struct net_buf_simple *raw_value_x; /*!< The value of Sensor Raw Value X field */
struct net_buf_simple *column_width; /*!< The value of Sensor Column Width field */
struct net_buf_simple *raw_value_y; /*!< The value of Sensor Raw Value Y field */
} esp_ble_mesh_sensor_series_column_t;
/** Parameters of Sensor states */
typedef struct {
uint16_t sensor_property_id; /*!< The value of Sensor Property ID field */
/* Constant throughout the lifetime of an element */
esp_ble_mesh_sensor_descriptor_t descriptor; /*!< Parameters of the Sensor Descriptor state */
/**
* Multiple Sensor Setting states may be present for each sensor.
* The Sensor Setting Property ID values shall be unique for each
* Sensor Property ID that identifies a sensor within an element.
*/
const uint8_t setting_count; /*!< */
esp_ble_mesh_sensor_setting_t *settings; /*!< Parameters of the Sensor Setting state */
/**
* The Sensor Cadence state may be not supported by sensors based
* on device properties referencing "non-scalar characteristics"
* such as "histograms" or "composite characteristics".
*/
esp_ble_mesh_sensor_cadence_t *cadence; /*!< Parameters of the Sensor Cadence state */
esp_ble_mesh_sensor_data_t sensor_data; /*!< Parameters of the Sensor Data state */
esp_ble_mesh_sensor_series_column_t series_column; /*!< Parameters of the Sensor Series Column state */
} esp_ble_mesh_sensor_state_t;
/** User data of Sensor Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Sensor Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
const uint8_t state_count; /*!< Sensor state count */
esp_ble_mesh_sensor_state_t *states; /*!< Parameters of the Sensor states */
} esp_ble_mesh_sensor_srv_t;
/** User data of Sensor Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Sensor Setup Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
const uint8_t state_count; /*!< Sensor state count */
esp_ble_mesh_sensor_state_t *states; /*!< Parameters of the Sensor states */
} esp_ble_mesh_sensor_setup_srv_t;
/** Parameters of Sensor Cadence Set state change event */
typedef struct {
uint16_t property_id; /*!< The value of Sensor Property ID state */
uint8_t period_divisor : 7, /*!< The value of Fast Cadence Period Divisor state */
trigger_type : 1; /*!< The value of Status Trigger Type state */
struct net_buf_simple *trigger_delta_down; /*!< The value of Status Trigger Delta Down state */
struct net_buf_simple *trigger_delta_up; /*!< The value of Status Trigger Delta Up state */
uint8_t min_interval; /*!< The value of Status Min Interval state */
struct net_buf_simple *fast_cadence_low; /*!< The value of Fast Cadence Low state */
struct net_buf_simple *fast_cadence_high; /*!< The value of Fast Cadence High state */
} esp_ble_mesh_state_change_sensor_cadence_set_t;
/** Parameters of Sensor Setting Set state change event */
typedef struct {
uint16_t property_id; /*!< The value of Sensor Property ID state */
uint16_t setting_property_id; /*!< The value of Sensor Setting Property ID state */
struct net_buf_simple *setting_value; /*!< The value of Sensor Property Value state */
} esp_ble_mesh_state_change_sensor_setting_set_t;
/**
* @brief Sensor Server Model state change value union
*/
typedef union {
/**
* The recv_op in ctx can be used to decide which state is changed.
*/
esp_ble_mesh_state_change_sensor_cadence_set_t sensor_cadence_set; /*!< Sensor Cadence Set */
esp_ble_mesh_state_change_sensor_setting_set_t sensor_setting_set; /*!< Sensor Setting Set */
} esp_ble_mesh_sensor_server_state_change_t;
/** Context of the received Sensor Descriptor Get message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID of a sensor (optional) */
} esp_ble_mesh_server_recv_sensor_descriptor_get_t;
/** Context of the received Sensor Cadence Get message */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_server_recv_sensor_cadence_get_t;
/** Context of the received Sensor Settings Get message */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_server_recv_sensor_settings_get_t;
/** Context of the received Sensor Setting Get message */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
uint16_t setting_property_id; /*!< Setting ID identifying a setting within a sensor */
} esp_ble_mesh_server_recv_sensor_setting_get_t;
/** Context of the received Sensor Get message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID for the sensor (optional) */
} esp_ble_mesh_server_recv_sensor_get_t;
/** Context of the received Sensor Column Get message */
typedef struct {
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value_x; /*!< Raw value identifying a column */
} esp_ble_mesh_server_recv_sensor_column_get_t;
/** Context of the received Sensor Series Get message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value; /*!< Raw value containing X1 and X2 (optional) */
} esp_ble_mesh_server_recv_sensor_series_get_t;
/**
* @brief Sensor Server Model received get message union
*/
typedef union {
esp_ble_mesh_server_recv_sensor_descriptor_get_t sensor_descriptor; /*!< Sensor Descriptor Get */
esp_ble_mesh_server_recv_sensor_cadence_get_t sensor_cadence; /*!< Sensor Cadence Get */
esp_ble_mesh_server_recv_sensor_settings_get_t sensor_settings; /*!< Sensor Settings Get */
esp_ble_mesh_server_recv_sensor_setting_get_t sensor_setting; /*!< Sensor Setting Get */
esp_ble_mesh_server_recv_sensor_get_t sensor_data; /*!< Sensor Get */
esp_ble_mesh_server_recv_sensor_column_get_t sensor_column; /*!< Sensor Column Get */
esp_ble_mesh_server_recv_sensor_series_get_t sensor_series; /*!< Sensor Series Get */
} esp_ble_mesh_sensor_server_recv_get_msg_t;
/** Context of the received Sensor Cadence Set message */
typedef struct {
uint16_t property_id; /*!< Property ID for the sensor */
struct net_buf_simple *cadence; /*!< Value of Sensor Cadence state */
} esp_ble_mesh_server_recv_sensor_cadence_set_t;
/** Context of the received Sensor Setting Set message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a sensor */
uint16_t setting_property_id; /*!< Setting ID identifying a setting within a sensor */
struct net_buf_simple *setting_raw; /*!< Raw value for the setting */
} esp_ble_mesh_server_recv_sensor_setting_set_t;
/**
* @brief Sensor Server Model received set message union
*/
typedef union {
esp_ble_mesh_server_recv_sensor_cadence_set_t sensor_cadence; /*!< Sensor Cadence Set */
esp_ble_mesh_server_recv_sensor_setting_set_t sensor_setting; /*!< Sensor Setting Set */
} esp_ble_mesh_sensor_server_recv_set_msg_t;
/**
* @brief Sensor Server Model callback value union
*/
typedef union {
esp_ble_mesh_sensor_server_state_change_t state_change; /*!< ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT */
esp_ble_mesh_sensor_server_recv_get_msg_t get; /*!< ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT */
esp_ble_mesh_sensor_server_recv_set_msg_t set; /*!< ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT */
} esp_ble_mesh_sensor_server_cb_value_t;
/** Sensor Server Model callback parameters */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to Sensor Server Models */
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received messages */
esp_ble_mesh_sensor_server_cb_value_t value; /*!< Value of the received Sensor Messages */
} esp_ble_mesh_sensor_server_cb_param_t;
/** This enum value is the event of Sensor Server Model */
typedef enum {
/**
* 1. When get_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, no event will be
* callback to the application layer when Sensor Get messages are received.
* 2. When set_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, this event will
* be callback to the application layer when Sensor Set/Set Unack messages
* are received.
*/
ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT,
/**
* When get_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
* callback to the application layer when Sensor Get messages are received.
*/
ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT,
/**
* When set_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
* callback to the application layer when Sensor Set/Set Unack messages are received.
*/
ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT,
ESP_BLE_MESH_SENSOR_SERVER_EVT_MAX,
} esp_ble_mesh_sensor_server_cb_event_t;
/**
* @brief Bluetooth Mesh Sensor Server Model function.
*/
/**
* @brief Sensor Server Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_sensor_server_cb_t)(esp_ble_mesh_sensor_server_cb_event_t event,
esp_ble_mesh_sensor_server_cb_param_t *param);
/**
* @brief Register BLE Mesh Sensor Server Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_sensor_server_callback(esp_ble_mesh_sensor_server_cb_t callback);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_SENSOR_MODEL_API_H_ */

View File

@ -0,0 +1,911 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Time and Scene Client Model APIs.
*/
#ifndef _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_
#define _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @def ESP_BLE_MESH_MODEL_TIME_CLI
*
* @brief Define a new Time Client Model.
*
* @note This API needs to be called for each element on which
* the application needs to have a Time Client Model.
*
* @param cli_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param cli_data Pointer to the unique struct esp_ble_mesh_client_t.
*
* @return New Time Client Model instance.
*/
#define ESP_BLE_MESH_MODEL_TIME_CLI(cli_pub, cli_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_TIME_CLI, \
NULL, cli_pub, cli_data)
/** @def ESP_BLE_MESH_MODEL_SCENE_CLI
*
* @brief Define a new Scene Client Model.
*
* @note This API needs to be called for each element on which
* the application needs to have a Scene Client Model.
*
* @param cli_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param cli_data Pointer to the unique struct esp_ble_mesh_client_t.
*
* @return New Scene Client Model instance.
*/
#define ESP_BLE_MESH_MODEL_SCENE_CLI(cli_pub, cli_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCENE_CLI, \
NULL, cli_pub, cli_data)
/** @def ESP_BLE_MESH_MODEL_SCHEDULER_CLI
*
* @brief Define a new Scheduler Client Model.
*
* @note This API needs to be called for each element on which
* the application needs to have a Scheduler Client Model.
*
* @param cli_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param cli_data Pointer to the unique struct esp_ble_mesh_client_t.
*
* @return New Scheduler Client Model instance.
*/
#define ESP_BLE_MESH_MODEL_SCHEDULER_CLI(cli_pub, cli_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCHEDULER_CLI, \
NULL, cli_pub, cli_data)
/**
* @brief Bluetooth Mesh Time Scene Client Model Get and Set parameters structure.
*/
/** Parameters of Time Set */
typedef struct {
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t sub_second; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_time_set_t;
/** Parameters of Time Zone Set */
typedef struct {
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
} esp_ble_mesh_time_zone_set_t;
/** Parameters of TAI-UTC Delta Set */
typedef struct {
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
uint16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
} esp_ble_mesh_tai_utc_delta_set_t;
/** Parameter of Time Role Set */
typedef struct {
uint8_t time_role; /*!< The Time Role for the element */
} esp_ble_mesh_time_role_set_t;
/** Parameter of Scene Store */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be stored */
} esp_ble_mesh_scene_store_t;
/** Parameters of Scene Recall */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t scene_number; /*!< The number of scenes to be recalled */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_scene_recall_t;
/** Parameter of Scene Delete */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be deleted */
} esp_ble_mesh_scene_delete_t;
/** Parameter of Scheduler Action Get */
typedef struct {
uint8_t index; /*!< Index of the Schedule Register entry to get */
} esp_ble_mesh_scheduler_act_get_t;
/** Parameters of Scheduler Action Set */
typedef struct {
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
uint64_t year : 7; /*!< Scheduled year for the action */
uint64_t month : 12; /*!< Scheduled month for the action */
uint64_t day : 5; /*!< Scheduled day of the month for the action */
uint64_t hour : 5; /*!< Scheduled hour for the action */
uint64_t minute : 6; /*!< Scheduled minute for the action */
uint64_t second : 6; /*!< Scheduled second for the action */
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
uint64_t trans_time : 8; /*!< Transition time for this action */
uint16_t scene_number; /*!< Transition time for this action */
} esp_ble_mesh_scheduler_act_set_t;
/**
* @brief Time Scene Client Model get message union
*/
typedef union {
esp_ble_mesh_scheduler_act_get_t scheduler_act_get; /*!< For ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET */
} esp_ble_mesh_time_scene_client_get_state_t;
/**
* @brief Time Scene Client Model set message union
*/
typedef union {
esp_ble_mesh_time_set_t time_set; /*!< For ESP_BLE_MESH_MODEL_OP_TIME_SET */
esp_ble_mesh_time_zone_set_t time_zone_set; /*!< For ESP_BLE_MESH_MODEL_OP_TIME_ZONE_SET */
esp_ble_mesh_tai_utc_delta_set_t tai_utc_delta_set; /*!< For ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET */
esp_ble_mesh_time_role_set_t time_role_set; /*!< For ESP_BLE_MESH_MODEL_OP_TIME_ROLE_SET */
esp_ble_mesh_scene_store_t scene_store; /*!< For ESP_BLE_MESH_MODEL_OP_SCENE_STORE & ESP_BLE_MESH_MODEL_OP_SCENE_STORE_UNACK */
esp_ble_mesh_scene_recall_t scene_recall; /*!< For ESP_BLE_MESH_MODEL_OP_SCENE_RECALL & ESP_BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK */
esp_ble_mesh_scene_delete_t scene_delete; /*!< For ESP_BLE_MESH_MODEL_OP_SCENE_DELETE & ESP_BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK */
esp_ble_mesh_scheduler_act_set_t scheduler_act_set; /*!< For ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET & ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK */
} esp_ble_mesh_time_scene_client_set_state_t;
/**
* @brief Bluetooth Mesh Time Scene Client Model Get and Set callback parameters structure.
*/
/** Parameters of Time Status */
typedef struct {
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t sub_second; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_time_status_cb_t;
/** Parameters of Time Zone Status */
typedef struct {
uint8_t time_zone_offset_curr; /*!< Current local time zone offset */
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
} esp_ble_mesh_time_zone_status_cb_t;
/** Parameters of TAI-UTC Delta Status */
typedef struct {
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
uint16_t padding_1 : 1; /*!< Always 0b0. Other values are Prohibited. */
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
uint16_t padding_2 : 1; /*!< Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
} esp_ble_mesh_tai_utc_delta_status_cb_t;
/** Parameter of Time Role Status */
typedef struct {
uint8_t time_role; /*!< The Time Role for the element */
} esp_ble_mesh_time_role_status_cb_t;
/** Parameters of Scene Status */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint8_t status_code; /*!< Status code of the last operation */
uint16_t current_scene; /*!< Scene Number of the current scene */
uint16_t target_scene; /*!< Scene Number of the target scene (optional) */
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
} esp_ble_mesh_scene_status_cb_t;
/** Parameters of Scene Register Status */
typedef struct {
uint8_t status_code; /*!< Status code for the previous operation */
uint16_t current_scene; /*!< Scene Number of the current scene */
struct net_buf_simple *scenes; /*!< A list of scenes stored within an element */
} esp_ble_mesh_scene_register_status_cb_t;
/** Parameter of Scheduler Status */
typedef struct {
uint16_t schedules; /*!< Bit field indicating defined Actions in the Schedule Register */
} esp_ble_mesh_scheduler_status_cb_t;
/** Parameters of Scheduler Action Status */
typedef struct {
uint64_t index : 4; /*!< Enumerates (selects) a Schedule Register entry */
uint64_t year : 7; /*!< Scheduled year for the action */
uint64_t month : 12; /*!< Scheduled month for the action */
uint64_t day : 5; /*!< Scheduled day of the month for the action */
uint64_t hour : 5; /*!< Scheduled hour for the action */
uint64_t minute : 6; /*!< Scheduled minute for the action */
uint64_t second : 6; /*!< Scheduled second for the action */
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
uint64_t trans_time : 8; /*!< Transition time for this action */
uint16_t scene_number; /*!< Transition time for this action */
} esp_ble_mesh_scheduler_act_status_cb_t;
/**
* @brief Time Scene Client Model received message union
*/
typedef union {
esp_ble_mesh_time_status_cb_t time_status; /*!< For ESP_BLE_MESH_MODEL_OP_TIME_STATUS */
esp_ble_mesh_time_zone_status_cb_t time_zone_status; /*!< For ESP_BLE_MESH_MODEL_OP_TIME_ZONE_STATUS */
esp_ble_mesh_tai_utc_delta_status_cb_t tai_utc_delta_status; /*!< For ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS */
esp_ble_mesh_time_role_status_cb_t time_role_status; /*!< For ESP_BLE_MESH_MODEL_OP_TIME_ROLE_STATUS */
esp_ble_mesh_scene_status_cb_t scene_status; /*!< For ESP_BLE_MESH_MODEL_OP_SCENE_STATUS */
esp_ble_mesh_scene_register_status_cb_t scene_register_status; /*!< For ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS */
esp_ble_mesh_scheduler_status_cb_t scheduler_status; /*!< For ESP_BLE_MESH_MODEL_OP_SCHEDULER_STATUS */
esp_ble_mesh_scheduler_act_status_cb_t scheduler_act_status; /*!< For ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS */
} esp_ble_mesh_time_scene_client_status_cb_t;
/** Time Scene Client Model callback parameters */
typedef struct {
int error_code; /*!< Appropriate error code */
esp_ble_mesh_client_common_param_t *params; /*!< The client common parameters. */
esp_ble_mesh_time_scene_client_status_cb_t status_cb; /*!< The scene status message callback values */
} esp_ble_mesh_time_scene_client_cb_param_t;
/** This enum value is the event of Time Scene Client Model */
typedef enum {
ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT,
ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT,
ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT,
ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT,
ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX,
} esp_ble_mesh_time_scene_client_cb_event_t;
/**
* @brief Bluetooth Mesh Time Scene Client Model function.
*/
/**
* @brief Time Scene Client Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_time_scene_client_cb_t)(esp_ble_mesh_time_scene_client_cb_event_t event,
esp_ble_mesh_time_scene_client_cb_param_t *param);
/**
* @brief Register BLE Mesh Time Scene Client Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_t callback);
/**
* @brief Get the value of Time Scene Server Model states using the Time Scene Client Model get messages.
*
* @note If you want to know the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_time_scene_message_opcode_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] get_state: Pointer to time scene get message value.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*/
esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_time_scene_client_get_state_t *get_state);
/**
* @brief Set the value of Time Scene Server Model states using the Time Scene Client Model set messages.
*
* @note If you want to know the opcodes and corresponding meanings accepted by this API,
* please refer to esp_ble_mesh_time_scene_message_opcode_t in esp_ble_mesh_defs.h
*
* @param[in] params: Pointer to BLE Mesh common client parameters.
* @param[in] set_state: Pointer to time scene set message value.
* Shall not be set to NULL.
*
* @return ESP_OK on success or error code otherwise.
*/
esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_time_scene_client_set_state_t *set_state);
/**
* @brief Time Scene Server Models related context.
*/
/** @def ESP_BLE_MESH_MODEL_TIME_SRV
*
* @brief Define a new Time Server Model.
*
* @note 1. The Time Server model is a root model. When this model is present on an
* Element, the corresponding Time Setup Server model shall also be present.
* 2. This model shall support model publication and model subscription.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_time_srv_t.
*
* @return New Time Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_TIME_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_TIME_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_TIME_SETUP_SRV
*
* @brief Define a new Time Setup Server Model.
*
* @note 1. The Time Setup Server model extends the Time Server model. Time is
* sensitive information that is propagated across a mesh network.
* 2. Only an authorized Time Client should be allowed to change the Time
* and Time Role states. A dedicated application key Bluetooth SIG
* Proprietary should be used on the Time Setup Server to restrict
* access to the server to only authorized Time Clients.
* 3. This model does not support subscribing nor publishing.
*
* @param srv_data Pointer to the unique struct esp_ble_mesh_time_setup_srv_t.
*
* @return New Time Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_TIME_SETUP_SRV(srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_TIME_SETUP_SRV, \
NULL, NULL, srv_data)
/** @def ESP_BLE_MESH_MODEL_SCENE_SRV
*
* @brief Define a new Scene Server Model.
*
* @note 1. The Scene Server model is a root model. When this model is present
* on an Element, the corresponding Scene Setup Server model shall
* also be present.
* 2. This model shall support model publication and model subscription.
* 3. The model may be present only on the Primary element of a node.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_scene_srv_t.
*
* @return New Scene Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SCENE_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCENE_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_SCENE_SETUP_SRV
*
* @brief Define a new Scene Setup Server Model.
*
* @note 1. The Scene Setup Server model extends the Scene Server model and
* the Generic Default Transition Time Server model.
* 2. This model shall support model subscription.
* 3. The model may be present only on the Primary element of a node.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_scene_setup_srv_t.
*
* @return New Scene Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SCENE_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_SCHEDULER_SRV
*
* @brief Define a new Scheduler Server Model.
*
* @note 1. The Scheduler Server model extends the Scene Server model. When
* this model is present on an Element, the corresponding Scheduler
* Setup Server model shall also be present.
* 2. This model shall support model publication and model subscription.
* 3. The model may be present only on the Primary element of a node.
* 4. The model requires the Time Server model shall be present on the element.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_scheduler_srv_t.
*
* @return New Scheduler Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SCHEDULER_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCHEDULER_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_SCHEDULER_SETUP_SRV
*
* @brief Define a new Scheduler Setup Server Model.
*
* @note 1. The Scheduler Setup Server model extends the Scheduler Server and
* the Scene Setup Server models.
* 2. This model shall support model subscription.
* 3. The model may be present only on the Primary element of a node.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_scheduler_setup_srv_t.
*
* @return New Scheduler Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SCHEDULER_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, \
NULL, srv_pub, srv_data)
#define ESP_BLE_MESH_UNKNOWN_TAI_SECONDS 0x0000000000 /*!< Unknown TAI Seconds */
#define ESP_BLE_MESH_UNKNOWN_TAI_ZONE_CHANGE 0x0000000000 /*!< Unknown TAI of Zone Change */
#define ESP_BLE_MESH_UNKNOWN_TAI_DELTA_CHANGE 0x0000000000 /*!< Unknown TAI of Delta Change */
#define ESP_BLE_MESH_TAI_UTC_DELTA_MAX_VALUE 0x7FFF /*!< Maximum TAI-UTC Delta value */
#define ESP_BLE_MESH_TAI_SECONDS_LEN 0x05 /*!< Length of TAI Seconds */
#define ESP_BLE_MESH_TAI_OF_ZONE_CHANGE_LEN 0x05 /*!< Length of TAI of Zone Change */
#define ESP_BLE_MESH_TAI_OF_DELTA_CHANGE_LEN 0x05 /*!< Length of TAI of Delta Change */
#define ESP_BLE_MESH_INVALID_SCENE_NUMBER 0x0000 /*!< Invalid Scene Number */
#define ESP_BLE_MESH_SCENE_NUMBER_LEN 0x02 /*!< Length of the Scene Number */
#define ESP_BLE_MESH_SCHEDULE_YEAR_ANY_YEAR 0x64 /*!< Any year of the Scheduled year */
#define ESP_BLE_MESH_SCHEDULE_DAY_ANY_DAY 0x00 /*!< Any day of the Scheduled day */
#define ESP_BLE_MESH_SCHEDULE_HOUR_ANY_HOUR 0x18 /*!< Any hour of the Scheduled hour */
#define ESP_BLE_MESH_SCHEDULE_HOUR_ONCE_A_DAY 0x19 /*!< Any hour of the Scheduled Day */
#define ESP_BLE_MESH_SCHEDULE_SEC_ANY_OF_HOUR 0x3C /*!< Any minute of the Scheduled hour */
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_15_MIN 0x3D /*!< Every 15 minutes of the Scheduled hour */
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_20_MIN 0x3E /*!< Every 20 minutes of the Scheduled hour */
#define ESP_BLE_MESH_SCHEDULE_SEC_ONCE_AN_HOUR 0x3F /*!< Once of the Scheduled hour */
#define ESP_BLE_MESH_SCHEDULE_SEC_ANY_OF_MIN 0x3C /*!< Any second of the Scheduled minute */
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_15_SEC 0x3D /*!< Every 15 seconds of the Scheduled minute */
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_20_SEC 0x3E /*!< Every 20 seconds of the Scheduled minute */
#define ESP_BLE_MESH_SCHEDULE_SEC_ONCE_AN_MIN 0x3F /*!< Once of the Scheduled minute */
#define ESP_BLE_MESH_SCHEDULE_ACT_TURN_OFF 0x00 /*!< Scheduled Action - Turn Off */
#define ESP_BLE_MESH_SCHEDULE_ACT_TURN_ON 0x01 /*!< Scheduled Action - Turn On */
#define ESP_BLE_MESH_SCHEDULE_ACT_SCENE_RECALL 0x02 /*!< Scheduled Action - Scene Recall */
#define ESP_BLE_MESH_SCHEDULE_ACT_NO_ACTION 0x0F /*!< Scheduled Action - No Action */
#define ESP_BLE_MESH_SCHEDULE_SCENE_NO_SCENE 0x0000 /*!< Scheduled Scene - No Scene */
#define ESP_BLE_MESH_SCHEDULE_ENTRY_MAX_INDEX 0x0F /*!< Maximum number of Scheduled entries */
#define ESP_BLE_MESH_TIME_NONE 0x00 /*!< Time Role - None */
#define ESP_BLE_MESH_TIME_AUTHORITY 0x01 /*!< Time Role - Mesh Time Authority */
#define ESP_BLE_MESH_TIME_RELAY 0x02 /*!< Time Role - Mesh Time Relay */
#define ESP_BLE_MESH_TIME_CLINET 0x03 /*!< Time Role - Mesh Time Client */
#define ESP_BLE_MESH_SCENE_SUCCESS 0x00 /*!< Scene operation - Success */
#define ESP_BLE_MESH_SCENE_REG_FULL 0x01 /*!< Scene operation - Scene Register Full */
#define ESP_BLE_MESH_SCENE_NOT_FOUND 0x02 /*!< Scene operation - Scene Not Found */
/** Parameters of Time state */
typedef struct {
struct {
uint8_t tai_seconds[5]; /*!< The value of the TAI Seconds state */
uint8_t subsecond; /*!< The value of the Subsecond field */
uint8_t uncertainty; /*!< The value of the Uncertainty field */
uint8_t time_zone_offset_curr; /*!< The value of the Time Zone Offset Current field */
uint8_t time_zone_offset_new; /*!< The value of the Time Zone Offset New state */
uint8_t tai_zone_change[5]; /*!< The value of the TAI of Zone Chaneg field */
uint16_t time_authority : 1, /*!< The value of the Time Authority bit */
tai_utc_delta_curr : 15; /*!< The value of the TAI-UTC Delta Current state */
uint16_t tai_utc_delta_new : 15; /*!< The value of the TAI-UTC Delta New state */
uint8_t tai_delta_change[5]; /*!< The value of the TAI of Delta Change field */
} time; /*!< Parameters of the Time state */
uint8_t time_role; /*!< The value of the Time Role state */
} esp_ble_mesh_time_state_t;
/** User data of Time Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Time Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_time_state_t *state; /*!< Parameters of the Time state */
} esp_ble_mesh_time_srv_t;
/** User data of Time Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Time Setup Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_time_state_t *state; /*!< Parameters of the Time state */
} esp_ble_mesh_time_setup_srv_t;
/**
* 1. Scene Store is an operation of storing values of a present state of an element.
* 2. The structure and meaning of the stored state is determined by a model. States
* to be stored are specified by each model.
* 3. The Scene Store operation shall persistently store all values of all states
* marked as Stored with Scene for all models present on all elements of a node.
* 4. If a model is extending another model, the extending model shall determine the
* Stored with Scene behavior of that model.
*/
/** Parameters of Scene Register state */
typedef struct {
uint16_t scene_number; /*!< The value of the Scene Number */
uint8_t scene_type; /*!< The value of the Scene Type */
/**
* Scene value may use a union to represent later, the union contains
* structures of all the model states which can be stored in a scene.
*/
struct net_buf_simple *scene_value; /*!< The value of the Scene Value */
} esp_ble_mesh_scene_register_t;
/**
* Parameters of Scenes state.
*
* Scenes serve as memory banks for storage of states (e.g., a power level
* or a light level/color). Values of states of an element can be stored
* as a scene and can be recalled later from the scene memory.
*
* A scene is represented by a Scene Number, which is a 16-bit non-zero,
* mesh-wide value. (There can be a maximum of 65535 scenes in a mesh
* network.) The meaning of a scene, as well as the state storage container
* associated with it, are determined by a model.
*
* The Scenes state change may start numerous parallel model transitions.
* In that case, each individual model handles the transition internally.
*
* The scene transition is defined as a group of individual model transitions
* started by a Scene Recall operation. The scene transition is in progress
* when at least one transition from the group of individual model transitions
* is in progress.
*/
typedef struct {
const uint16_t scene_count; /*!< The Scenes state's scene count */
esp_ble_mesh_scene_register_t *scenes; /*!< Parameters of the Scenes state */
/**
* The Current Scene state is a 16-bit value that contains either the Scene
* Number of the currently active scene or a value of 0x0000 when no scene
* is active.
*
* When a Scene Store operation or a Scene Recall operation completes with
* success, the Current Scene state value shall be to the Scene Number used
* during that operation.
*
* When the Current Scene Number is deleted from a Scene Register state as a
* result of Scene Delete operation, the Current Scene state shall be set to
* 0x0000.
*
* When any of the element's state that is marked as “Stored with Scene” has
* changed not as a result of a Scene Recall operation, the value of the
* Current Scene state shall be set to 0x0000.
*
* When a scene transition is in progress, the value of the Current Scene
* state shall be set to 0x0000.
*/
uint16_t current_scene; /*!< The value of the Current Scene state */
/**
* The Target Scene state is a 16-bit value that contains the target Scene
* Number when a scene transition is in progress.
*
* When the scene transition is in progress and the target Scene Number is
* deleted from a Scene Register state as a result of Scene Delete operation,
* the Target Scene state shall be set to 0x0000.
*
* When the scene transition is in progress and a new Scene Number is stored
* in the Scene Register as a result of Scene Store operation, the Target
* Scene state shall be set to the new Scene Number.
*
* When the scene transition is not in progress, the value of the Target Scene
* state shall be set to 0x0000.
*/
uint16_t target_scene; /*!< The value of the Target Scene state */
/* Indicate the status code for the last operation */
uint8_t status_code; /*!< The status code of the last scene operation */
/* Indicate if scene transition is in progress */
bool in_progress; /*!< Indicate if the scene transition is in progress */
} esp_ble_mesh_scenes_state_t;
/** User data of Scene Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Scene Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_scenes_state_t *state; /*!< Parameters of the Scenes state */
esp_ble_mesh_last_msg_info_t last; /*!< Parameters of the last received set message */
esp_ble_mesh_state_transition_t transition; /*!< Parameters of state transition */
} esp_ble_mesh_scene_srv_t;
/** User data of Scene Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Scene Setup Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_scenes_state_t *state; /*!< Parameters of the Scenes state */
} esp_ble_mesh_scene_setup_srv_t;
/** Parameters of Scheduler Register state */
typedef struct {
bool in_use; /*!< Indicate if the registered schedule is in use */
uint64_t year : 7, /*!< The value of Scheduled year for the action */
month : 12, /*!< The value of Scheduled month for the action */
day : 5, /*!< The value of Scheduled day of the month for the action */
hour : 5, /*!< The value of Scheduled hour for the action */
minute : 6, /*!< The value of Scheduled minute for the action */
second : 6, /*!< The value of Scheduled second for the action */
day_of_week : 7, /*!< The value of Schedule days of the week for the action */
action : 4, /*!< The value of Action to be performed at the scheduled time */
trans_time : 8; /*!< The value of Transition time for this action */
uint16_t scene_number; /*!< The value of Scene Number to be used for some actions */
} esp_ble_mesh_schedule_register_t;
/** Parameters of Scheduler state */
typedef struct {
const uint8_t schedule_count; /*!< Scheduler count */
esp_ble_mesh_schedule_register_t *schedules; /*!< Up to 16 scheduled entries */
} esp_ble_mesh_scheduler_state_t;
/** User data of Scheduler Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Scheduler Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_scheduler_state_t *state; /*!< Parameters of the Scheduler state */
} esp_ble_mesh_scheduler_srv_t;
/** User data of Scheduler Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Scheduler Setup Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_scheduler_state_t *state; /*!< Parameters of the Scheduler state */
} esp_ble_mesh_scheduler_setup_srv_t;
/** Parameters of Time Set state change event */
typedef struct {
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset_curr; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_state_change_time_set_t;
/** Parameters of Time Status state change event */
typedef struct {
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset_curr; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_state_change_time_status_t;
/** Parameters of Time Zone Set state change event */
typedef struct {
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
} esp_ble_mesh_state_change_time_zone_set_t;
/** Parameters of TAI UTC Delta Set state change event */
typedef struct {
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
} esp_ble_mesh_state_change_tai_utc_delta_set_t;
/** Parameter of Time Role Set state change event */
typedef struct {
uint8_t time_role; /*!< The Time Role for the element */
} esp_ble_mesh_state_change_time_role_set_t;
/** Parameter of Scene Store state change event */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be stored */
} esp_ble_mesh_state_change_scene_store_t;
/** Parameter of Scene Recall state change event */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be recalled */
} esp_ble_mesh_state_change_scene_recall_t;
/** Parameter of Scene Delete state change event */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be deleted */
} esp_ble_mesh_state_change_scene_delete_t;
/** Parameter of Scheduler Action Set state change event */
typedef struct {
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
uint64_t year : 7; /*!< Scheduled year for the action */
uint64_t month : 12; /*!< Scheduled month for the action */
uint64_t day : 5; /*!< Scheduled day of the month for the action */
uint64_t hour : 5; /*!< Scheduled hour for the action */
uint64_t minute : 6; /*!< Scheduled minute for the action */
uint64_t second : 6; /*!< Scheduled second for the action */
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
uint64_t trans_time : 8; /*!< Transition time for this action */
uint16_t scene_number; /*!< Scene number to be used for some actions */
} esp_ble_mesh_state_change_scheduler_act_set_t;
/**
* @brief Time Scene Server Model state change value union
*/
typedef union {
/**
* The recv_op in ctx can be used to decide which state is changed.
*/
esp_ble_mesh_state_change_time_set_t time_set; /*!< Time Set */
esp_ble_mesh_state_change_time_status_t time_status; /*!< Time Status */
esp_ble_mesh_state_change_time_zone_set_t time_zone_set; /*!< Time Zone Set */
esp_ble_mesh_state_change_tai_utc_delta_set_t tai_utc_delta_set; /*!< TAI UTC Delta Set */
esp_ble_mesh_state_change_time_role_set_t time_role_set; /*!< Time Role Set */
esp_ble_mesh_state_change_scene_store_t scene_store; /*!< Scene Store */
esp_ble_mesh_state_change_scene_recall_t scene_recall; /*!< Scene Recall */
esp_ble_mesh_state_change_scene_delete_t scene_delete; /*!< Scene Delete */
esp_ble_mesh_state_change_scheduler_act_set_t scheduler_act_set; /*!< Scheduler Action Set */
} esp_ble_mesh_time_scene_server_state_change_t;
/** Context of the received Scheduler Action Get message */
typedef struct {
uint8_t index; /*!< Index of the Schedule Register entry to get */
} esp_ble_mesh_server_recv_scheduler_act_get_t;
/**
* @brief Time Scene Server Model received get message union
*/
typedef union {
esp_ble_mesh_server_recv_scheduler_act_get_t scheduler_act; /*!< Scheduler Action Get */
} esp_ble_mesh_time_scene_server_recv_get_msg_t;
/** Context of the received Time Set message */
typedef struct {
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_server_recv_time_set_t;
/** Context of the received Time Zone Set message */
typedef struct {
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
} esp_ble_mesh_server_recv_time_zone_set_t;
/** Context of the received TAI UTC Delta Set message */
typedef struct {
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
uint16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
} esp_ble_mesh_server_recv_tai_utc_delta_set_t;
/** Context of the received Time Role Set message */
typedef struct {
uint8_t time_role; /*!< The Time Role for the element */
} esp_ble_mesh_server_recv_time_role_set_t;
/** Context of the received Scene Store message */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be stored */
} esp_ble_mesh_server_recv_scene_store_t;
/** Context of the received Scene Recall message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t scene_number; /*!< The number of scenes to be recalled */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
uint8_t delay; /*!< Indicate message execution delay (C.1) */
} esp_ble_mesh_server_recv_scene_recall_t;
/** Context of the received Scene Delete message */
typedef struct {
uint16_t scene_number; /*!< The number of scenes to be deleted */
} esp_ble_mesh_server_recv_scene_delete_t;
/** Context of the received Scheduler Action Set message */
typedef struct {
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
uint64_t year : 7; /*!< Scheduled year for the action */
uint64_t month : 12; /*!< Scheduled month for the action */
uint64_t day : 5; /*!< Scheduled day of the month for the action */
uint64_t hour : 5; /*!< Scheduled hour for the action */
uint64_t minute : 6; /*!< Scheduled minute for the action */
uint64_t second : 6; /*!< Scheduled second for the action */
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
uint64_t trans_time : 8; /*!< Transition time for this action */
uint16_t scene_number; /*!< Scene number to be used for some actions */
} esp_ble_mesh_server_recv_scheduler_act_set_t;
/**
* @brief Time Scene Server Model received set message union
*/
typedef union {
esp_ble_mesh_server_recv_time_set_t time; /*!< Time Set */
esp_ble_mesh_server_recv_time_zone_set_t time_zone; /*!< Time Zone Set */
esp_ble_mesh_server_recv_tai_utc_delta_set_t tai_utc_delta; /*!< TAI-UTC Delta Set */
esp_ble_mesh_server_recv_time_role_set_t time_role; /*!< Time Role Set */
esp_ble_mesh_server_recv_scene_store_t scene_store; /*!< Scene Store/Scene Store Unack */
esp_ble_mesh_server_recv_scene_recall_t scene_recall; /*!< Scene Recall/Scene Recall Unack */
esp_ble_mesh_server_recv_scene_delete_t scene_delete; /*!< Scene Delete/Scene Delete Unack */
esp_ble_mesh_server_recv_scheduler_act_set_t scheduler_act; /*!< Scheduler Action Set/Scheduler Action Set Unack */
} esp_ble_mesh_time_scene_server_recv_set_msg_t;
/** Context of the received Time Status message */
typedef struct {
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
} esp_ble_mesh_server_recv_time_status_t;
/**
* @brief Time Scene Server Model received status message union
*/
typedef union {
esp_ble_mesh_server_recv_time_status_t time_status; /*!< Time Status */
} esp_ble_mesh_time_scene_server_recv_status_msg_t;
/**
* @brief Time Scene Server Model callback value union
*/
typedef union {
esp_ble_mesh_time_scene_server_state_change_t state_change; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT */
esp_ble_mesh_time_scene_server_recv_get_msg_t get; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT */
esp_ble_mesh_time_scene_server_recv_set_msg_t set; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT */
esp_ble_mesh_time_scene_server_recv_status_msg_t status; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT */
} esp_ble_mesh_time_scene_server_cb_value_t;
/** Time Scene Server Model callback parameters */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to Time and Scenes Server Models */
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received messages */
esp_ble_mesh_time_scene_server_cb_value_t value; /*!< Value of the received Time and Scenes Messages */
} esp_ble_mesh_time_scene_server_cb_param_t;
/** This enum value is the event of Time Scene Server Model */
typedef enum {
/**
* 1. When get_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, no event will be
* callback to the application layer when Time Scene Get messages are received.
* 2. When set_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, this event will
* be callback to the application layer when Time Scene Set/Set Unack messages
* are received.
*/
ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT,
/**
* When get_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
* callback to the application layer when Time Scene Get messages are received.
*/
ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT,
/**
* When set_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
* callback to the application layer when Time Scene Set/Set Unack messages are received.
*/
ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT,
/**
* When status_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will
* be callback to the application layer when TIme Status message is received.
*/
ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT,
ESP_BLE_MESH_TIME_SCENE_SERVER_EVT_MAX,
} esp_ble_mesh_time_scene_server_cb_event_t;
/**
* @brief Bluetooth Mesh Time and Scenes Server Model function.
*/
/**
* @brief Time Scene Server Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_time_scene_server_cb_t)(esp_ble_mesh_time_scene_server_cb_event_t event,
esp_ble_mesh_time_scene_server_cb_param_t *param);
/**
* @brief Register BLE Mesh Time and Scenes Server Model callback.
*
* @param[in] callback: Pointer to the callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_t callback);
#ifdef __cplusplus
}
#endif
#endif /* _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_ */

View File

@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_BLE_H_
#define _BTC_BLE_MESH_BLE_H_
#include <stdint.h>
#include "btc/btc_manage.h"
#include "mesh_bearer_adapt.h"
#include "esp_ble_mesh_ble_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef union {
struct {
esp_ble_mesh_ble_adv_param_t param;
esp_ble_mesh_ble_adv_data_t data;
} start_ble_adv;
struct {
uint8_t index;
} stop_ble_adv;
struct {
esp_ble_mesh_ble_scan_param_t param;
} start_ble_scan;
struct {
/* RFU */
} stop_ble_scan;
} btc_ble_mesh_ble_args_t;
typedef enum {
BTC_BLE_MESH_ACT_START_BLE_ADV,
BTC_BLE_MESH_ACT_STOP_BLE_ADV,
BTC_BLE_MESH_ACT_START_BLE_SCAN,
BTC_BLE_MESH_ACT_STOP_BLE_SCAN,
} btc_ble_mesh_ble_act_t;
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi);
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg);
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_BLE_H_ */

View File

@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_CONFIG_MODEL_H_
#define _BTC_BLE_MESH_CONFIG_MODEL_H_
#include "btc/btc_manage.h"
#include "esp_ble_mesh_config_model_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_CONFIG_CLIENT_MAX,
} btc_ble_mesh_config_client_act_t;
typedef union {
struct ble_mesh_cfg_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_cfg_client_get_state_t *get_state;
} cfg_client_get_state;
struct ble_mesh_cfg_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_cfg_client_set_state_t *set_state;
} cfg_client_set_state;
} btc_ble_mesh_config_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_MAX,
} btc_ble_mesh_config_client_evt_t;
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX,
} btc_ble_mesh_config_server_evt_t;
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_CONFIG_MODEL_H_ */

View File

@ -0,0 +1,74 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_GENERIC_MODEL_H_
#define _BTC_BLE_MESH_GENERIC_MODEL_H_
#include "btc/btc_manage.h"
#include "esp_ble_mesh_generic_model_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_GENERIC_CLIENT_MAX,
} btc_ble_mesh_generic_client_act_t;
typedef union {
struct ble_mesh_generic_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_generic_client_get_state_t *get_state;
} generic_client_get_state;
struct ble_mesh_generic_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_generic_client_set_state_t *set_state;
} generic_client_set_state;
} btc_ble_mesh_generic_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_MAX,
} btc_ble_mesh_generic_client_evt_t;
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_generic_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
typedef enum {
BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE,
BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_GET_MSG,
BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_SET_MSG,
BTC_BLE_MESH_EVT_GENERIC_SERVER_MAX,
} btc_ble_mesh_generic_server_evt_t;
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_GENERIC_MODEL_H_ */

View File

@ -0,0 +1,87 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_HEALTH_MODEL_H_
#define _BTC_BLE_MESH_HEALTH_MODEL_H_
#include "btc/btc_manage.h"
#include "esp_ble_mesh_health_model_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_HEALTH_CLIENT_MAX,
} btc_ble_mesh_health_client_act_t;
typedef union {
struct ble_mesh_health_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_health_client_get_state_t *get_state;
} health_client_get_state;
struct ble_mesh_health_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_health_client_set_state_t *set_state;
} health_client_set_state;
} btc_ble_mesh_health_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_MAX,
} btc_ble_mesh_health_client_evt_t;
void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_health_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_health_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, uint16_t len);
typedef enum {
BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE,
BTC_BLE_MESH_ACT_HEALTH_SERVER_MAX,
} btc_ble_mesh_health_server_act_t;
typedef union {
struct ble_mesh_health_server_fault_update_args {
esp_ble_mesh_elem_t *element;
} health_fault_update;
} btc_ble_mesh_health_server_args_t;
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg);
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, uint16_t company_id);
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model,
uint8_t test_id, uint16_t company_id);
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, uint8_t time);
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_HEALTH_MODEL_H_ */

View File

@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_LIGHTING_MODEL_H_
#define _BTC_BLE_MESH_LIGHTING_MODEL_H_
#include "btc/btc_manage.h"
#include "esp_ble_mesh_lighting_model_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_MAX,
} btc_ble_mesh_lighting_client_act_t;
typedef union {
struct ble_mesh_light_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_light_client_get_state_t *get_state;
} light_client_get_state;
struct ble_mesh_light_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_light_client_set_state_t *set_state;
} light_client_set_state;
} btc_ble_mesh_lighting_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_MAX,
} btc_ble_mesh_lighting_client_evt_t;
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_lighting_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
typedef enum {
BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG,
BTC_BLE_MESH_EVT_LIGHTING_SERVER_MAX,
} btc_ble_mesh_lighting_server_evt_t;
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_LIGHTING_MODEL_H_ */

View File

@ -0,0 +1,392 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_PROV_H_
#define _BTC_BLE_MESH_PROV_H_
#include "btc/btc_manage.h"
#include "mesh_byteorder.h"
#include "mesh_config.h"
#include "mesh_main.h"
#include "fast_prov.h"
#include "provisioner_prov.h"
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_MESH_INIT = 0,
BTC_BLE_MESH_ACT_PROV_ENABLE,
BTC_BLE_MESH_ACT_PROV_DISABLE,
BTC_BLE_MESH_ACT_NODE_RESET,
BTC_BLE_MESH_ACT_SET_OOB_PUB_KEY,
BTC_BLE_MESH_ACT_INPUT_NUMBER,
BTC_BLE_MESH_ACT_INPUT_STRING,
BTC_BLE_MESH_ACT_SET_DEVICE_NAME,
BTC_BLE_MESH_ACT_PROXY_IDENTITY_ENABLE,
BTC_BLE_MESH_ACT_PROXY_GATT_ENABLE,
BTC_BLE_MESH_ACT_PROXY_GATT_DISABLE,
BTC_BLE_MESH_ACT_NODE_ADD_LOCAL_NET_KEY,
BTC_BLE_MESH_ACT_NODE_ADD_LOCAL_APP_KEY,
BTC_BLE_MESH_ACT_NODE_BIND_APP_KEY_TO_MODEL,
BTC_BLE_MESH_ACT_PROVISIONER_READ_OOB_PUB_KEY,
BTC_BLE_MESH_ACT_PROVISIONER_INPUT_STR,
BTC_BLE_MESH_ACT_PROVISIONER_INPUT_NUM,
BTC_BLE_MESH_ACT_PROVISIONER_ENABLE,
BTC_BLE_MESH_ACT_PROVISIONER_DISABLE,
BTC_BLE_MESH_ACT_PROVISIONER_DEV_ADD,
BTC_BLE_MESH_ACT_PROVISIONER_PROV_DEV_WITH_ADDR,
BTC_BLE_MESH_ACT_PROVISIONER_DEV_DEL,
BTC_BLE_MESH_ACT_PROVISIONER_SET_DEV_UUID_MATCH,
BTC_BLE_MESH_ACT_PROVISIONER_SET_PROV_DATA_INFO,
BTC_BLE_MESH_ACT_PROVISIONER_SET_STATIC_OOB_VAL,
BTC_BLE_MESH_ACT_PROVISIONER_SET_PRIMARY_ELEM_ADDR,
BTC_BLE_MESH_ACT_PROVISIONER_SET_NODE_NAME,
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_APP_KEY,
BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY,
BTC_BLE_MESH_ACT_PROVISIONER_BIND_LOCAL_MOD_APP,
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY,
BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY,
BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA,
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_UUID,
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_ADDR,
BTC_BLE_MESH_ACT_PROVISIONER_ENABLE_HEARTBEAT_RECV,
BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE,
BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_INFO,
BTC_BLE_MESH_ACT_PROVISIONER_DIRECT_ERASE_SETTINGS,
BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_INDEX,
BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_UID,
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX,
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_UID,
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_INDEX,
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_UID,
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
BTC_BLE_MESH_ACT_LPN_ENABLE,
BTC_BLE_MESH_ACT_LPN_DISABLE,
BTC_BLE_MESH_ACT_LPN_POLL,
BTC_BLE_MESH_ACT_PROXY_CLIENT_CONNECT,
BTC_BLE_MESH_ACT_PROXY_CLIENT_DISCONNECT,
BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE,
BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR,
BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR,
BTC_BLE_MESH_ACT_MODEL_SUBSCRIBE_GROUP_ADDR,
BTC_BLE_MESH_ACT_MODEL_UNSUBSCRIBE_GROUP_ADDR,
BTC_BLE_MESH_ACT_DEINIT_MESH,
} btc_ble_mesh_prov_act_t;
typedef enum {
BTC_BLE_MESH_ACT_MODEL_PUBLISH,
BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE,
} btc_ble_mesh_model_act_t;
typedef union {
struct ble_mesh_init_args {
esp_ble_mesh_prov_t *prov;
esp_ble_mesh_comp_t *comp;
SemaphoreHandle_t semaphore;
} mesh_init;
struct ble_mesh_node_prov_enable_args {
esp_ble_mesh_prov_bearer_t bearers;
} node_prov_enable;
struct ble_mesh_node_prov_disable_args {
esp_ble_mesh_prov_bearer_t bearers;
} node_prov_disable;
struct ble_mesh_set_oob_pub_key_args {
uint8_t pub_key_x[32];
uint8_t pub_key_y[32];
uint8_t private_key[32];
} set_oob_pub_key;
struct ble_mesh_node_input_num_args {
uint32_t number;
} input_number;
struct ble_mesh_node_input_str_args {
char string[8];
} input_string;
struct ble_mesh_set_device_name_args {
char name[ESP_BLE_MESH_DEVICE_NAME_MAX_LEN + 1];
} set_device_name;
struct ble_mesh_node_add_local_net_key_args {
uint8_t net_key[16];
uint16_t net_idx;
} node_add_local_net_key;
struct ble_mesh_node_add_local_app_key_args {
uint8_t app_key[16];
uint16_t net_idx;
uint16_t app_idx;
} node_add_local_app_key;
struct ble_mesh_node_bind_local_mod_app_args {
uint16_t element_addr;
uint16_t company_id;
uint16_t model_id;
uint16_t app_idx;
} node_local_mod_app_bind;
struct ble_mesh_provisioner_read_oob_pub_key_args {
uint8_t link_idx;
uint8_t pub_key_x[32];
uint8_t pub_key_y[32];
} provisioner_read_oob_pub_key;
struct ble_mesh_provisioner_input_str_args {
char string[8];
uint8_t link_idx;
} provisioner_input_str;
struct ble_mesh_provisioner_input_num_args {
uint32_t number;
uint8_t link_idx;
} provisioner_input_num;
struct ble_mesh_provisioner_enable_args {
esp_ble_mesh_prov_bearer_t bearers;
} provisioner_enable;
struct ble_mesh_provisioner_disable_args {
esp_ble_mesh_prov_bearer_t bearers;
} provisioner_disable;
struct ble_mesh_provisioner_dev_add_args {
esp_ble_mesh_unprov_dev_add_t add_dev;
esp_ble_mesh_dev_add_flag_t flags;
} provisioner_dev_add;
struct ble_mesh_provisioner_prov_dev_with_addr_args {
uint8_t uuid[16];
esp_ble_mesh_bd_addr_t addr;
esp_ble_mesh_addr_type_t addr_type;
esp_ble_mesh_prov_bearer_t bearer;
uint16_t oob_info;
uint16_t unicast_addr;
} provisioner_prov_dev_with_addr;
struct ble_mesh_provisioner_dev_del_args {
esp_ble_mesh_device_delete_t del_dev;
} provisioner_dev_del;
struct ble_mesh_provisioner_set_dev_uuid_match_args {
uint8_t offset;
uint8_t match_len;
uint8_t match_val[16];
bool prov_after_match;
} set_dev_uuid_match;
struct ble_mesh_provisioner_set_prov_net_idx_args {
esp_ble_mesh_prov_data_info_t prov_data;
} set_prov_data_info;
struct ble_mesh_provisioner_set_static_oob_val_args {
uint8_t value[16];
uint8_t length;
} set_static_oob_val;
struct ble_mesh_provisioner_set_primary_elem_addr_args {
uint16_t addr;
} set_primary_elem_addr;
struct ble_mesh_provisioner_set_node_name_args {
uint16_t index;
char name[ESP_BLE_MESH_NODE_NAME_MAX_LEN + 1];
} set_node_name;
struct ble_mesh_provisioner_add_local_app_key_args {
uint8_t app_key[16];
uint16_t net_idx;
uint16_t app_idx;
} add_local_app_key;
struct ble_mesh_provisioner_update_local_app_key_args {
uint8_t app_key[16];
uint16_t net_idx;
uint16_t app_idx;
} update_local_app_key;
struct ble_mesh_provisioner_bind_local_mod_app_args {
uint16_t elem_addr;
uint16_t model_id;
uint16_t cid;
uint16_t app_idx;
} local_mod_app_bind;
struct ble_mesh_provisioner_add_local_net_key_args {
uint8_t net_key[16];
uint16_t net_idx;
} add_local_net_key;
struct ble_mesh_provisioner_update_local_net_key_args {
uint8_t net_key[16];
uint16_t net_idx;
} update_local_net_key;
struct ble_mesh_provisioner_store_node_comp_data_args {
uint16_t unicast_addr;
uint16_t length;
uint8_t *data;
} store_node_comp_data;
struct ble_mesh_provisioner_delete_node_with_uuid_args {
uint8_t uuid[16];
} delete_node_with_uuid;
struct ble_mesh_provisioner_delete_node_with_addr_args {
uint16_t unicast_addr;
} delete_node_with_addr;
struct {
bool enable;
} enable_heartbeat_recv;
struct {
uint8_t type;
} set_heartbeat_filter_type;
struct {
uint8_t op;
uint16_t hb_src;
uint16_t hb_dst;
} set_heartbeat_filter_info;
struct {
uint8_t index;
} open_settings_with_index;
struct {
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
} open_settings_with_uid;
struct {
uint8_t index;
bool erase;
} close_settings_with_index;
struct {
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
bool erase;
} close_settings_with_uid;
struct {
uint8_t index;
} delete_settings_with_index;
struct {
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
} delete_settings_with_uid;
struct ble_mesh_set_fast_prov_info_args {
uint16_t unicast_min;
uint16_t unicast_max;
uint16_t net_idx;
uint8_t flags;
uint32_t iv_index;
uint8_t offset;
uint8_t match_len;
uint8_t match_val[16];
} set_fast_prov_info;
struct ble_mesh_set_fast_prov_action_args {
uint8_t action;
} set_fast_prov_action;
struct ble_mesh_lpn_enable_args {
/* RFU */
} lpn_enable;
struct ble_mesh_lpn_disable_args {
bool force;
} lpn_disable;
struct ble_mesh_lpn_poll_args {
/* RFU */
} lpn_poll;
struct ble_mesh_proxy_client_connect_args {
uint8_t addr[6];
uint8_t addr_type;
uint16_t net_idx;
} proxy_client_connect;
struct ble_mesh_proxy_client_disconnect_args {
uint8_t conn_handle;
} proxy_client_disconnect;
struct ble_mesh_proxy_client_set_filter_type_args {
uint8_t conn_handle;
uint16_t net_idx;
uint8_t filter_type;
} proxy_client_set_filter_type;
struct ble_mesh_proxy_client_add_filter_addr_args {
uint8_t conn_handle;
uint16_t net_idx;
uint16_t addr_num;
uint16_t *addr;
} proxy_client_add_filter_addr;
struct ble_mesh_proxy_client_remove_filter_addr_args {
uint8_t conn_handle;
uint16_t net_idx;
uint16_t addr_num;
uint16_t *addr;
} proxy_client_remove_filter_addr;
struct ble_mesh_model_sub_group_addr_args {
uint16_t element_addr;
uint16_t company_id;
uint16_t model_id;
uint16_t group_addr;
} model_sub_group_addr;
struct ble_mesh_model_unsub_group_addr_args {
uint16_t element_addr;
uint16_t company_id;
uint16_t model_id;
uint16_t group_addr;
} model_unsub_group_addr;
struct ble_mesh_deinit_args {
esp_ble_mesh_deinit_param_t param;
} mesh_deinit;
} btc_ble_mesh_prov_args_t;
typedef union {
struct ble_mesh_model_publish_args {
esp_ble_mesh_model_t *model;
uint8_t device_role;
} model_publish;
struct ble_mesh_model_send_args {
esp_ble_mesh_model_t *model;
esp_ble_mesh_msg_ctx_t *ctx;
uint32_t opcode;
bool need_rsp;
uint16_t length;
uint8_t *data;
uint8_t device_role;
int32_t msg_timeout;
} model_send;
struct ble_mesh_server_model_update_state_args {
esp_ble_mesh_model_t *model;
esp_ble_mesh_server_state_type_t type;
esp_ble_mesh_server_state_value_t *value;
} model_update_state;
} btc_ble_mesh_model_args_t;
void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
const uint8_t *btc_ble_mesh_node_get_local_net_key(uint16_t net_idx);
const uint8_t *btc_ble_mesh_node_get_local_app_key(uint16_t app_idx);
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_name(const char *name);
uint16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
const esp_ble_mesh_node_t **btc_ble_mesh_provisioner_get_node_table_entry(void);
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
int btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod);
uint16_t btc_ble_mesh_get_primary_addr(void);
uint16_t *btc_ble_mesh_model_find_group(esp_ble_mesh_model_t *mod, uint16_t addr);
esp_ble_mesh_elem_t *btc_ble_mesh_elem_find(uint16_t addr);
uint8_t btc_ble_mesh_elem_count(void);
esp_ble_mesh_model_t *btc_ble_mesh_model_find_vnd(const esp_ble_mesh_elem_t *elem,
uint16_t company, uint16_t id);
esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem, uint16_t id);
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
const char *btc_ble_mesh_provisioner_get_settings_uid(uint8_t index);
uint8_t btc_ble_mesh_provisioner_get_settings_index(const char *uid);
uint8_t btc_ble_mesh_provisioner_get_free_settings_count(void);
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_prov_call_handler(btc_msg_t *msg);
void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_PROV_H_ */

View File

@ -0,0 +1,74 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_SENSOR_MODEL_H_
#define _BTC_BLE_MESH_SENSOR_MODEL_H_
#include "btc/btc_manage.h"
#include "esp_ble_mesh_sensor_model_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_SENSOR_CLIENT_MAX,
} btc_ble_mesh_sensor_client_act_t;
typedef union {
struct ble_mesh_sensor_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_sensor_client_get_state_t *get_state;
} sensor_client_get_state;
struct ble_mesh_sensor_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_sensor_client_set_state_t *set_state;
} sensor_client_set_state;
} btc_ble_mesh_sensor_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_MAX,
} btc_ble_mesh_sensor_client_evt_t;
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_sensor_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
typedef enum {
BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE,
BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_GET_MSG,
BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_SET_MSG,
BTC_BLE_MESH_EVT_SENSOR_SERVER_MAX,
} btc_ble_mesh_sensor_server_evt_t;
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_SENSOR_MODEL_H_ */

View File

@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_TIME_SCENE_MODEL_H_
#define _BTC_BLE_MESH_TIME_SCENE_MODEL_H_
#include "btc/btc_manage.h"
#include "esp_ble_mesh_time_scene_model_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE,
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE,
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_MAX,
} btc_ble_mesh_time_scene_client_act_t;
typedef union {
struct ble_mesh_time_scene_client_get_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_time_scene_client_get_state_t *get_state;
} time_scene_client_get_state;
struct ble_mesh_time_scene_client_set_state_reg_args {
esp_ble_mesh_client_common_param_t *params;
esp_ble_mesh_time_scene_client_set_state_t *set_state;
} time_scene_client_set_state;
} btc_ble_mesh_time_scene_client_args_t;
typedef enum {
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_MAX,
} btc_ble_mesh_time_scene_client_evt_t;
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
void bt_mesh_time_scene_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
typedef enum {
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE,
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_GET_MSG,
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_SET_MSG,
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_STATUS_MSG,
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_MAX,
} btc_ble_mesh_time_scene_server_evt_t;
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ */

View File

@ -0,0 +1,305 @@
/* atomic operations */
/*
* SPDX-FileCopyrightText: 1997-2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_ATOMIC_H_
#define _BLE_MESH_ATOMIC_H_
#include "mesh_types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef bt_mesh_atomic_t bt_mesh_atomic_val_t;
/**
* @defgroup atomic_apis Atomic Services APIs
* @ingroup kernel_apis
* @{
*/
/**
*
* @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.
*/
#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN
static inline bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target)
{
return bt_mesh_atomic_add(target, 1);
}
#else
extern bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target);
#endif
/**
*
* @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.
*/
#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN
static inline bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target)
{
return bt_mesh_atomic_sub(target, 1);
}
#else
extern bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target);
#endif
/**
*
* @brief Atomic get.
*
* This routine performs an atomic read on @a target.
*
* @param target Address of atomic variable.
*
* @return Value of @a target.
*/
#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN
static inline bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target)
{
return __atomic_load_n(target, __ATOMIC_SEQ_CST);
}
#else
extern bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target);
#endif
/**
*
* @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.
*/
#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN
static inline bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_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);
}
#else
extern bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value);
#endif
/**
*
* @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.
*/
#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN
static inline bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
{
return __atomic_fetch_or(target, value, __ATOMIC_SEQ_CST);
}
#else
extern bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value);
#endif
/**
*
* @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.
*/
#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN
static inline bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
{
return __atomic_fetch_and(target, value, __ATOMIC_SEQ_CST);
}
#else
extern bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value);
#endif
/**
* @cond INTERNAL_HIDDEN
*/
#define BLE_MESH_ATOMIC_BITS (sizeof(bt_mesh_atomic_val_t) * 8)
#define BLE_MESH_ATOMIC_MASK(bit) (1 << ((bit) & (BLE_MESH_ATOMIC_BITS - 1)))
#define BLE_MESH_ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / BLE_MESH_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 BLE_MESH_ATOMIC_DEFINE(name, num_bits) \
bt_mesh_atomic_t name[1 + ((num_bits) - 1) / BLE_MESH_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 bt_mesh_atomic_test_bit(const bt_mesh_atomic_t *target, int bit)
{
bt_mesh_atomic_val_t val = bt_mesh_atomic_get(BLE_MESH_ATOMIC_ELEM(target, bit));
return (1 & (val >> (bit & (BLE_MESH_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 bt_mesh_atomic_test_and_clear_bit(bt_mesh_atomic_t *target, int bit)
{
bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit);
bt_mesh_atomic_val_t old;
old = bt_mesh_atomic_and(BLE_MESH_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 bt_mesh_atomic_test_and_set_bit(bt_mesh_atomic_t *target, int bit)
{
bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit);
bt_mesh_atomic_val_t old;
old = bt_mesh_atomic_or(BLE_MESH_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 bt_mesh_atomic_clear_bit(bt_mesh_atomic_t *target, int bit)
{
bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit);
(void)bt_mesh_atomic_and(BLE_MESH_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 bt_mesh_atomic_set_bit(bt_mesh_atomic_t *target, int bit)
{
bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit);
(void)bt_mesh_atomic_or(BLE_MESH_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 bt_mesh_atomic_set_bit_to(bt_mesh_atomic_t *target, int bit, bool val)
{
bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit);
if (val) {
(void)bt_mesh_atomic_or(BLE_MESH_ATOMIC_ELEM(target, bit), mask);
} else {
(void)bt_mesh_atomic_and(BLE_MESH_ATOMIC_ELEM(target, bit), ~mask);
}
}
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_ATOMIC_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,599 @@
/*
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_BYTEORDER_H_
#define _BLE_MESH_BYTEORDER_H_
#include "mesh_types.h"
#include "mesh_trace.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Internal helpers only used by the sys_* APIs further below */
#ifndef __bswap_16
#define __bswap_16(x) ((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
#endif
#ifndef __bswap_24
#define __bswap_24(x) ((uint32_t) ((((x) >> 16) & 0xff) | \
(((x)) & 0xff00) | \
(((x) & 0xff) << 16)))
#endif
#ifndef __bswap_32
#define __bswap_32(x) ((uint32_t) ((((x) >> 24) & 0xff) | \
(((x) >> 8) & 0xff00) | \
(((x) & 0xff00) << 8) | \
(((x) & 0xff) << 24)))
#endif
#ifndef __bswap_48
#define __bswap_48(x) ((uint64_t) ((((x) >> 40) & 0xff) | \
(((x) >> 24) & 0xff00) | \
(((x) >> 8) & 0xff0000) | \
(((x) & 0xff0000) << 8) | \
(((x) & 0xff00) << 24) | \
(((x) & 0xff) << 40)))
#endif
#ifndef __bswap_64
#define __bswap_64(x) ((uint64_t) ((((x) >> 56) & 0xff) | \
(((x) >> 40) & 0xff00) | \
(((x) >> 24) & 0xff0000) | \
(((x) >> 8) & 0xff000000) | \
(((x) & 0xff000000) << 8) | \
(((x) & 0xff0000) << 24) | \
(((x) & 0xff00) << 40) | \
(((x) & 0xff) << 56)))
#endif
/** @def sys_le16_to_cpu
* @brief Convert 16-bit integer from little-endian to host endianness.
*
* @param val 16-bit integer in little-endian format.
*
* @return 16-bit integer in host endianness.
*/
/** @def sys_cpu_to_le16
* @brief Convert 16-bit integer from host endianness to little-endian.
*
* @param val 16-bit integer in host endianness.
*
* @return 16-bit integer in little-endian format.
*/
/** @def sys_le24_to_cpu
* @brief Convert 24-bit integer from little-endian to host endianness.
*
* @param val 24-bit integer in little-endian format.
*
* @return 24-bit integer in host endianness.
*/
/** @def sys_cpu_to_le24
* @brief Convert 24-bit integer from host endianness to little-endian.
*
* @param val 24-bit integer in host endianness.
*
* @return 24-bit integer in little-endian format.
*/
/** @def sys_le32_to_cpu
* @brief Convert 32-bit integer from little-endian to host endianness.
*
* @param val 32-bit integer in little-endian format.
*
* @return 32-bit integer in host endianness.
*/
/** @def sys_cpu_to_le32
* @brief Convert 32-bit integer from host endianness to little-endian.
*
* @param val 32-bit integer in host endianness.
*
* @return 32-bit integer in little-endian format.
*/
/** @def sys_le48_to_cpu
* @brief Convert 48-bit integer from little-endian to host endianness.
*
* @param val 48-bit integer in little-endian format.
*
* @return 48-bit integer in host endianness.
*/
/** @def sys_cpu_to_le48
* @brief Convert 48-bit integer from host endianness to little-endian.
*
* @param val 48-bit integer in host endianness.
*
* @return 48-bit integer in little-endian format.
*/
/** @def sys_be16_to_cpu
* @brief Convert 16-bit integer from big-endian to host endianness.
*
* @param val 16-bit integer in big-endian format.
*
* @return 16-bit integer in host endianness.
*/
/** @def sys_cpu_to_be16
* @brief Convert 16-bit integer from host endianness to big-endian.
*
* @param val 16-bit integer in host endianness.
*
* @return 16-bit integer in big-endian format.
*/
/** @def sys_be24_to_cpu
* @brief Convert 24-bit integer from big-endian to host endianness.
*
* @param val 24-bit integer in big-endian format.
*
* @return 24-bit integer in host endianness.
*/
/** @def sys_cpu_to_be24
* @brief Convert 24-bit integer from host endianness to big-endian.
*
* @param val 24-bit integer in host endianness.
*
* @return 24-bit integer in big-endian format.
*/
/** @def sys_be32_to_cpu
* @brief Convert 32-bit integer from big-endian to host endianness.
*
* @param val 32-bit integer in big-endian format.
*
* @return 32-bit integer in host endianness.
*/
/** @def sys_cpu_to_be32
* @brief Convert 32-bit integer from host endianness to big-endian.
*
* @param val 32-bit integer in host endianness.
*
* @return 32-bit integer in big-endian format.
*/
/** @def sys_be48_to_cpu
* @brief Convert 48-bit integer from big-endian to host endianness.
*
* @param val 48-bit integer in big-endian format.
*
* @return 48-bit integer in host endianness.
*/
/** @def sys_cpu_to_be48
* @brief Convert 48-bit integer from host endianness to big-endian.
*
* @param val 48-bit integer in host endianness.
*
* @return 48-bit integer in big-endian format.
*/
#ifndef sys_le16_to_cpu
#define sys_le16_to_cpu(val) (val)
#endif
#ifndef sys_cpu_to_le16
#define sys_cpu_to_le16(val) (val)
#endif
#ifndef sys_le24_to_cpu
#define sys_le24_to_cpu(val) (val)
#endif
#ifndef sys_cpu_to_le24
#define sys_cpu_to_le24(val) (val)
#endif
#ifndef sys_le32_to_cpu
#define sys_le32_to_cpu(val) (val)
#endif
#ifndef sys_cpu_to_le32
#define sys_cpu_to_le32(val) (val)
#endif
#ifndef sys_le48_to_cpu
#define sys_le48_to_cpu(val) (val)
#endif
#ifndef sys_cpu_to_le48
#define sys_cpu_to_le48(val) (val)
#endif
#ifndef sys_le64_to_cpu
#define sys_le64_to_cpu(val) (val)
#endif
#ifndef sys_cpu_to_le64
#define sys_cpu_to_le64(val) (val)
#endif
#ifndef sys_be16_to_cpu
#define sys_be16_to_cpu(val) __bswap_16(val)
#endif
#ifndef sys_cpu_to_be16
#define sys_cpu_to_be16(val) __bswap_16(val)
#endif
#ifndef sys_be24_to_cpu
#define sys_be24_to_cpu(val) __bswap_24(val)
#endif
#ifndef sys_cpu_to_be24
#define sys_cpu_to_be24(val) __bswap_24(val)
#endif
#ifndef sys_be32_to_cpu
#define sys_be32_to_cpu(val) __bswap_32(val)
#endif
#ifndef sys_cpu_to_be32
#define sys_cpu_to_be32(val) __bswap_32(val)
#endif
#ifndef sys_be48_to_cpu
#define sys_be48_to_cpu(val) __bswap_48(val)
#endif
#ifndef sys_cpu_to_be48
#define sys_cpu_to_be48(val) __bswap_48(val)
#endif
#ifndef sys_be64_to_cpu
#define sys_be64_to_cpu(val) __bswap_64(val)
#endif
#ifndef sys_cpu_to_be64
#define sys_cpu_to_be64(val) __bswap_64(val)
#endif
/**
* @brief Put a 16-bit integer as big-endian to arbitrary location.
*
* Put a 16-bit integer, originally in host endianness, to a
* potentially unaligned memory location in big-endian format.
*
* @param val 16-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_be16(uint16_t val, uint8_t dst[2])
{
dst[0] = val >> 8;
dst[1] = val;
}
/**
* @brief Put a 24-bit integer as big-endian to arbitrary location.
*
* Put a 24-bit integer, originally in host endianness, to a
* potentially unaligned memory location in big-endian format.
*
* @param val 24-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_be24(uint32_t val, uint8_t dst[3])
{
dst[0] = val >> 16;
sys_put_be16(val, &dst[1]);
}
/**
* @brief Put a 32-bit integer as big-endian to arbitrary location.
*
* Put a 32-bit integer, originally in host endianness, to a
* potentially unaligned memory location in big-endian format.
*
* @param val 32-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_be32(uint32_t val, uint8_t dst[4])
{
sys_put_be16(val >> 16, dst);
sys_put_be16(val, &dst[2]);
}
/**
* @brief Put a 48-bit integer as big-endian to arbitrary location.
*
* Put a 48-bit integer, originally in host endianness, to a
* potentially unaligned memory location in big-endian format.
*
* @param val 48-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_be48(uint64_t val, uint8_t dst[6])
{
sys_put_be16(val >> 32, dst);
sys_put_be32(val, &dst[2]);
}
/**
* @brief Put a 64-bit integer as big-endian to arbitrary location.
*
* Put a 64-bit integer, originally in host endianness, to a
* potentially unaligned memory location in big-endian format.
*
* @param val 64-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_be64(uint64_t val, uint8_t dst[8])
{
sys_put_be32(val >> 32, dst);
sys_put_be32(val, &dst[4]);
}
/**
* @brief Put a 16-bit integer as little-endian to arbitrary location.
*
* Put a 16-bit integer, originally in host endianness, to a
* potentially unaligned memory location in little-endian format.
*
* @param val 16-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_le16(uint16_t val, uint8_t dst[2])
{
dst[0] = val;
dst[1] = val >> 8;
}
/**
* @brief Put a 24-bit integer as little-endian to arbitrary location.
*
* Put a 24-bit integer, originally in host endianness, to a
* potentially unaligned memory location in littel-endian format.
*
* @param val 24-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_le24(uint32_t val, uint8_t dst[3])
{
sys_put_le16(val, dst);
dst[2] = val >> 16;
}
/**
* @brief Put a 32-bit integer as little-endian to arbitrary location.
*
* Put a 32-bit integer, originally in host endianness, to a
* potentially unaligned memory location in little-endian format.
*
* @param val 32-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_le32(uint32_t val, uint8_t dst[4])
{
sys_put_le16(val, dst);
sys_put_le16(val >> 16, &dst[2]);
}
/**
* @brief Put a 48-bit integer as little-endian to arbitrary location.
*
* Put a 48-bit integer, originally in host endianness, to a
* potentially unaligned memory location in little-endian format.
*
* @param val 48-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_le48(uint64_t val, uint8_t dst[6])
{
sys_put_le32(val, dst);
sys_put_le16(val >> 32, &dst[4]);
}
/**
* @brief Put a 64-bit integer as little-endian to arbitrary location.
*
* Put a 64-bit integer, originally in host endianness, to a
* potentially unaligned memory location in little-endian format.
*
* @param val 64-bit integer in host endianness.
* @param dst Destination memory address to store the result.
*/
static inline void sys_put_le64(uint64_t val, uint8_t dst[8])
{
sys_put_le32(val, dst);
sys_put_le32(val >> 32, &dst[4]);
}
/**
* @brief Get a 16-bit integer stored in big-endian format.
*
* Get a 16-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 16-bit integer to get.
*
* @return 16-bit integer in host endianness.
*/
static inline uint16_t sys_get_be16(const uint8_t src[2])
{
return ((uint16_t)src[0] << 8) | src[1];
}
/**
* @brief Get a 24-bit integer stored in big-endian format.
*
* Get a 24-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 24-bit integer to get.
*
* @return 24-bit integer in host endianness.
*/
static inline uint32_t sys_get_be24(const uint8_t src[3])
{
return ((uint32_t)src[0] << 16) | sys_get_be16(&src[1]);
}
/**
* @brief Get a 32-bit integer stored in big-endian format.
*
* Get a 32-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 32-bit integer to get.
*
* @return 32-bit integer in host endianness.
*/
static inline uint32_t sys_get_be32(const uint8_t src[4])
{
return ((uint32_t)sys_get_be16(&src[0]) << 16) | sys_get_be16(&src[2]);
}
/**
* @brief Get a 48-bit integer stored in big-endian format.
*
* Get a 48-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 48-bit integer to get.
*
* @return 48-bit integer in host endianness.
*/
static inline uint64_t sys_get_be48(const uint8_t src[6])
{
return ((uint64_t)sys_get_be32(&src[0]) << 32) | sys_get_be16(&src[4]);
}
/**
* @brief Get a 64-bit integer stored in big-endian format.
*
* Get a 64-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 64-bit integer to get.
*
* @return 64-bit integer in host endianness.
*/
static inline uint64_t sys_get_be64(const uint8_t src[8])
{
return ((uint64_t)sys_get_be32(&src[0]) << 32) | sys_get_be32(&src[4]);
}
/**
* @brief Get a 16-bit integer stored in little-endian format.
*
* Get a 16-bit integer, stored in little-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the little-endian 16-bit integer to get.
*
* @return 16-bit integer in host endianness.
*/
static inline uint16_t sys_get_le16(const uint8_t src[2])
{
return ((uint16_t)src[1] << 8) | src[0];
}
/**
* @brief Get a 24-bit integer stored in big-endian format.
*
* Get a 24-bit integer, stored in big-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the big-endian 24-bit integer to get.
*
* @return 24-bit integer in host endianness.
*/
static inline uint32_t sys_get_le24(const uint8_t src[3])
{
return ((uint32_t)src[2] << 16) | sys_get_le16(&src[0]);
}
/**
* @brief Get a 32-bit integer stored in little-endian format.
*
* Get a 32-bit integer, stored in little-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the little-endian 32-bit integer to get.
*
* @return 32-bit integer in host endianness.
*/
static inline uint32_t sys_get_le32(const uint8_t src[4])
{
return ((uint32_t)sys_get_le16(&src[2]) << 16) | sys_get_le16(&src[0]);
}
/**
* @brief Get a 48-bit integer stored in little-endian format.
*
* Get a 48-bit integer, stored in little-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the little-endian 48-bit integer to get.
*
* @return 48-bit integer in host endianness.
*/
static inline uint64_t sys_get_le48(const uint8_t src[6])
{
return ((uint64_t)sys_get_le32(&src[2]) << 32) | sys_get_le16(&src[0]);
}
/**
* @brief Get a 64-bit integer stored in little-endian format.
*
* Get a 64-bit integer, stored in little-endian format in a potentially
* unaligned memory location, and convert it to the host endianness.
*
* @param src Location of the little-endian 64-bit integer to get.
*
* @return 64-bit integer in host endianness.
*/
static inline uint64_t sys_get_le64(const uint8_t src[8])
{
return ((uint64_t)sys_get_le32(&src[4]) << 32) | sys_get_le32(&src[0]);
}
/**
* @brief Swap one buffer content into another
*
* Copy the content of src buffer into dst buffer in reversed order,
* i.e.: src[n] will be put in dst[end-n]
* Where n is an index and 'end' the last index in both arrays.
* The 2 memory pointers must be pointing to different areas, and have
* a minimum size of given length.
*
* @param dst A valid pointer on a memory area where to copy the data in
* @param src A valid pointer on a memory area where to copy the data from
* @param length Size of both dst and src memory areas
*/
static inline void sys_memcpy_swap(void *dst, const void *src, size_t length)
{
uint8_t *pdst = (uint8_t *)dst;
const uint8_t *psrc = (const uint8_t *)src;
__ASSERT(((psrc < pdst && (psrc + length) <= pdst) ||
(psrc > pdst && (pdst + length) <= psrc)),
"Source and destination buffers must not overlap");
psrc += length - 1;
for (; length > 0; length--) {
*pdst++ = *psrc--;
}
}
/**
* @brief Swap buffer content
*
* In-place memory swap, where final content will be reversed.
* I.e.: buf[n] will be put in buf[end-n]
* Where n is an index and 'end' the last index of buf.
*
* @param buf A valid pointer on a memory area to swap
* @param length Size of buf memory area
*/
static inline void sys_mem_swap(void *buf, size_t length)
{
size_t i;
for (i = 0; i < (length / 2); i++) {
uint8_t tmp = ((uint8_t *)buf)[i];
((uint8_t *)buf)[i] = ((uint8_t *)buf)[length - 1 - i];
((uint8_t *)buf)[length - 1 - i] = tmp;
}
}
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_BYTEORDER_H_ */

View File

@ -0,0 +1,74 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Model Common APIs.
*/
#ifndef _BLE_MESH_COMMON_H_
#define _BLE_MESH_COMMON_H_
#include <stddef.h>
#include <stdlib.h>
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include "mesh_byteorder.h"
#include "mesh_ffs.h"
#include "mesh_trace.h"
#include "mesh_mutex.h"
#include "mesh_access.h"
#ifdef __cplusplus
extern "C" {
#endif
IRAM_ATTR void *bt_mesh_malloc(size_t size);
IRAM_ATTR void *bt_mesh_calloc(size_t size);
IRAM_ATTR void bt_mesh_free(void *ptr);
/**
* @brief This function allocates memory to store outgoing message.
*
* @param[in] size: Length of memory allocated to store message value
*
* @return NULL-fail, pointer of a net_buf_simple structure-success
*/
struct net_buf_simple *bt_mesh_alloc_buf(uint16_t size);
/**
* @brief This function releases the memory allocated for the outgoing message.
*
* @param[in] buf: Pointer to the net_buf_simple structure to be freed
*
* @return none
*/
void bt_mesh_free_buf(struct net_buf_simple *buf);
/**
* @brief This function gets device role for stack internal use.
*
* @Note Currently Provisioner only support client models, Node supports
* client models and server models. Hence if srv_send is set to be
* TRUE, then role NODE will be returned.
*
* @param[in] model: Pointer to the model structure
* @param[in] srv_send: Indicate if the message is sent by a server model
*
* @return 0 - Node, 1 - Provisioner
*/
uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send);
int bt_mesh_rand(void *buf, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_COMMON_H_ */

View File

@ -0,0 +1,80 @@
/*
* SPDX-FileCopyrightText: 2010-2014,2017 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_COMPILER_H_
#define _BLE_MESH_COMPILER_H_
#ifdef __cplusplus
extern "C" {
#endif
#define ___in_section(a, b, c)
#define __in_section(a, b, c) ___in_section(a, b, c)
#define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__)
#ifndef __packed
#define __packed __attribute__((__packed__))
#endif
#ifndef __aligned
#define __aligned(x) __attribute__((__aligned__(x)))
#endif
#ifndef __used
#define __used __attribute__((__used__))
#endif
#ifndef ARG_UNUSED
#define ARG_UNUSED(x) (void)(x)
#endif
#ifndef popcount
#define popcount(x) __builtin_popcount(x)
#endif
#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE inline __attribute__((always_inline))
#endif
/*
* This is meant to be used in conjunction with __in_section() and similar
* where scattered structure instances are concatened together by the linker
* and walked by the code at run time just like a contiguous array of such
* structures.
*
* Assemblers and linkers may insert alignment padding by default whose
* size is larger than the natural alignment for those structures when
* gathering various section segments together, messing up the array walk.
* To prevent this, we need to provide an explicit alignment not to rely
* on the default that might just work by luck.
*
* Alignment statements in linker scripts are not sufficient as
* the assembler may add padding by itself to each segment when switching
* between sections within the same file even if it merges many such segments
* into a single section in the end.
*/
#ifndef Z_DECL_ALIGN
#define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type
#endif
/*
* Convenience helper combining __in_section() and Z_DECL_ALIGN().
* The section name is the struct type prepended with an underscore.
* The subsection is "static" and the subsubsection is the variable name.
*/
#ifndef Z_STRUCT_SECTION_ITERABLE
#define Z_STRUCT_SECTION_ITERABLE(struct_type, name) \
Z_DECL_ALIGN(struct struct_type) name
#endif
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_COMPILER_H_ */

View File

@ -0,0 +1,47 @@
/*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_CONFIG_H_
#define _BLE_MESH_CONFIG_H_
#include "sdkconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CONFIG_BLE_MESH_GENERIC_CLIENT (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI || \
CONFIG_BLE_MESH_GENERIC_LEVEL_CLI || \
CONFIG_BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI || \
CONFIG_BLE_MESH_GENERIC_POWER_ONOFF_CLI || \
CONFIG_BLE_MESH_GENERIC_POWER_LEVEL_CLI || \
CONFIG_BLE_MESH_GENERIC_BATTERY_CLI || \
CONFIG_BLE_MESH_GENERIC_LOCATION_CLI || \
CONFIG_BLE_MESH_GENERIC_PROPERTY_CLI)
#define CONFIG_BLE_MESH_TIME_SCENE_CLIENT (CONFIG_BLE_MESH_TIME_CLI || \
CONFIG_BLE_MESH_SCENE_CLI || \
CONFIG_BLE_MESH_SCHEDULER_CLI)
#define CONFIG_BLE_MESH_LIGHTING_CLIENT (CONFIG_BLE_MESH_LIGHT_LIGHTNESS_CLI || \
CONFIG_BLE_MESH_LIGHT_CTL_CLI || \
CONFIG_BLE_MESH_LIGHT_HSL_CLI || \
CONFIG_BLE_MESH_LIGHT_XYL_CLI || \
CONFIG_BLE_MESH_LIGHT_LC_CLI)
#define CONFIG_BLE_MESH_SERVER_MODEL (CONFIG_BLE_MESH_GENERIC_SERVER || \
CONFIG_BLE_MESH_SENSOR_SERVER || \
CONFIG_BLE_MESH_TIME_SCENE_SERVER || \
CONFIG_BLE_MESH_LIGHTING_SERVER)
#define CONFIG_BLE_MESH_BLE_COEX_SUPPORT (CONFIG_BLE_MESH_SUPPORT_BLE_ADV || \
CONFIG_BLE_MESH_SUPPORT_BLE_SCAN)
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_CONFIG_H_ */

View File

@ -0,0 +1,498 @@
/*
* SPDX-FileCopyrightText: 2013-2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Doubly-linked list implementation
*
* Doubly-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.
*
* The lists are expected to be initialized such that both the head and tail
* pointers point to the list itself. Initializing the lists in such a fashion
* simplifies the adding and removing of nodes to/from the list.
*/
#ifndef _BLE_MESH_DLIST_H_
#define _BLE_MESH_DLIST_H_
#include <stddef.h>
#include "mesh_util.h"
#ifdef __cplusplus
extern "C" {
#endif
struct _dnode {
union {
struct _dnode *head; /* ptr to head of list (sys_dlist_t) */
struct _dnode *next; /* ptr to next node (sys_dnode_t) */
};
union {
struct _dnode *tail; /* ptr to tail of list (sys_dlist_t) */
struct _dnode *prev; /* ptr to previous node (sys_dnode_t) */
};
};
typedef struct _dnode sys_dlist_t;
typedef struct _dnode sys_dnode_t;
/**
* @brief Provide the primitive to iterate on a list
* Note: the loop is unsafe and thus __dn should not be removed
*
* User _MUST_ add the loop statement curly braces enclosing its own code:
*
* SYS_DLIST_FOR_EACH_NODE(l, n) {
* <user code>
* }
*
* This and other SYS_DLIST_*() macros are not thread safe.
*
* @param __dl A pointer on a sys_dlist_t to iterate on
* @param __dn A sys_dnode_t pointer to peek each node of the list
*/
#define SYS_DLIST_FOR_EACH_NODE(__dl, __dn) \
for (__dn = sys_dlist_peek_head(__dl); __dn; \
__dn = sys_dlist_peek_next(__dl, __dn))
/**
* @brief Provide the primitive to iterate on a list, from a node in the list
* Note: the loop is unsafe and thus __dn should not be removed
*
* User _MUST_ add the loop statement curly braces enclosing its own code:
*
* SYS_DLIST_ITERATE_FROM_NODE(l, n) {
* <user code>
* }
*
* Like SYS_DLIST_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_DLIST_*() macros are not thread safe.
*
* @param __dl A pointer on a sys_dlist_t to iterate on
* @param __dn A sys_dnode_t pointer to peek each node of the list;
* it contains the starting node, or NULL to start from the head
*/
#define SYS_DLIST_ITERATE_FROM_NODE(__dl, __dn) \
for (__dn = __dn ? sys_dlist_peek_next_no_check(__dl, __dn) \
: sys_dlist_peek_head(__dl); \
__dn; \
__dn = sys_dlist_peek_next(__dl, __dn))
/**
* @brief Provide the primitive to safely iterate on a list
* Note: __dn can be removed, it will not break the loop.
*
* User _MUST_ add the loop statement curly braces enclosing its own code:
*
* SYS_DLIST_FOR_EACH_NODE_SAFE(l, n, s) {
* <user code>
* }
*
* This and other SYS_DLIST_*() macros are not thread safe.
*
* @param __dl A pointer on a sys_dlist_t to iterate on
* @param __dn A sys_dnode_t pointer to peek each node of the list
* @param __dns A sys_dnode_t pointer for the loop to run safely
*/
#define SYS_DLIST_FOR_EACH_NODE_SAFE(__dl, __dn, __dns) \
for (__dn = sys_dlist_peek_head(__dl), \
__dns = sys_dlist_peek_next(__dl, __dn); \
__dn; __dn = __dns, \
__dns = sys_dlist_peek_next(__dl, __dn))
/*
* @brief Provide the primitive to resolve the container of a list node
* Note: it is safe to use with NULL pointer nodes
*
* @param __dn A pointer on a sys_dnode_t to get its container
* @param __cn Container struct type pointer
* @param __n The field name of sys_dnode_t within the container struct
*/
#define SYS_DLIST_CONTAINER(__dn, __cn, __n) \
(__dn ? CONTAINER_OF(__dn, __typeof__(*__cn), __n) : NULL)
/*
* @brief Provide the primitive to peek container of the list head
*
* @param __dl A pointer on a sys_dlist_t to peek
* @param __cn Container struct type pointer
* @param __n The field name of sys_dnode_t within the container struct
*/
#define SYS_DLIST_PEEK_HEAD_CONTAINER(__dl, __cn, __n) \
SYS_DLIST_CONTAINER(sys_dlist_peek_head(__dl), __cn, __n)
/*
* @brief Provide the primitive to peek the next container
*
* @param __dl A pointer on a sys_dlist_t to peek
* @param __cn Container struct type pointer
* @param __n The field name of sys_dnode_t within the container struct
*/
#define SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n) \
((__cn) ? SYS_DLIST_CONTAINER(sys_dlist_peek_next(__dl, &(__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_DLIST_FOR_EACH_CONTAINER(l, c, n) {
* <user code>
* }
*
* @param __dl A pointer on a sys_dlist_t to iterate on
* @param __cn A pointer to peek each entry of the list
* @param __n The field name of sys_dnode_t within the container struct
*/
#define SYS_DLIST_FOR_EACH_CONTAINER(__dl, __cn, __n) \
for (__cn = SYS_DLIST_PEEK_HEAD_CONTAINER(__dl, __cn, __n); __cn; \
__cn = SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __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_DLIST_FOR_EACH_CONTAINER_SAFE(l, c, cn, n) {
* <user code>
* }
*
* @param __dl A pointer on a sys_dlist_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_dnode_t within the container struct
*/
#define SYS_DLIST_FOR_EACH_CONTAINER_SAFE(__dl, __cn, __cns, __n) \
for (__cn = SYS_DLIST_PEEK_HEAD_CONTAINER(__dl, __cn, __n), \
__cns = SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n); __cn; \
__cn = __cns, \
__cns = SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n))
/**
* @brief initialize list
*
* @param list the doubly-linked list
*
* @return N/A
*/
static inline void sys_dlist_init(sys_dlist_t *list)
{
list->head = (sys_dnode_t *)list;
list->tail = (sys_dnode_t *)list;
}
#define SYS_DLIST_STATIC_INIT(ptr_to_list) {{(ptr_to_list)}, {(ptr_to_list)}}
/**
* @brief check if a node is the list's head
*
* @param list the doubly-linked list to operate on
* @param node the node to check
*
* @return 1 if node is the head, 0 otherwise
*/
static inline int sys_dlist_is_head(sys_dlist_t *list, sys_dnode_t *node)
{
return list->head == node;
}
/**
* @brief check if a node is the list's tail
*
* @param list the doubly-linked list to operate on
* @param node the node to check
*
* @return 1 if node is the tail, 0 otherwise
*/
static inline int sys_dlist_is_tail(sys_dlist_t *list, sys_dnode_t *node)
{
return list->tail == node;
}
/**
* @brief check if the list is empty
*
* @param list the doubly-linked list to operate on
*
* @return 1 if empty, 0 otherwise
*/
static inline int sys_dlist_is_empty(sys_dlist_t *list)
{
return list->head == list;
}
/**
* @brief check if more than one node present
*
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
*
* @return 1 if multiple nodes, 0 otherwise
*/
static inline int sys_dlist_has_multiple_nodes(sys_dlist_t *list)
{
return list->head != list->tail;
}
/**
* @brief get a reference to the head item in the list
*
* @param list the doubly-linked list to operate on
*
* @return a pointer to the head element, NULL if list is empty
*/
static inline sys_dnode_t *sys_dlist_peek_head(sys_dlist_t *list)
{
return sys_dlist_is_empty(list) ? NULL : list->head;
}
/**
* @brief get a reference to the head item in the list
*
* The list must be known to be non-empty.
*
* @param list the doubly-linked list to operate on
*
* @return a pointer to the head element
*/
static inline sys_dnode_t *sys_dlist_peek_head_not_empty(sys_dlist_t *list)
{
return list->head;
}
/**
* @brief get a reference to the next item in the list, node is not NULL
*
* Faster than sys_dlist_peek_next() if node is known not to be NULL.
*
* @param list the doubly-linked list to operate on
* @param node the node from which to get the next element in the list
*
* @return a pointer to the next element from a node, NULL if node is the tail
*/
static inline sys_dnode_t *sys_dlist_peek_next_no_check(sys_dlist_t *list,
sys_dnode_t *node)
{
return (node == list->tail) ? NULL : node->next;
}
/**
* @brief get a reference to the next item in the list
*
* @param list the doubly-linked list to operate on
* @param node the node from which to get the next element in the list
*
* @return a pointer to the next element from a node, NULL if node is the tail
* or NULL (when node comes from reading the head of an empty list).
*/
static inline sys_dnode_t *sys_dlist_peek_next(sys_dlist_t *list,
sys_dnode_t *node)
{
return node ? sys_dlist_peek_next_no_check(list, node) : NULL;
}
/**
* @brief get a reference to the tail item in the list
*
* @param list the doubly-linked list to operate on
*
* @return a pointer to the tail element, NULL if list is empty
*/
static inline sys_dnode_t *sys_dlist_peek_tail(sys_dlist_t *list)
{
return sys_dlist_is_empty(list) ? NULL : list->tail;
}
/**
* @brief add node to tail of list
*
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
* @param node the element to append
*
* @return N/A
*/
static inline void sys_dlist_append(sys_dlist_t *list, sys_dnode_t *node)
{
node->next = list;
node->prev = list->tail;
list->tail->next = node;
list->tail = node;
}
/**
* @brief add node to head of list
*
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
* @param node the element to append
*
* @return N/A
*/
static inline void sys_dlist_prepend(sys_dlist_t *list, sys_dnode_t *node)
{
node->next = list->head;
node->prev = list;
list->head->prev = node;
list->head = node;
}
/**
* @brief insert node after a node
*
* Insert a node after a specified node in a list.
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
* @param insert_point the insert point in the list: if NULL, insert at head
* @param node the element to append
*
* @return N/A
*/
static inline void sys_dlist_insert_after(sys_dlist_t *list,
sys_dnode_t *insert_point,
sys_dnode_t *node)
{
if (!insert_point) {
sys_dlist_prepend(list, node);
} else {
node->next = insert_point->next;
node->prev = insert_point;
insert_point->next->prev = node;
insert_point->next = node;
}
}
/**
* @brief insert node before a node
*
* Insert a node before a specified node in a list.
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
* @param insert_point the insert point in the list: if NULL, insert at tail
* @param node the element to insert
*
* @return N/A
*/
static inline void sys_dlist_insert_before(sys_dlist_t *list,
sys_dnode_t *insert_point,
sys_dnode_t *node)
{
if (!insert_point) {
sys_dlist_append(list, node);
} else {
node->prev = insert_point->prev;
node->next = insert_point;
insert_point->prev->next = node;
insert_point->prev = node;
}
}
/**
* @brief insert node at position
*
* Insert a node in a location depending on a external condition. The cond()
* function checks if the node is to be inserted _before_ the current node
* against which it is checked.
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
* @param node the element to insert
* @param cond a function that determines if the current node is the correct
* insert point
* @param data parameter to cond()
*
* @return N/A
*/
static inline void sys_dlist_insert_at(sys_dlist_t *list, sys_dnode_t *node,
int (*cond)(sys_dnode_t *, void *), void *data)
{
if (sys_dlist_is_empty(list)) {
sys_dlist_append(list, node);
} else {
sys_dnode_t *pos = sys_dlist_peek_head(list);
while (pos && !cond(pos, data)) {
pos = sys_dlist_peek_next(list, pos);
}
sys_dlist_insert_before(list, pos, node);
}
}
/**
* @brief remove a specific node from a list
*
* The list is implicit from the node. The node must be part of a list.
* This and other sys_dlist_*() functions are not thread safe.
*
* @param node the node to remove
*
* @return N/A
*/
static inline void sys_dlist_remove(sys_dnode_t *node)
{
node->prev->next = node->next;
node->next->prev = node->prev;
}
/**
* @brief get the first node in a list
*
* This and other sys_dlist_*() functions are not thread safe.
*
* @param list the doubly-linked list to operate on
*
* @return the first node in the list, NULL if list is empty
*/
static inline sys_dnode_t *sys_dlist_get(sys_dlist_t *list)
{
sys_dnode_t *node;
if (sys_dlist_is_empty(list)) {
return NULL;
}
node = list->head;
sys_dlist_remove(node);
return node;
}
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_DLIST_H_ */

View File

@ -0,0 +1,60 @@
/*
* SPDX-FileCopyrightText: 2015 Wind River Systems, Inc.
* SPDX-FileCopyrightText: 2017 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_FFS_H_
#define _BLE_MESH_FFS_H_
#include "mesh_types.h"
#include "mesh_compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
*
* @brief find most significant bit set in a 32-bit word
*
* This routine finds the first bit set starting from the most significant bit
* in the argument passed in and returns the index of that bit. Bits are
* numbered starting at 1 from the least significant bit. A return value of
* zero indicates that the value passed is zero.
*
* @return most significant bit set, 0 if @a op is 0
*/
static ALWAYS_INLINE unsigned int find_msb_set(uint32_t op)
{
if (op == 0) {
return 0;
}
return 32 - __builtin_clz(op);
}
/**
*
* @brief find least significant bit set in a 32-bit word
*
* This routine finds the first bit set starting from the least significant bit
* in the argument passed in and returns the index of that bit. Bits are
* numbered starting at 1 from the least significant bit. A return value of
* zero indicates that the value passed is zero.
*
* @return least significant bit set, 0 if @a op is 0
*/
static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
{
return __builtin_ffs(op);
}
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_FFS_H_ */

View File

@ -0,0 +1,59 @@
/*
* SPDX-FileCopyrightText: 2016 Wind River Systems, Inc.
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_KERNEL_H_
#define _BLE_MESH_KERNEL_H_
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "mesh_config.h"
#include "mesh_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#ifdef CONFIG_BT_BLUEDROID_PINNED_TO_CORE
#define BLE_MESH_ADV_TASK_CORE (CONFIG_BT_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY)
#else
#define BLE_MESH_ADV_TASK_CORE (0)
#endif
#endif
#ifdef CONFIG_BT_NIMBLE_ENABLED
#ifdef CONFIG_BT_NIMBLE_PINNED_TO_CORE
#define BLE_MESH_ADV_TASK_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
#else
#define BLE_MESH_ADV_TASK_CORE (0)
#endif
#endif
#define BLE_MESH_ADV_TASK_STACK_SIZE 3072
#define BLE_MESH_ADV_TASK_NAME "mesh_adv_task"
#define BLE_MESH_ADV_TASK_PRIO (configMAX_PRIORITIES - 5)
/**
* @brief Put the current thread to sleep.
*
* This routine puts the current thread to sleep for @a duration
* milliseconds.
*
* @param duration Number of milliseconds to sleep.
*
* @return N/A
*/
void k_sleep(int32_t duration);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_KERNEL_H_ */

View File

@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_MUTEX_H_
#define _BLE_MESH_MUTEX_H_
#include "mesh_kernel.h"
#include "mesh_slist.h"
#include "mesh_atomic.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
SemaphoreHandle_t mutex;
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
StaticQueue_t *buffer;
#endif
} bt_mesh_mutex_t;
void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex);
void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex);
void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex);
void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex);
void bt_mesh_alarm_lock(void);
void bt_mesh_alarm_unlock(void);
void bt_mesh_list_lock(void);
void bt_mesh_list_unlock(void);
void bt_mesh_buf_lock(void);
void bt_mesh_buf_unlock(void);
void bt_mesh_atomic_lock(void);
void bt_mesh_atomic_unlock(void);
void bt_mesh_mutex_init(void);
void bt_mesh_mutex_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_MUTEX_H_ */

View File

@ -0,0 +1,467 @@
/*
* SPDX-FileCopyrightText: 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 _BLE_MESH_SLIST_H_
#define _BLE_MESH_SLIST_H_
#include <stddef.h>
#include <stdbool.h>
#include "mesh_util.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 /* _BLE_MESH_SLIST_H_ */

View File

@ -0,0 +1,266 @@
/*
* SPDX-FileCopyrightText: 2016 Wind River Systems, Inc.
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_TIMER_H_
#define _BLE_MESH_TIMER_H_
#include "mesh_types.h"
#include "mesh_slist.h"
#include "mesh_atomic.h"
#ifdef __cplusplus
extern "C" {
#endif
/* number of nsec per usec */
#define NSEC_PER_USEC 1000
/* number of microseconds per millisecond */
#define USEC_PER_MSEC 1000
/* number of milliseconds per second */
#define MSEC_PER_SEC 1000
/* number of microseconds per second */
#define USEC_PER_SEC ((USEC_PER_MSEC) * (MSEC_PER_SEC))
/* number of nanoseconds per second */
#define NSEC_PER_SEC ((NSEC_PER_USEC) * (USEC_PER_MSEC) * (MSEC_PER_SEC))
/* timeout is not in use */
#define _INACTIVE (-1)
struct k_work;
/**
* @typedef k_work_handler_t
* @brief Work item handler function type.
*
* A work item's handler function is executed by a workqueue's thread
* when the work item is processed by the workqueue.
*
* @param work Address of the work item.
*
* @return N/A
*/
typedef void (*k_work_handler_t)(struct k_work *work);
struct k_work {
void *_reserved;
k_work_handler_t handler;
int index;
};
#define _K_WORK_INITIALIZER(work_handler) \
{ \
._reserved = NULL, \
.handler = work_handler, \
}
/**
* @brief Generate null timeout delay.
*
* This macro generates a timeout delay that that instructs a kernel API
* not to wait if the requested operation cannot be performed immediately.
*
* @return Timeout delay value.
*/
#define K_NO_WAIT 0
/**
* @brief Generate timeout delay from milliseconds.
*
* This macro generates a timeout delay that that instructs a kernel API
* to wait up to @a ms milliseconds to perform the requested operation.
*
* @param ms Duration in milliseconds.
*
* @return Timeout delay value.
*/
#define K_MSEC(ms) (ms)
/**
* @brief Generate timeout delay from seconds.
*
* This macro generates a timeout delay that that instructs a kernel API
* to wait up to @a s seconds to perform the requested operation.
*
* @param s Duration in seconds.
*
* @return Timeout delay value.
*/
#define K_SECONDS(s) K_MSEC((s) * MSEC_PER_SEC)
/**
* @brief Generate timeout delay from minutes.
*
* This macro generates a timeout delay that that instructs a kernel API
* to wait up to @a m minutes to perform the requested operation.
*
* @param m Duration in minutes.
*
* @return Timeout delay value.
*/
#define K_MINUTES(m) K_SECONDS((m) * 60)
/**
* @brief Generate timeout delay from hours.
*
* This macro generates a timeout delay that that instructs a kernel API
* to wait up to @a h hours to perform the requested operation.
*
* @param h Duration in hours.
*
* @return Timeout delay value.
*/
#define K_HOURS(h) K_MINUTES((h) * 60)
/**
* @brief Generate infinite timeout delay.
*
* This macro generates a timeout delay that that instructs a kernel API
* to wait as long as necessary to perform the requested operation.
*
* @return Timeout delay value.
*/
#define K_FOREVER (-1)
/**
* @brief Get system uptime (32-bit version).
*
* This routine returns the lower 32-bits of the elapsed time since the system
* booted, in milliseconds.
*
* This routine can be more efficient than k_uptime_get(), as it reduces the
* need for interrupt locking and 64-bit math. However, the 32-bit result
* cannot hold a system uptime time larger than approximately 50 days, so the
* caller must handle possible rollovers.
*
* @return Current uptime.
*/
uint32_t k_uptime_get_32(void);
struct k_delayed_work {
struct k_work work;
};
/**
* @brief Submit a delayed work item to the system workqueue.
*
* This routine schedules work item @a work to be processed by the system
* workqueue after a delay of @a delay milliseconds. The routine initiates
* an asynchronous countdown for the work item and then returns to the caller.
* Only when the countdown completes is the work item actually submitted to
* the workqueue and becomes pending.
*
* Submitting a previously submitted delayed work item that is still
* counting down cancels the existing submission and restarts the countdown
* using the new delay. If the work item is currently pending on the
* workqueue's queue because the countdown has completed it is too late to
* resubmit the item, and resubmission fails without impacting the work item.
* If the work item has already been processed, or is currently being processed,
* its work is considered complete and the work item can be resubmitted.
*
* @warning
* Work items submitted to the system workqueue should avoid using handlers
* that block or yield since this may prevent the system workqueue from
* processing other work items in a timely manner.
*
* @note Can be called by ISRs.
*
* @param work Address of delayed work item.
* @param delay Delay before submitting the work item (in milliseconds).
*
* @retval 0 Work item countdown started.
* @retval -EINPROGRESS Work item is already pending.
* @retval -EINVAL Work item is being processed or has completed its work.
* @retval -EADDRINUSE Work item is pending on a different workqueue.
*/
int k_delayed_work_submit(struct k_delayed_work *work, int32_t delay);
int k_delayed_work_submit_periodic(struct k_delayed_work *work, int32_t period);
/**
* @brief Get time remaining before a delayed work gets scheduled.
*
* This routine computes the (approximate) time remaining before a
* delayed work gets executed. If the delayed work is not waiting to be
* scheduled, it returns zero.
*
* @param work Delayed work item.
*
* @return Remaining time (in milliseconds).
*/
int32_t k_delayed_work_remaining_get(struct k_delayed_work *work);
/**
* @brief Submit a work item to the system workqueue.
*
* This routine submits work item @a work to be processed by the system
* workqueue. If the work item is already pending in the workqueue's queue
* as a result of an earlier submission, this routine has no effect on the
* work item. If the work item has already been processed, or is currently
* being processed, its work is considered complete and the work item can be
* resubmitted.
*
* @warning
* Work items submitted to the system workqueue should avoid using handlers
* that block or yield since this may prevent the system workqueue from
* processing other work items in a timely manner.
*
* @note Can be called by ISRs.
*
* @param work Address of work item.
*
* @return N/A
*/
static inline void k_work_submit(struct k_work *work)
{
if (work && work->handler) {
work->handler(work);
}
}
/**
* @brief Initialize a work item.
*
* This routine initializes a workqueue work item, prior to its first use.
*
* @param work Address of work item.
* @param handler Function to invoke each time work item is processed.
*
* @return N/A
*/
static inline void k_work_init(struct k_work *work, k_work_handler_t handler)
{
work->handler = handler;
}
int k_delayed_work_cancel(struct k_delayed_work *work);
int k_delayed_work_free(struct k_delayed_work *work);
int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler);
/**
* @brief Get system uptime.
*
* This routine returns the elapsed time since the system booted,
* in milliseconds.
*
* @return Current uptime.
*/
int64_t k_uptime_get(void);
void bt_mesh_timer_init(void);
void bt_mesh_timer_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_TIMER_H_ */

View File

@ -0,0 +1,127 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_TRACE_H_
#define _BLE_MESH_TRACE_H_
#include <assert.h>
#include "esp_log.h"
#include "mesh_util.h"
#include "esp_rom_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Define common tracing for all */
#ifndef BLE_MESH_LOG_LEVEL_ERROR
#define BLE_MESH_LOG_LEVEL_ERROR 1
#endif /* BLE_MESH_LOG_LEVEL_ERROR */
#ifndef BLE_MESH_LOG_LEVEL_WARN
#define BLE_MESH_LOG_LEVEL_WARN 2
#endif /* BLE_MESH_LOG_LEVEL_WARN */
#ifndef BLE_MESH_LOG_LEVEL_INFO
#define BLE_MESH_LOG_LEVEL_INFO 3
#endif /* BLE_MESH_LOG_LEVEL_INFO */
#ifndef BLE_MESH_LOG_LEVEL_DEBUG
#define BLE_MESH_LOG_LEVEL_DEBUG 4
#endif /* BLE_MESH_LOG_LEVEL_DEBUG */
#ifndef BLE_MESH_LOG_LEVEL_VERBOSE
#define BLE_MESH_LOG_LEVEL_VERBOSE 5
#endif /*BLE_MESH_LOG_LEVEL_VERBOSE */
#ifdef CONFIG_BLE_MESH_STACK_TRACE_LEVEL
#define BLE_MESH_LOG_LEVEL CONFIG_BLE_MESH_STACK_TRACE_LEVEL
#else
#define BLE_MESH_LOG_LEVEL BLE_MESH_LOG_LEVEL_WARN
#endif
#ifdef CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL
#define BLE_MESH_NET_BUF_LOG_LEVEL CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL
#else
#define BLE_MESH_NET_BUF_LOG_LEVEL BLE_MESH_LOG_LEVEL_WARN
#endif
#define BLE_MESH_TRACE_TAG "BLE_MESH"
#if (LOG_LOCAL_LEVEL >= 4)
#define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL + 1)
#else
#define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL
#endif
#define BLE_MESH_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_LOG_LEVEL, BLE_MESH_LOG_LOCAL_LEVEL_MAPPING) >= BLE_MESH_LOG_LEVEL_##LEVEL)
#define BLE_MESH_PRINT_E(tag, format, ...) {esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define BLE_MESH_PRINT_W(tag, format, ...) {esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define BLE_MESH_PRINT_I(tag, format, ...) {esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define BLE_MESH_PRINT_D(tag, format, ...) {esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define BLE_MESH_PRINT_V(tag, format, ...) {esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define printk esp_rom_printf
#define _STRINGIFY(x) #x
#define STRINGIFY(s) _STRINGIFY(s)
#ifndef __ASSERT
#define __ASSERT(test, str) assert(test)
#endif
#ifndef __ASSERT_NO_MSG
#define __ASSERT_NO_MSG(x) assert(x)
#endif
#if !CONFIG_BLE_MESH_NO_LOG
#define BT_ERR(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define BT_WARN(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define BT_INFO(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define BT_DBG(fmt, args...) do {if ((BLE_MESH_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH, DEBUG)) BLE_MESH_PRINT_D(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#else
#define BT_ERR(fmt, args...)
#define BT_WARN(fmt, args...)
#define BT_INFO(fmt, args...)
#define BT_DBG(fmt, args...)
#endif
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) && (!CONFIG_BLE_MESH_NO_LOG)
#define NET_BUF_ERR(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_WARN(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_INFO(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_DBG(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, DEBUG)) BLE_MESH_PRINT_D(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_ASSERT(cond) __ASSERT_NO_MSG(cond)
#else
#define NET_BUF_ERR(fmt, args...)
#define NET_BUF_WARN(fmt, args...)
#define NET_BUF_INFO(fmt, args...)
#define NET_BUF_DBG(fmt, args...)
#define NET_BUF_ASSERT(cond)
#endif
#if defined(CONFIG_BLE_MESH_NET_BUF_SIMPLE_LOG) && (!CONFIG_BLE_MESH_NO_LOG)
#define NET_BUF_SIMPLE_ERR(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_SIMPLE_WARN(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_SIMPLE_INFO(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_SIMPLE_DBG(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, DEBUG)) BLE_MESH_PRINT_D(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_SIMPLE_ASSERT(cond) __ASSERT_NO_MSG(cond)
#else
#define NET_BUF_SIMPLE_ERR(fmt, args...)
#define NET_BUF_SIMPLE_WARN(fmt, args...)
#define NET_BUF_SIMPLE_INFO(fmt, args...)
#define NET_BUF_SIMPLE_DBG(fmt, args...)
#define NET_BUF_SIMPLE_ASSERT(cond)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_TRACE_H_ */

View File

@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: 2017 Linaro Limited
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_TYPES_H_
#define _BLE_MESH_TYPES_H_
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef int bt_mesh_atomic_t;
#ifndef PRIu64
#define PRIu64 "llu"
#endif
#ifndef PRIx64
#define PRIx64 "llx"
#endif
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_TYPES_H_ */

View File

@ -0,0 +1,191 @@
/*
* SPDX-FileCopyrightText: 2011-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Misc utilities
*
* Misc utilities usable by the kernel and application code.
*/
#ifndef _BLE_MESH_UTIL_H_
#define _BLE_MESH_UTIL_H_
#include <stddef.h>
#include "esp_bit_defs.h"
#include "mesh_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Helper to pass a int as a pointer or vice-versa.
* Those are available for 32 bits architectures:
*/
#ifndef POINTER_TO_UINT
#define POINTER_TO_UINT(x) ((uint32_t) (x))
#endif
#ifndef UINT_TO_POINTER
#define UINT_TO_POINTER(x) ((void *) (x))
#endif
#ifndef POINTER_TO_INT
#define POINTER_TO_INT(x) ((int32_t) (x))
#endif
#ifndef INT_TO_POINTER
#define INT_TO_POINTER(x) ((void *) (x))
#endif
/* Evaluates to 0 if cond is true-ish; compile error otherwise */
#ifndef ZERO_OR_COMPILE_ERROR
#define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
#endif
/* Evaluates to 0 if array is an array; compile error if not array (e.g.
* pointer)
*/
#ifndef IS_ARRAY
#define IS_ARRAY(array) \
ZERO_OR_COMPILE_ERROR( \
!__builtin_types_compatible_p(__typeof__(array), \
__typeof__(&(array)[0])))
#endif
/* Evaluates to number of elements in an array; compile error if not
* an array (e.g. pointer)
*/
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif
/* Evaluates to 1 if ptr is part of array, 0 otherwise; compile error if
* "array" argument is not an array (e.g. "ptr" and "array" mixed up)
*/
#ifndef PART_OF_ARRAY
#define PART_OF_ARRAY(array, ptr) \
((ptr) && ((ptr) >= &array[0] && (ptr) < &array[ARRAY_SIZE(array)]))
#endif
#ifndef CONTAINER_OF
#define CONTAINER_OF(ptr, type, field) \
((type *)(((char *)(ptr)) - offsetof(type, field)))
#endif
/* round "x" up/down to next multiple of "align" (which must be a power of 2) */
#ifndef ROUND_UP
#define ROUND_UP(x, align) \
(((unsigned long)(x) + ((unsigned long)align - 1)) & \
~((unsigned long)align - 1))
#endif
#ifndef ROUND_DOWN
#define ROUND_DOWN(x, align) ((unsigned long)(x) & ~((unsigned long)align - 1))
#endif
/* round up/down to the next word boundary */
#ifndef WB_UP
#define WB_UP(x) ROUND_UP(x, sizeof(void *))
#endif
#ifndef WB_DN
#define WB_DN(x) ROUND_DOWN(x, sizeof(void *))
#endif
#ifndef ceiling_fraction
#define ceiling_fraction(numerator, divider) \
(((numerator) + ((divider) - 1)) / (divider))
#endif
#ifndef CHECKIF
#define CHECKIF(expr) if (expr)
#endif
/** @brief Return larger value of two provided expressions.
*
* @note Arguments are evaluated twice. See Z_MAX for GCC only, single
* evaluation version.
*/
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
/** @brief Return smaller value of two provided expressions.
*
* @note Arguments are evaluated twice. See Z_MIN for GCC only, single
* evaluation version.
*/
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef BIT
#define BIT(n) (1UL << (n))
#endif
#ifndef BIT_MASK
#define BIT_MASK(n) (BIT(n) - 1)
#endif
/**
* @brief Check for macro definition in compiler-visible expressions
*
* This trick was pioneered in Linux as the config_enabled() macro.
* The madness has the effect of taking a macro value that may be
* defined to "1" (e.g. CONFIG_MYFEATURE), or may not be defined at
* all and turning it into a literal expression that can be used at
* "runtime". That is, it works similarly to
* "defined(CONFIG_MYFEATURE)" does except that it is an expansion
* that can exist in a standard expression and be seen by the compiler
* and optimizer. Thus much ifdef usage can be replaced with cleaner
* expressions like:
*
* if (IS_ENABLED(CONFIG_MYFEATURE))
* myfeature_enable();
*
* INTERNAL
* First pass just to expand any existing macros, we need the macro
* value to be e.g. a literal "1" at expansion time in the next macro,
* not "(1)", etc... Standard recursive expansion does not work.
*/
#define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
/* Now stick on a "_XXXX" prefix, it will now be "_XXXX1" if config_macro
* is "1", or just "_XXXX" if it's undefined.
* ENABLED: Z_IS_ENABLED2(_XXXX1)
* DISABLED Z_IS_ENABLED2(_XXXX)
*/
#define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
/* Here's the core trick, we map "_XXXX1" to "_YYYY," (i.e. a string
* with a trailing comma), so it has the effect of making this a
* two-argument tuple to the preprocessor only in the case where the
* value is defined to "1"
* ENABLED: _YYYY, <--- note comma!
* DISABLED: _XXXX
*/
#define _XXXX1 _YYYY,
/* Then we append an extra argument to fool the gcc preprocessor into
* accepting it as a varargs macro.
* arg1 arg2 arg3
* ENABLED: Z_IS_ENABLED3(_YYYY, 1, 0)
* DISABLED Z_IS_ENABLED3(_XXXX 1, 0)
*/
#define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args true, false)
/* And our second argument is thus now cooked to be 1 in the case
* where the value is defined to 1, and 0 if not:
*/
#define Z_IS_ENABLED3(ignore_this, val, ...) val
const char *bt_hex(const void *buf, size_t len);
void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_UTIL_H_ */

View File

@ -0,0 +1,130 @@
/* aes.h - TinyCrypt interface to an AES-128 implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief -- Interface to an AES-128 implementation.
*
* Overview: AES-128 is a NIST approved block cipher specified in
* FIPS 197. Block ciphers are deterministic algorithms that
* perform a transformation specified by a symmetric key in fixed-
* length data sets, also called blocks.
*
* Security: AES-128 provides approximately 128 bits of security.
*
* Usage: 1) call tc_aes128_set_encrypt/decrypt_key to set the key.
*
* 2) call tc_aes_encrypt/decrypt to process the data.
*/
#ifndef __BLE_MESH_TC_AES_H__
#define __BLE_MESH_TC_AES_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define Nb (4) /* number of columns (32-bit words) comprising the state */
#define Nk (4) /* number of 32-bit words comprising the key */
#define Nr (10) /* number of rounds */
#define TC_AES_BLOCK_SIZE (Nb*Nk)
#define TC_AES_KEY_SIZE (Nb*Nk)
typedef struct tc_aes_key_sched_struct {
unsigned int words[Nb * (Nr + 1)];
} *TCAesKeySched_t;
/**
* @brief Set AES-128 encryption key
* Uses key k to initialize s
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if: s == NULL or k == NULL
* @note This implementation skips the additional steps required for keys
* larger than 128 bits, and must not be used for AES-192 or
* AES-256 key schedule -- see FIPS 197 for details
* @param s IN/OUT -- initialized struct tc_aes_key_sched_struct
* @param k IN -- points to the AES key
*/
int tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k);
/**
* @brief AES-128 Encryption procedure
* Encrypts contents of in buffer into out buffer under key;
* schedule s
* @note Assumes s was initialized by aes_set_encrypt_key;
* out and in point to 16 byte buffers
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if: out == NULL or in == NULL or s == NULL
* @param out IN/OUT -- buffer to receive ciphertext block
* @param in IN -- a plaintext block to encrypt
* @param s IN -- initialized AES key schedule
*/
int tc_aes_encrypt(uint8_t *out, const uint8_t *in,
const TCAesKeySched_t s);
/**
* @brief Set the AES-128 decryption key
* Uses key k to initialize s
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if: s == NULL or k == NULL
* @note This is the implementation of the straightforward inverse cipher
* using the cipher documented in FIPS-197 figure 12, not the
* equivalent inverse cipher presented in Figure 15
* @warning This routine skips the additional steps required for keys larger
* than 128, and must not be used for AES-192 or AES-256 key
* schedule -- see FIPS 197 for details
* @param s IN/OUT -- initialized struct tc_aes_key_sched_struct
* @param k IN -- points to the AES key
*/
int tc_aes128_set_decrypt_key(TCAesKeySched_t s, const uint8_t *k);
/**
* @brief AES-128 Encryption procedure
* Decrypts in buffer into out buffer under key schedule s
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if: out is NULL or in is NULL or s is NULL
* @note Assumes s was initialized by aes_set_encrypt_key
* out and in point to 16 byte buffers
* @param out IN/OUT -- buffer to receive ciphertext block
* @param in IN -- a plaintext block to encrypt
* @param s IN -- initialized AES key schedule
*/
int tc_aes_decrypt(uint8_t *out, const uint8_t *in,
const TCAesKeySched_t s);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_AES_H__ */

View File

@ -0,0 +1,151 @@
/* cbc_mode.h - TinyCrypt interface to a CBC mode implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to a CBC mode implementation.
*
* Overview: CBC (for "cipher block chaining") mode is a NIST approved mode of
* operation defined in SP 800-38a. It can be used with any block
* cipher to provide confidentiality of strings whose lengths are
* multiples of the block_size of the underlying block cipher.
* TinyCrypt hard codes AES as the block cipher.
*
* Security: CBC mode provides data confidentiality given that the maximum
* number q of blocks encrypted under a single key satisfies
* q < 2^63, which is not a practical constraint (it is considered a
* good practice to replace the encryption when q == 2^56). CBC mode
* provides NO data integrity.
*
* CBC mode assumes that the IV value input into the
* tc_cbc_mode_encrypt is randomly generated. The TinyCrypt library
* provides HMAC-PRNG module, which generates suitable IVs. Other
* methods for generating IVs are acceptable, provided that the
* values of the IVs generated appear random to any adversary,
* including someone with complete knowledge of the system design.
*
* The randomness property on which CBC mode's security depends is
* the unpredictability of the IV. Since it is unpredictable, this
* means in practice that CBC mode requires that the IV is stored
* somehow with the ciphertext in order to recover the plaintext.
*
* TinyCrypt CBC encryption prepends the IV to the ciphertext,
* because this affords a more efficient (few buffers) decryption.
* Hence tc_cbc_mode_encrypt assumes the ciphertext buffer is always
* 16 bytes larger than the plaintext buffer.
*
* Requires: AES-128
*
* Usage: 1) call tc_cbc_mode_encrypt to encrypt data.
*
* 2) call tc_cbc_mode_decrypt to decrypt data.
*
*/
#ifndef __BLE_MESH_TC_CBC_MODE_H__
#define __BLE_MESH_TC_CBC_MODE_H__
#include <tinycrypt/aes.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief CBC encryption procedure
* CBC encrypts inlen bytes of the in buffer into the out buffer
* using the encryption key schedule provided, prepends iv to out
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* out == NULL or
* in == NULL or
* ctr == NULL or
* sched == NULL or
* inlen == 0 or
* (inlen % TC_AES_BLOCK_SIZE) != 0 or
* (outlen % TC_AES_BLOCK_SIZE) != 0 or
* outlen != inlen + TC_AES_BLOCK_SIZE
* @note Assumes: - sched has been configured by aes_set_encrypt_key
* - iv contains a 16 byte random string
* - out buffer is large enough to hold the ciphertext + iv
* - out buffer is a contiguous buffer
* - in holds the plaintext and is a contiguous buffer
* - inlen gives the number of bytes in the in buffer
* @param out IN/OUT -- buffer to receive the ciphertext
* @param outlen IN -- length of ciphertext buffer in bytes
* @param in IN -- plaintext to encrypt
* @param inlen IN -- length of plaintext buffer in bytes
* @param iv IN -- the IV for the this encrypt/decrypt
* @param sched IN -- AES key schedule for this encrypt
*/
int tc_cbc_mode_encrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
unsigned int inlen, const uint8_t *iv,
const TCAesKeySched_t sched);
/**
* @brief CBC decryption procedure
* CBC decrypts inlen bytes of the in buffer into the out buffer
* using the provided encryption key schedule
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* out == NULL or
* in == NULL or
* sched == NULL or
* inlen == 0 or
* outlen == 0 or
* (inlen % TC_AES_BLOCK_SIZE) != 0 or
* (outlen % TC_AES_BLOCK_SIZE) != 0 or
* outlen != inlen + TC_AES_BLOCK_SIZE
* @note Assumes:- in == iv + ciphertext, i.e. the iv and the ciphertext are
* contiguous. This allows for a very efficient decryption
* algorithm that would not otherwise be possible
* - sched was configured by aes_set_decrypt_key
* - out buffer is large enough to hold the decrypted plaintext
* and is a contiguous buffer
* - inlen gives the number of bytes in the in buffer
* @param out IN/OUT -- buffer to receive decrypted data
* @param outlen IN -- length of plaintext buffer in bytes
* @param in IN -- ciphertext to decrypt, including IV
* @param inlen IN -- length of ciphertext buffer in bytes
* @param iv IN -- the IV for the this encrypt/decrypt
* @param sched IN -- AES key schedule for this decrypt
*
*/
int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
unsigned int inlen, const uint8_t *iv,
const TCAesKeySched_t sched);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_CBC_MODE_H__ */

View File

@ -0,0 +1,211 @@
/* ccm_mode.h - TinyCrypt interface to a CCM mode implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to a CCM mode implementation.
*
* Overview: CCM (for "Counter with CBC-MAC") mode is a NIST approved mode of
* operation defined in SP 800-38C.
*
* TinyCrypt CCM implementation accepts:
*
* 1) Both non-empty payload and associated data (it encrypts and
* authenticates the payload and also authenticates the associated
* data);
* 2) Non-empty payload and empty associated data (it encrypts and
* authenticates the payload);
* 3) Non-empty associated data and empty payload (it degenerates to
* an authentication mode on the associated data).
*
* TinyCrypt CCM implementation accepts associated data of any length
* between 0 and (2^16 - 2^8) bytes.
*
* Security: The mac length parameter is an important parameter to estimate the
* security against collision attacks (that aim at finding different
* messages that produce the same authentication tag). TinyCrypt CCM
* implementation accepts any even integer between 4 and 16, as
* suggested in SP 800-38C.
*
* RFC-3610, which also specifies CCM, presents a few relevant
* security suggestions, such as: it is recommended for most
* applications to use a mac length greater than 8. Besides, the
* usage of the same nonce for two different messages which are
* encrypted with the same key destroys the security of CCM mode.
*
* Requires: AES-128
*
* Usage: 1) call tc_ccm_config to configure.
*
* 2) call tc_ccm_mode_encrypt to encrypt data and generate tag.
*
* 3) call tc_ccm_mode_decrypt to decrypt data and verify tag.
*/
#ifndef __BLE_MESH_TC_CCM_MODE_H__
#define __BLE_MESH_TC_CCM_MODE_H__
#include <tinycrypt/aes.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* max additional authenticated size in bytes: 2^16 - 2^8 = 65280 */
#define TC_CCM_AAD_MAX_BYTES 0xff00
/* max message size in bytes: 2^(8L) = 2^16 = 65536 */
#define TC_CCM_PAYLOAD_MAX_BYTES 0x10000
/* struct tc_ccm_mode_struct represents the state of a CCM computation */
typedef struct tc_ccm_mode_struct {
TCAesKeySched_t sched; /* AES key schedule */
uint8_t *nonce; /* nonce required by CCM */
unsigned int mlen; /* mac length in bytes (parameter t in SP-800 38C) */
} *TCCcmMode_t;
/**
* @brief CCM configuration procedure
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* c == NULL or
* sched == NULL or
* nonce == NULL or
* mlen != {4, 6, 8, 10, 12, 16}
* @param c -- CCM state
* @param sched IN -- AES key schedule
* @param nonce IN - nonce
* @param nlen -- nonce length in bytes
* @param mlen -- mac length in bytes (parameter t in SP-800 38C)
*/
int tc_ccm_config(TCCcmMode_t c, TCAesKeySched_t sched, uint8_t *nonce,
unsigned int nlen, unsigned int mlen);
/**
* @brief CCM tag generation and encryption procedure
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* out == NULL or
* c == NULL or
* ((plen > 0) and (payload == NULL)) or
* ((alen > 0) and (associated_data == NULL)) or
* (alen >= TC_CCM_AAD_MAX_BYTES) or
* (plen >= TC_CCM_PAYLOAD_MAX_BYTES) or
* (olen < plen + maclength)
*
* @param out OUT -- encrypted data
* @param olen IN -- output length in bytes
* @param associated_data IN -- associated data
* @param alen IN -- associated data length in bytes
* @param payload IN -- payload
* @param plen IN -- payload length in bytes
* @param c IN -- CCM state
*
* @note: out buffer should be at least (plen + c->mlen) bytes long.
*
* @note: The sequence b for encryption is formatted as follows:
* b = [FLAGS | nonce | counter ], where:
* FLAGS is 1 byte long
* nonce is 13 bytes long
* counter is 2 bytes long
* The byte FLAGS is composed by the following 8 bits:
* 0-2 bits: used to represent the value of q-1
* 3-7 btis: always 0's
*
* @note: The sequence b for authentication is formatted as follows:
* b = [FLAGS | nonce | length(mac length)], where:
* FLAGS is 1 byte long
* nonce is 13 bytes long
* length(mac length) is 2 bytes long
* The byte FLAGS is composed by the following 8 bits:
* 0-2 bits: used to represent the value of q-1
* 3-5 bits: mac length (encoded as: (mlen-2)/2)
* 6: Adata (0 if alen == 0, and 1 otherwise)
* 7: always 0
*/
int tc_ccm_generation_encryption(uint8_t *out, unsigned int olen,
const uint8_t *associated_data,
unsigned int alen, const uint8_t *payload,
unsigned int plen, TCCcmMode_t c);
/**
* @brief CCM decryption and tag verification procedure
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* out == NULL or
* c == NULL or
* ((plen > 0) and (payload == NULL)) or
* ((alen > 0) and (associated_data == NULL)) or
* (alen >= TC_CCM_AAD_MAX_BYTES) or
* (plen >= TC_CCM_PAYLOAD_MAX_BYTES) or
* (olen < plen - c->mlen)
*
* @param out OUT -- decrypted data
* @param associated_data IN -- associated data
* @param alen IN -- associated data length in bytes
* @param payload IN -- payload
* @param plen IN -- payload length in bytes
* @param c IN -- CCM state
*
* @note: out buffer should be at least (plen - c->mlen) bytes long.
*
* @note: The sequence b for encryption is formatted as follows:
* b = [FLAGS | nonce | counter ], where:
* FLAGS is 1 byte long
* nonce is 13 bytes long
* counter is 2 bytes long
* The byte FLAGS is composed by the following 8 bits:
* 0-2 bits: used to represent the value of q-1
* 3-7 btis: always 0's
*
* @note: The sequence b for authentication is formatted as follows:
* b = [FLAGS | nonce | length(mac length)], where:
* FLAGS is 1 byte long
* nonce is 13 bytes long
* length(mac length) is 2 bytes long
* The byte FLAGS is composed by the following 8 bits:
* 0-2 bits: used to represent the value of q-1
* 3-5 bits: mac length (encoded as: (mlen-2)/2)
* 6: Adata (0 if alen == 0, and 1 otherwise)
* 7: always 0
*/
int tc_ccm_decryption_verification(uint8_t *out, unsigned int olen,
const uint8_t *associated_data,
unsigned int alen, const uint8_t *payload, unsigned int plen,
TCCcmMode_t c);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_CCM_MODE_H__ */

View File

@ -0,0 +1,194 @@
/* cmac_mode.h -- interface to a CMAC implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to a CMAC implementation.
*
* Overview: CMAC is defined NIST in SP 800-38B, and is the standard algorithm
* for computing a MAC using a block cipher. It can compute the MAC
* for a byte string of any length. It is distinguished from CBC-MAC
* in the processing of the final message block; CMAC uses a
* different technique to compute the final message block is full
* size or only partial, while CBC-MAC uses the same technique for
* both. This difference permits CMAC to be applied to variable
* length messages, while all messages authenticated by CBC-MAC must
* be the same length.
*
* Security: AES128-CMAC mode of operation offers 64 bits of security against
* collision attacks. Note however that an external attacker cannot
* generate the tags him/herself without knowing the MAC key. In this
* sense, to attack the collision property of AES128-CMAC, an
* external attacker would need the cooperation of the legal user to
* produce an exponentially high number of tags (e.g. 2^64) to
* finally be able to look for collisions and benefit from them. As
* an extra precaution, the current implementation allows to at most
* 2^48 calls to the tc_cmac_update function before re-calling
* tc_cmac_setup (allowing a new key to be set), as suggested in
* Appendix B of SP 800-38B.
*
* Requires: AES-128
*
* Usage: This implementation provides a "scatter-gather" interface, so that
* the CMAC value can be computed incrementally over a message
* scattered in different segments throughout memory. Experience shows
* this style of interface tends to minimize the burden of programming
* correctly. Like all symmetric key operations, it is session
* oriented.
*
* To begin a CMAC session, use tc_cmac_setup to initialize a struct
* tc_cmac_struct with encryption key and buffer. Our implementation
* always assume that the AES key to be the same size as the block
* cipher block size. Once setup, this data structure can be used for
* many CMAC computations.
*
* Once the state has been setup with a key, computing the CMAC of
* some data requires three steps:
*
* (1) first use tc_cmac_init to initialize a new CMAC computation.
* (2) next mix all of the data into the CMAC computation state using
* tc_cmac_update. If all of the data resides in a single data
* segment then only one tc_cmac_update call is needed; if data
* is scattered throughout memory in n data segments, then n calls
* will be needed. CMAC IS ORDER SENSITIVE, to be able to detect
* attacks that swap bytes, so the order in which data is mixed
* into the state is critical!
* (3) Once all of the data for a message has been mixed, use
* tc_cmac_final to compute the CMAC tag value.
*
* Steps (1)-(3) can be repeated as many times as you want to CMAC
* multiple messages. A practical limit is 2^48 1K messages before you
* have to change the key.
*
* Once you are done computing CMAC with a key, it is a good idea to
* destroy the state so an attacker cannot recover the key; use
* tc_cmac_erase to accomplish this.
*/
#ifndef __BLE_MESH_TC_CMAC_MODE_H__
#define __BLE_MESH_TC_CMAC_MODE_H__
#include <tinycrypt/aes.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* padding for last message block */
#define TC_CMAC_PADDING 0x80
/* struct tc_cmac_struct represents the state of a CMAC computation */
typedef struct tc_cmac_struct {
/* initialization vector */
uint8_t iv[TC_AES_BLOCK_SIZE];
/* used if message length is a multiple of block_size bytes */
uint8_t K1[TC_AES_BLOCK_SIZE];
/* used if message length isn't a multiple block_size bytes */
uint8_t K2[TC_AES_BLOCK_SIZE];
/* where to put bytes that didn't fill a block */
uint8_t leftover[TC_AES_BLOCK_SIZE];
/* identifies the encryption key */
unsigned int keyid;
/* next available leftover location */
unsigned int leftover_offset;
/* AES key schedule */
TCAesKeySched_t sched;
/* calls to tc_cmac_update left before re-key */
uint64_t countdown;
} *TCCmacState_t;
/**
* @brief Configures the CMAC state to use the given AES key
* @return returns TC_CRYPTO_SUCCESS (1) after having configured the CMAC state
* returns TC_CRYPTO_FAIL (0) if:
* s == NULL or
* key == NULL
*
* @param s IN/OUT -- the state to set up
* @param key IN -- the key to use
* @param sched IN -- AES key schedule
*/
int tc_cmac_setup(TCCmacState_t s, const uint8_t *key,
TCAesKeySched_t sched);
/**
* @brief Erases the CMAC state
* @return returns TC_CRYPTO_SUCCESS (1) after having configured the CMAC state
* returns TC_CRYPTO_FAIL (0) if:
* s == NULL
*
* @param s IN/OUT -- the state to erase
*/
int tc_cmac_erase(TCCmacState_t s);
/**
* @brief Initializes a new CMAC computation
* @return returns TC_CRYPTO_SUCCESS (1) after having initialized the CMAC state
* returns TC_CRYPTO_FAIL (0) if:
* s == NULL
*
* @param s IN/OUT -- the state to initialize
*/
int tc_cmac_init(TCCmacState_t s);
/**
* @brief Incrementally computes CMAC over the next data segment
* @return returns TC_CRYPTO_SUCCESS (1) after successfully updating the CMAC state
* returns TC_CRYPTO_FAIL (0) if:
* s == NULL or
* if data == NULL when dlen > 0
*
* @param s IN/OUT -- the CMAC state
* @param data IN -- the next data segment to MAC
* @param dlen IN -- the length of data in bytes
*/
int tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t dlen);
/**
* @brief Generates the tag from the CMAC state
* @return returns TC_CRYPTO_SUCCESS (1) after successfully generating the tag
* returns TC_CRYPTO_FAIL (0) if:
* tag == NULL or
* s == NULL
*
* @param tag OUT -- the CMAC tag
* @param s IN -- CMAC state
*/
int tc_cmac_final(uint8_t *tag, TCCmacState_t s);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_CMAC_MODE_H__ */

View File

@ -0,0 +1,61 @@
/* constants.h - TinyCrypt interface to constants */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief -- Interface to constants.
*
*/
#ifndef __BLE_MESH_TC_CONSTANTS_H__
#define __BLE_MESH_TC_CONSTANTS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#ifndef NULL
#define NULL ((void *)0)
#endif
#define TC_CRYPTO_SUCCESS 1
#define TC_CRYPTO_FAIL 0
#define TC_ZERO_BYTE 0x00
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_CONSTANTS_H__ */

View File

@ -0,0 +1,108 @@
/* ctr_mode.h - TinyCrypt interface to CTR mode */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to CTR mode.
*
* Overview: CTR (pronounced "counter") mode is a NIST approved mode of
* operation defined in SP 800-38a. It can be used with any
* block cipher to provide confidentiality of strings of any
* length. TinyCrypt hard codes AES128 as the block cipher.
*
* Security: CTR mode achieves confidentiality only if the counter value is
* never reused with a same encryption key. If the counter is
* repeated, than an adversary might be able to defeat the scheme.
*
* A usual method to ensure different counter values refers to
* initialize the counter in a given value (0, for example) and
* increases it every time a new block is enciphered. This naturally
* leaves to a limitation on the number q of blocks that can be
* enciphered using a same key: q < 2^(counter size).
*
* TinyCrypt uses a counter of 32 bits. This means that after 2^32
* block encryptions, the counter will be reused (thus losing CBC
* security). 2^32 block encryptions should be enough for most of
* applications targeting constrained devices. Applications intended
* to encrypt a larger number of blocks must replace the key after
* 2^32 block encryptions.
*
* CTR mode provides NO data integrity.
*
* Requires: AES-128
*
* Usage: 1) call tc_ctr_mode to process the data to encrypt/decrypt.
*
*/
#ifndef __BLE_MESH_TC_CTR_MODE_H__
#define __BLE_MESH_TC_CTR_MODE_H__
#include <tinycrypt/aes.h>
#include <tinycrypt/constants.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief CTR mode encryption/decryption procedure.
* CTR mode encrypts (or decrypts) inlen bytes from in buffer into out buffer
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* out == NULL or
* in == NULL or
* ctr == NULL or
* sched == NULL or
* inlen == 0 or
* outlen == 0 or
* inlen != outlen
* @note Assumes:- The current value in ctr has NOT been used with sched
* - out points to inlen bytes
* - in points to inlen bytes
* - ctr is an integer counter in littleEndian format
* - sched was initialized by aes_set_encrypt_key
* @param out OUT -- produced ciphertext (plaintext)
* @param outlen IN -- length of ciphertext buffer in bytes
* @param in IN -- data to encrypt (or decrypt)
* @param inlen IN -- length of input data in bytes
* @param ctr IN/OUT -- the current counter value
* @param sched IN -- an initialized AES key schedule
*/
int tc_ctr_mode(uint8_t *out, unsigned int outlen, const uint8_t *in,
unsigned int inlen, uint8_t *ctr, const TCAesKeySched_t sched);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_CTR_MODE_H__ */

View File

@ -0,0 +1,166 @@
/* ctr_prng.h - TinyCrypt interface to a CTR-PRNG implementation */
/*
* Copyright (c) 2016, Chris Morrison
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to a CTR-PRNG implementation.
*
* Overview: A pseudo-random number generator (PRNG) generates a sequence
* of numbers that have a distribution close to the one expected
* for a sequence of truly random numbers. The NIST Special
* Publication 800-90A specifies several mechanisms to generate
* sequences of pseudo random numbers, including the CTR-PRNG one
* which is based on AES. TinyCrypt implements CTR-PRNG with
* AES-128.
*
* Security: A cryptographically secure PRNG depends on the existence of an
* entropy source to provide a truly random seed as well as the
* security of the primitives used as the building blocks (AES-128
* in this instance).
*
* Requires: - AES-128
*
* Usage: 1) call tc_ctr_prng_init to seed the prng context
*
* 2) call tc_ctr_prng_reseed to mix in additional entropy into
* the prng context
*
* 3) call tc_ctr_prng_generate to output the pseudo-random data
*
* 4) call tc_ctr_prng_uninstantiate to zero out the prng context
*/
#ifndef __BLE_MESH_TC_CTR_PRNG_H__
#define __BLE_MESH_TC_CTR_PRNG_H__
#include <tinycrypt/aes.h>
#define TC_CTR_PRNG_RESEED_REQ -1
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
/* updated each time another BLOCKLEN_BYTES bytes are produced */
uint8_t V[TC_AES_BLOCK_SIZE];
/* updated whenever the PRNG is reseeded */
struct tc_aes_key_sched_struct key;
/* number of requests since initialization/reseeding */
uint64_t reseedCount;
} TCCtrPrng_t;
/**
* @brief CTR-PRNG initialization procedure
* Initializes prng context with entropy and personalization string (if any)
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* ctx == NULL,
* entropy == NULL,
* entropyLen < (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE)
* @note Only the first (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE) bytes of
* both the entropy and personalization inputs are used -
* supplying additional bytes has no effect.
* @param ctx IN/OUT -- the PRNG context to initialize
* @param entropy IN -- entropy used to seed the PRNG
* @param entropyLen IN -- entropy length in bytes
* @param personalization IN -- personalization string used to seed the PRNG
* (may be null)
* @param plen IN -- personalization length in bytes
*
*/
int tc_ctr_prng_init(TCCtrPrng_t *const ctx,
uint8_t const *const entropy,
unsigned int entropyLen,
uint8_t const *const personalization,
unsigned int pLen);
/**
* @brief CTR-PRNG reseed procedure
* Mixes entropy and additional_input into the prng context
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* ctx == NULL,
* entropy == NULL,
* entropylen < (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE)
* @note It is better to reseed an existing prng context rather than
* re-initialise, so that any existing entropy in the context is
* presereved. This offers some protection against undetected failures
* of the entropy source.
* @note Assumes tc_ctr_prng_init has been called for ctx
* @param ctx IN/OUT -- the PRNG state
* @param entropy IN -- entropy to mix into the prng
* @param entropylen IN -- length of entropy in bytes
* @param additional_input IN -- additional input to the prng (may be null)
* @param additionallen IN -- additional input length in bytes
*/
int tc_ctr_prng_reseed(TCCtrPrng_t *const ctx,
uint8_t const *const entropy,
unsigned int entropyLen,
uint8_t const *const additional_input,
unsigned int additionallen);
/**
* @brief CTR-PRNG generate procedure
* Generates outlen pseudo-random bytes into out buffer, updates prng
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CTR_PRNG_RESEED_REQ (-1) if a reseed is needed
* returns TC_CRYPTO_FAIL (0) if:
* ctx == NULL,
* out == NULL,
* outlen >= 2^16
* @note Assumes tc_ctr_prng_init has been called for ctx
* @param ctx IN/OUT -- the PRNG context
* @param additional_input IN -- additional input to the prng (may be null)
* @param additionallen IN -- additional input length in bytes
* @param out IN/OUT -- buffer to receive output
* @param outlen IN -- size of out buffer in bytes
*/
int tc_ctr_prng_generate(TCCtrPrng_t *const ctx,
uint8_t const *const additional_input,
unsigned int additionallen,
uint8_t *const out,
unsigned int outlen);
/**
* @brief CTR-PRNG uninstantiate procedure
* Zeroes the internal state of the supplied prng context
* @return none
* @param ctx IN/OUT -- the PRNG context
*/
void tc_ctr_prng_uninstantiate(TCCtrPrng_t *const ctx);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_CTR_PRNG_H__ */

View File

@ -0,0 +1,545 @@
/* ecc.h - TinyCrypt interface to common ECC functions */
/* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief -- Interface to common ECC functions.
*
* Overview: This software is an implementation of common functions
* necessary to elliptic curve cryptography. This implementation uses
* curve NIST p-256.
*
* Security: The curve NIST p-256 provides approximately 128 bits of security.
*
*/
#ifndef __BLE_MESH_TC_UECC_H__
#define __BLE_MESH_TC_UECC_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Word size (4 bytes considering 32-bits architectures) */
#define uECC_WORD_SIZE 4
/* setting max number of calls to prng: */
#ifndef uECC_RNG_MAX_TRIES
#define uECC_RNG_MAX_TRIES 64
#endif
/* defining data types to store word and bit counts: */
typedef int8_t wordcount_t;
typedef int16_t bitcount_t;
/* defining data type for comparison result: */
typedef int8_t cmpresult_t;
/* defining data type to store ECC coordinate/point in 32bits words: */
typedef unsigned int uECC_word_t;
/* defining data type to store an ECC coordinate/point in 64bits words: */
typedef uint64_t uECC_dword_t;
/* defining masks useful for ecc computations: */
#define HIGH_BIT_SET 0x80000000
#define uECC_WORD_BITS 32
#define uECC_WORD_BITS_SHIFT 5
#define uECC_WORD_BITS_MASK 0x01F
/* Number of words of 32 bits to represent an element of the the curve p-256: */
#define NUM_ECC_WORDS 8
/* Number of bytes to represent an element of the the curve p-256: */
#define NUM_ECC_BYTES (uECC_WORD_SIZE*NUM_ECC_WORDS)
/* structure that represents an elliptic curve (e.g. p256):*/
struct uECC_Curve_t;
typedef const struct uECC_Curve_t *uECC_Curve;
struct uECC_Curve_t {
wordcount_t num_words;
wordcount_t num_bytes;
bitcount_t num_n_bits;
uECC_word_t p[NUM_ECC_WORDS];
uECC_word_t n[NUM_ECC_WORDS];
uECC_word_t G[NUM_ECC_WORDS * 2];
uECC_word_t b[NUM_ECC_WORDS];
void (*double_jacobian)(uECC_word_t *X1, uECC_word_t *Y1, uECC_word_t *Z1,
uECC_Curve curve);
void (*x_side)(uECC_word_t *result, const uECC_word_t *x, uECC_Curve curve);
void (*mmod_fast)(uECC_word_t *result, uECC_word_t *product);
};
/*
* @brief computes doubling of point ion jacobian coordinates, in place.
* @param X1 IN/OUT -- x coordinate
* @param Y1 IN/OUT -- y coordinate
* @param Z1 IN/OUT -- z coordinate
* @param curve IN -- elliptic curve
*/
void double_jacobian_default(uECC_word_t *X1, uECC_word_t *Y1,
uECC_word_t *Z1, uECC_Curve curve);
/*
* @brief Computes x^3 + ax + b. result must not overlap x.
* @param result OUT -- x^3 + ax + b
* @param x IN -- value of x
* @param curve IN -- elliptic curve
*/
void x_side_default(uECC_word_t *result, const uECC_word_t *x,
uECC_Curve curve);
/*
* @brief Computes result = product % curve_p
* from http://www.nsa.gov/ia/_files/nist-routines.pdf
* @param result OUT -- product % curve_p
* @param product IN -- value to be reduced mod curve_p
*/
void vli_mmod_fast_secp256r1(unsigned int *result, unsigned int *product);
/* Bytes to words ordering: */
#define BYTES_TO_WORDS_8(a, b, c, d, e, f, g, h) 0x##d##c##b##a, 0x##h##g##f##e
#define BYTES_TO_WORDS_4(a, b, c, d) 0x##d##c##b##a
#define BITS_TO_WORDS(num_bits) \
((num_bits + ((uECC_WORD_SIZE * 8) - 1)) / (uECC_WORD_SIZE * 8))
#define BITS_TO_BYTES(num_bits) ((num_bits + 7) / 8)
/* definition of curve NIST p-256: */
static const struct uECC_Curve_t curve_secp256r1 = {
NUM_ECC_WORDS,
NUM_ECC_BYTES,
256, /* num_n_bits */ {
BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF),
BYTES_TO_WORDS_8(FF, FF, FF, FF, 00, 00, 00, 00),
BYTES_TO_WORDS_8(00, 00, 00, 00, 00, 00, 00, 00),
BYTES_TO_WORDS_8(01, 00, 00, 00, FF, FF, FF, FF)
}, {
BYTES_TO_WORDS_8(51, 25, 63, FC, C2, CA, B9, F3),
BYTES_TO_WORDS_8(84, 9E, 17, A7, AD, FA, E6, BC),
BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF),
BYTES_TO_WORDS_8(00, 00, 00, 00, FF, FF, FF, FF)
}, {
BYTES_TO_WORDS_8(96, C2, 98, D8, 45, 39, A1, F4),
BYTES_TO_WORDS_8(A0, 33, EB, 2D, 81, 7D, 03, 77),
BYTES_TO_WORDS_8(F2, 40, A4, 63, E5, E6, BC, F8),
BYTES_TO_WORDS_8(47, 42, 2C, E1, F2, D1, 17, 6B),
BYTES_TO_WORDS_8(F5, 51, BF, 37, 68, 40, B6, CB),
BYTES_TO_WORDS_8(CE, 5E, 31, 6B, 57, 33, CE, 2B),
BYTES_TO_WORDS_8(16, 9E, 0F, 7C, 4A, EB, E7, 8E),
BYTES_TO_WORDS_8(9B, 7F, 1A, FE, E2, 42, E3, 4F)
}, {
BYTES_TO_WORDS_8(4B, 60, D2, 27, 3E, 3C, CE, 3B),
BYTES_TO_WORDS_8(F6, B0, 53, CC, B0, 06, 1D, 65),
BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3),
BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A)
},
&double_jacobian_default,
&x_side_default,
&vli_mmod_fast_secp256r1
};
uECC_Curve uECC_secp256r1(void);
/*
* @brief Generates a random integer in the range 0 < random < top.
* Both random and top have num_words words.
* @param random OUT -- random integer in the range 0 < random < top
* @param top IN -- upper limit
* @param num_words IN -- number of words
* @return a random integer in the range 0 < random < top
*/
int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top,
wordcount_t num_words);
/* uECC_RNG_Function type
* The RNG function should fill 'size' random bytes into 'dest'. It should
* return 1 if 'dest' was filled with random data, or 0 if the random data could
* not be generated. The filled-in values should be either truly random, or from
* a cryptographically-secure PRNG.
*
* A correctly functioning RNG function must be set (using uECC_set_rng())
* before calling uECC_make_key() or uECC_sign().
*
* Setting a correctly functioning RNG function improves the resistance to
* side-channel attacks for uECC_shared_secret().
*
* A correct RNG function is set by default. If you are building on another
* POSIX-compliant system that supports /dev/random or /dev/urandom, you can
* define uECC_POSIX to use the predefined RNG.
*/
typedef int(*uECC_RNG_Function)(uint8_t *dest, unsigned int size);
/*
* @brief Set the function that will be used to generate random bytes. The RNG
* function should return 1 if the random data was generated, or 0 if the random
* data could not be generated.
*
* @note On platforms where there is no predefined RNG function, this must be
* called before uECC_make_key() or uECC_sign() are used.
*
* @param rng_function IN -- function that will be used to generate random bytes
*/
void uECC_set_rng(uECC_RNG_Function rng_function);
/*
* @brief provides current uECC_RNG_Function.
* @return Returns the function that will be used to generate random bytes.
*/
uECC_RNG_Function uECC_get_rng(void);
/*
* @brief computes the size of a private key for the curve in bytes.
* @param curve IN -- elliptic curve
* @return size of a private key for the curve in bytes.
*/
int uECC_curve_private_key_size(uECC_Curve curve);
/*
* @brief computes the size of a public key for the curve in bytes.
* @param curve IN -- elliptic curve
* @return the size of a public key for the curve in bytes.
*/
int uECC_curve_public_key_size(uECC_Curve curve);
/*
* @brief Compute the corresponding public key for a private key.
* @param private_key IN -- The private key to compute the public key for
* @param public_key OUT -- Will be filled in with the corresponding public key
* @param curve
* @return Returns 1 if key was computed successfully, 0 if an error occurred.
*/
int uECC_compute_public_key(const uint8_t *private_key,
uint8_t *public_key, uECC_Curve curve);
/*
* @brief Compute public-key.
* @return corresponding public-key.
* @param result OUT -- public-key
* @param private_key IN -- private-key
* @param curve IN -- elliptic curve
*/
uECC_word_t EccPoint_compute_public_key(uECC_word_t *result,
uECC_word_t *private_key, uECC_Curve curve);
/*
* @brief Regularize the bitcount for the private key so that attackers cannot
* use a side channel attack to learn the number of leading zeros.
* @return Regularized k
* @param k IN -- private-key
* @param k0 IN/OUT -- regularized k
* @param k1 IN/OUT -- regularized k
* @param curve IN -- elliptic curve
*/
uECC_word_t regularize_k(const uECC_word_t *const k, uECC_word_t *k0,
uECC_word_t *k1, uECC_Curve curve);
/*
* @brief Point multiplication algorithm using Montgomery's ladder with co-Z
* coordinates. See http://eprint.iacr.org/2011/338.pdf.
* @note Result may overlap point.
* @param result OUT -- returns scalar*point
* @param point IN -- elliptic curve point
* @param scalar IN -- scalar
* @param initial_Z IN -- initial value for z
* @param num_bits IN -- number of bits in scalar
* @param curve IN -- elliptic curve
*/
void EccPoint_mult(uECC_word_t *result, const uECC_word_t *point,
const uECC_word_t *scalar, const uECC_word_t *initial_Z,
bitcount_t num_bits, uECC_Curve curve);
/*
* @brief Constant-time comparison to zero - secure way to compare long integers
* @param vli IN -- very long integer
* @param num_words IN -- number of words in the vli
* @return 1 if vli == 0, 0 otherwise.
*/
uECC_word_t uECC_vli_isZero(const uECC_word_t *vli, wordcount_t num_words);
/*
* @brief Check if 'point' is the point at infinity
* @param point IN -- elliptic curve point
* @param curve IN -- elliptic curve
* @return if 'point' is the point at infinity, 0 otherwise.
*/
uECC_word_t EccPoint_isZero(const uECC_word_t *point, uECC_Curve curve);
/*
* @brief computes the sign of left - right, in constant time.
* @param left IN -- left term to be compared
* @param right IN -- right term to be compared
* @param num_words IN -- number of words
* @return the sign of left - right
*/
cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right,
wordcount_t num_words);
/*
* @brief computes sign of left - right, not in constant time.
* @note should not be used if inputs are part of a secret
* @param left IN -- left term to be compared
* @param right IN -- right term to be compared
* @param num_words IN -- number of words
* @return the sign of left - right
*/
cmpresult_t uECC_vli_cmp_unsafe(const uECC_word_t *left, const uECC_word_t *right,
wordcount_t num_words);
/*
* @brief Computes result = (left - right) % mod.
* @note Assumes that (left < mod) and (right < mod), and that result does not
* overlap mod.
* @param result OUT -- (left - right) % mod
* @param left IN -- leftright term in modular subtraction
* @param right IN -- right term in modular subtraction
* @param mod IN -- mod
* @param num_words IN -- number of words
*/
void uECC_vli_modSub(uECC_word_t *result, const uECC_word_t *left,
const uECC_word_t *right, const uECC_word_t *mod,
wordcount_t num_words);
/*
* @brief Computes P' = (x1', y1', Z3), P + Q = (x3, y3, Z3) or
* P => P', Q => P + Q
* @note assumes Input P = (x1, y1, Z), Q = (x2, y2, Z)
* @param X1 IN -- x coordinate of P
* @param Y1 IN -- y coordinate of P
* @param X2 IN -- x coordinate of Q
* @param Y2 IN -- y coordinate of Q
* @param curve IN -- elliptic curve
*/
void XYcZ_add(uECC_word_t *X1, uECC_word_t *Y1, uECC_word_t *X2,
uECC_word_t *Y2, uECC_Curve curve);
/*
* @brief Computes (x1 * z^2, y1 * z^3)
* @param X1 IN -- previous x1 coordinate
* @param Y1 IN -- previous y1 coordinate
* @param Z IN -- z value
* @param curve IN -- elliptic curve
*/
void apply_z(uECC_word_t *X1, uECC_word_t *Y1, const uECC_word_t *const Z,
uECC_Curve curve);
/*
* @brief Check if bit is set.
* @return Returns nonzero if bit 'bit' of vli is set.
* @warning It is assumed that the value provided in 'bit' is within the
* boundaries of the word-array 'vli'.
* @note The bit ordering layout assumed for vli is: {31, 30, ..., 0},
* {63, 62, ..., 32}, {95, 94, ..., 64}, {127, 126,..., 96} for a vli consisting
* of 4 uECC_word_t elements.
*/
uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit);
/*
* @brief Computes result = product % mod, where product is 2N words long.
* @param result OUT -- product % mod
* @param mod IN -- module
* @param num_words IN -- number of words
* @warning Currently only designed to work for curve_p or curve_n.
*/
void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product,
const uECC_word_t *mod, wordcount_t num_words);
/*
* @brief Computes modular product (using curve->mmod_fast)
* @param result OUT -- (left * right) mod % curve_p
* @param left IN -- left term in product
* @param right IN -- right term in product
* @param curve IN -- elliptic curve
*/
void uECC_vli_modMult_fast(uECC_word_t *result, const uECC_word_t *left,
const uECC_word_t *right, uECC_Curve curve);
/*
* @brief Computes result = left - right.
* @note Can modify in place.
* @param result OUT -- left - right
* @param left IN -- left term in subtraction
* @param right IN -- right term in subtraction
* @param num_words IN -- number of words
* @return borrow
*/
uECC_word_t uECC_vli_sub(uECC_word_t *result, const uECC_word_t *left,
const uECC_word_t *right, wordcount_t num_words);
/*
* @brief Constant-time comparison function(secure way to compare long ints)
* @param left IN -- left term in comparison
* @param right IN -- right term in comparison
* @param num_words IN -- number of words
* @return Returns 0 if left == right, 1 otherwise.
*/
uECC_word_t uECC_vli_equal(const uECC_word_t *left, const uECC_word_t *right,
wordcount_t num_words);
/*
* @brief Computes (left * right) % mod
* @param result OUT -- (left * right) % mod
* @param left IN -- left term in product
* @param right IN -- right term in product
* @param mod IN -- mod
* @param num_words IN -- number of words
*/
void uECC_vli_modMult(uECC_word_t *result, const uECC_word_t *left,
const uECC_word_t *right, const uECC_word_t *mod,
wordcount_t num_words);
/*
* @brief Computes (1 / input) % mod
* @note All VLIs are the same size.
* @note See "Euclid's GCD to Montgomery Multiplication to the Great Divide"
* @param result OUT -- (1 / input) % mod
* @param input IN -- value to be modular inverted
* @param mod IN -- mod
* @param num_words -- number of words
*/
void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
const uECC_word_t *mod, wordcount_t num_words);
/*
* @brief Sets dest = src.
* @param dest OUT -- destination buffer
* @param src IN -- origin buffer
* @param num_words IN -- number of words
*/
void uECC_vli_set(uECC_word_t *dest, const uECC_word_t *src,
wordcount_t num_words);
/*
* @brief Computes (left + right) % mod.
* @note Assumes that (left < mod) and right < mod), and that result does not
* overlap mod.
* @param result OUT -- (left + right) % mod.
* @param left IN -- left term in addition
* @param right IN -- right term in addition
* @param mod IN -- mod
* @param num_words IN -- number of words
*/
void uECC_vli_modAdd(uECC_word_t *result, const uECC_word_t *left,
const uECC_word_t *right, const uECC_word_t *mod,
wordcount_t num_words);
/*
* @brief Counts the number of bits required to represent vli.
* @param vli IN -- very long integer
* @param max_words IN -- number of words
* @return number of bits in given vli
*/
bitcount_t uECC_vli_numBits(const uECC_word_t *vli,
const wordcount_t max_words);
/*
* @brief Erases (set to 0) vli
* @param vli IN -- very long integer
* @param num_words IN -- number of words
*/
void uECC_vli_clear(uECC_word_t *vli, wordcount_t num_words);
/*
* @brief check if it is a valid point in the curve
* @param point IN -- point to be checked
* @param curve IN -- elliptic curve
* @return 0 if point is valid
* @exception returns -1 if it is a point at infinity
* @exception returns -2 if x or y is smaller than p,
* @exception returns -3 if y^2 != x^3 + ax + b.
*/
int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve);
/*
* @brief Check if a public key is valid.
* @param public_key IN -- The public key to be checked.
* @return returns 0 if the public key is valid
* @exception returns -1 if it is a point at infinity
* @exception returns -2 if x or y is smaller than p,
* @exception returns -3 if y^2 != x^3 + ax + b.
* @exception returns -4 if public key is the group generator.
*
* @note Note that you are not required to check for a valid public key before
* using any other uECC functions. However, you may wish to avoid spending CPU
* time computing a shared secret or verifying a signature using an invalid
* public key.
*/
int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve);
/*
* @brief Converts an integer in uECC native format to big-endian bytes.
* @param bytes OUT -- bytes representation
* @param num_bytes IN -- number of bytes
* @param native IN -- uECC native representation
*/
void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes,
const unsigned int *native);
/*
* @brief Converts big-endian bytes to an integer in uECC native format.
* @param native OUT -- uECC native representation
* @param bytes IN -- bytes representation
* @param num_bytes IN -- number of bytes
*/
void uECC_vli_bytesToNative(unsigned int *native, const uint8_t *bytes,
int num_bytes);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_UECC_H__ */

View File

@ -0,0 +1,131 @@
/* ecc_dh.h - TinyCrypt interface to EC-DH implementation */
/*
* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief -- Interface to EC-DH implementation.
*
* Overview: This software is an implementation of EC-DH. This implementation
* uses curve NIST p-256.
*
* Security: The curve NIST p-256 provides approximately 128 bits of security.
*/
#ifndef __BLE_MESH_TC_ECC_DH_H__
#define __BLE_MESH_TC_ECC_DH_H__
#include <tinycrypt/ecc.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Create a public/private key pair.
* @return returns TC_CRYPTO_SUCCESS (1) if the key pair was generated successfully
* returns TC_CRYPTO_FAIL (0) if error while generating key pair
*
* @param p_public_key OUT -- Will be filled in with the public key. Must be at
* least 2 * the curve size (in bytes) long. For curve secp256r1, p_public_key
* must be 64 bytes long.
* @param p_private_key OUT -- Will be filled in with the private key. Must be as
* long as the curve order (for secp256r1, p_private_key must be 32 bytes long).
*
* @note side-channel countermeasure: algorithm strengthened against timing
* attack.
* @warning A cryptographically-secure PRNG function must be set (using
* uECC_set_rng()) before calling uECC_make_key().
*/
int uECC_make_key(uint8_t *p_public_key, uint8_t *p_private_key, uECC_Curve curve);
#ifdef ENABLE_TESTS
/**
* @brief Create a public/private key pair given a specific d.
*
* @note THIS FUNCTION SHOULD BE CALLED ONLY FOR TEST PURPOSES. Refer to
* uECC_make_key() function for real applications.
*/
int uECC_make_key_with_d(uint8_t *p_public_key, uint8_t *p_private_key,
unsigned int *d, uECC_Curve curve);
#endif
/**
* @brief Compute a shared secret given your secret key and someone else's
* public key.
* @return returns TC_CRYPTO_SUCCESS (1) if the shared secret was computed successfully
* returns TC_CRYPTO_FAIL (0) otherwise
*
* @param p_secret OUT -- Will be filled in with the shared secret value. Must be
* the same size as the curve size (for curve secp256r1, secret must be 32 bytes
* long.
* @param p_public_key IN -- The public key of the remote party.
* @param p_private_key IN -- Your private key.
*
* @warning It is recommended to use the output of uECC_shared_secret() as the
* input of a recommended Key Derivation Function (see NIST SP 800-108) in
* order to produce a cryptographically secure symmetric key.
*/
int uECC_shared_secret(const uint8_t *p_public_key, const uint8_t *p_private_key,
uint8_t *p_secret, uECC_Curve curve);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_ECC_DH_H__ */

View File

@ -0,0 +1,139 @@
/* ecc_dh.h - TinyCrypt interface to EC-DSA implementation */
/*
* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief -- Interface to EC-DSA implementation.
*
* Overview: This software is an implementation of EC-DSA. This implementation
* uses curve NIST p-256.
*
* Security: The curve NIST p-256 provides approximately 128 bits of security.
*
* Usage: - To sign: Compute a hash of the data you wish to sign (SHA-2 is
* recommended) and pass it in to ecdsa_sign function along with your
* private key and a random number. You must use a new non-predictable
* random number to generate each new signature.
* - To verify a signature: Compute the hash of the signed data using
* the same hash as the signer and pass it to this function along with
* the signer's public key and the signature values (r and s).
*/
#ifndef __BLE_MESH_TC_ECC_DSA_H__
#define __BLE_MESH_TC_ECC_DSA_H__
#include <tinycrypt/ecc.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Generate an ECDSA signature for a given hash value.
* @return returns TC_CRYPTO_SUCCESS (1) if the signature generated successfully
* returns TC_CRYPTO_FAIL (0) if an error occurred.
*
* @param p_private_key IN -- Your private key.
* @param p_message_hash IN -- The hash of the message to sign.
* @param p_hash_size IN -- The size of p_message_hash in bytes.
* @param p_signature OUT -- Will be filled in with the signature value. Must be
* at least 2 * curve size long (for secp256r1, signature must be 64 bytes long).
*
* @warning A cryptographically-secure PRNG function must be set (using
* uECC_set_rng()) before calling uECC_sign().
* @note Usage: Compute a hash of the data you wish to sign (SHA-2 is
* recommended) and pass it in to this function along with your private key.
* @note side-channel countermeasure: algorithm strengthened against timing
* attack.
*/
int uECC_sign(const uint8_t *p_private_key, const uint8_t *p_message_hash,
unsigned p_hash_size, uint8_t *p_signature, uECC_Curve curve);
#ifdef ENABLE_TESTS
/*
* THIS FUNCTION SHOULD BE CALLED FOR TEST PURPOSES ONLY.
* Refer to uECC_sign() function for real applications.
*/
int uECC_sign_with_k(const uint8_t *private_key, const uint8_t *message_hash,
unsigned int hash_size, uECC_word_t *k, uint8_t *signature,
uECC_Curve curve);
#endif
/**
* @brief Verify an ECDSA signature.
* @return returns TC_SUCCESS (1) if the signature is valid
* returns TC_FAIL (0) if the signature is invalid.
*
* @param p_public_key IN -- The signer's public key.
* @param p_message_hash IN -- The hash of the signed data.
* @param p_hash_size IN -- The size of p_message_hash in bytes.
* @param p_signature IN -- The signature values.
*
* @note Usage: Compute the hash of the signed data using the same hash as the
* signer and pass it to this function along with the signer's public key and
* the signature values (hash_size and signature).
*/
int uECC_verify(const uint8_t *p_public_key, const uint8_t *p_message_hash,
unsigned int p_hash_size, const uint8_t *p_signature, uECC_Curve curve);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_ECC_DSA_H__ */

View File

@ -0,0 +1,81 @@
/* uECC_platform_specific.h - Interface to platform specific functions*/
/* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.*/
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* uECC_platform_specific.h -- Interface to platform specific functions
*/
#ifndef __BLE_MESH_UECC_PLATFORM_SPECIFIC_H_
#define __BLE_MESH_UECC_PLATFORM_SPECIFIC_H_
/*
* The RNG function should fill 'size' random bytes into 'dest'. It should
* return 1 if 'dest' was filled with random data, or 0 if the random data could
* not be generated. The filled-in values should be either truly random, or from
* a cryptographically-secure PRNG.
*
* A cryptographically-secure PRNG function must be set (using uECC_set_rng())
* before calling uECC_make_key() or uECC_sign().
*
* Setting a cryptographically-secure PRNG function improves the resistance to
* side-channel attacks for uECC_shared_secret().
*
* A correct PRNG function is set by default (default_RNG_defined = 1) and works
* for some platforms, such as Unix and Linux. For other platforms, you may need
* to provide another PRNG function.
*/
#define default_RNG_defined 0
int default_CSPRNG(uint8_t *dest, unsigned int size);
#endif /* __BLE_MESH_UECC_PLATFORM_SPECIFIC_H_ */

View File

@ -0,0 +1,139 @@
/* hmac.h - TinyCrypt interface to an HMAC implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to an HMAC implementation.
*
* Overview: HMAC is a message authentication code based on hash functions.
* TinyCrypt hard codes SHA-256 as the hash function. A message
* authentication code based on hash functions is also called a
* keyed cryptographic hash function since it performs a
* transformation specified by a key in an arbitrary length data
* set into a fixed length data set (also called tag).
*
* Security: The security of the HMAC depends on the length of the key and
* on the security of the hash function. Note that HMAC primitives
* are much less affected by collision attacks than their
* corresponding hash functions.
*
* Requires: SHA-256
*
* Usage: 1) call tc_hmac_set_key to set the HMAC key.
*
* 2) call tc_hmac_init to initialize a struct hash_state before
* processing the data.
*
* 3) call tc_hmac_update to process the next input segment;
* tc_hmac_update can be called as many times as needed to process
* all of the segments of the input; the order is important.
*
* 4) call tc_hmac_final to out put the tag.
*/
#ifndef __BLE_MESH_TC_HMAC_H__
#define __BLE_MESH_TC_HMAC_H__
#include <tinycrypt/sha256.h>
#ifdef __cplusplus
extern "C" {
#endif
struct tc_hmac_state_struct {
/* the internal state required by h */
struct tc_sha256_state_struct hash_state;
/* HMAC key schedule */
uint8_t key[2 * TC_SHA256_BLOCK_SIZE];
};
typedef struct tc_hmac_state_struct *TCHmacState_t;
/**
* @brief HMAC set key procedure
* Configures ctx to use key
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if
* ctx == NULL or
* key == NULL or
* key_size == 0
* @param ctx IN/OUT -- the struct tc_hmac_state_struct to initial
* @param key IN -- the HMAC key to configure
* @param key_size IN -- the HMAC key size
*/
int tc_hmac_set_key(TCHmacState_t ctx, const uint8_t *key,
unsigned int key_size);
/**
* @brief HMAC init procedure
* Initializes ctx to begin the next HMAC operation
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if: ctx == NULL or key == NULL
* @param ctx IN/OUT -- struct tc_hmac_state_struct buffer to init
*/
int tc_hmac_init(TCHmacState_t ctx);
/**
* @brief HMAC update procedure
* Mixes data_length bytes addressed by data into state
* @return returns TC_CRYPTO_SUCCCESS (1)
* returns TC_CRYPTO_FAIL (0) if: ctx == NULL or key == NULL
* @note Assumes state has been initialized by tc_hmac_init
* @param ctx IN/OUT -- state of HMAC computation so far
* @param data IN -- data to incorporate into state
* @param data_length IN -- size of data in bytes
*/
int tc_hmac_update(TCHmacState_t ctx, const void *data,
unsigned int data_length);
/**
* @brief HMAC final procedure
* Writes the HMAC tag into the tag buffer
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* tag == NULL or
* ctx == NULL or
* key == NULL or
* taglen != TC_SHA256_DIGEST_SIZE
* @note ctx is erased before exiting. This should never be changed/removed.
* @note Assumes the tag bufer is at least sizeof(hmac_tag_size(state)) bytes
* state has been initialized by tc_hmac_init
* @param tag IN/OUT -- buffer to receive computed HMAC tag
* @param taglen IN -- size of tag in bytes
* @param ctx IN/OUT -- the HMAC state for computing tag
*/
int tc_hmac_final(uint8_t *tag, unsigned int taglen, TCHmacState_t ctx);
#ifdef __cplusplus
}
#endif
#endif /*__BLE_MESH_TC_HMAC_H__*/

View File

@ -0,0 +1,164 @@
/* hmac_prng.h - TinyCrypt interface to an HMAC-PRNG implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to an HMAC-PRNG implementation.
*
* Overview: A pseudo-random number generator (PRNG) generates a sequence
* of numbers that have a distribution close to the one expected
* for a sequence of truly random numbers. The NIST Special
* Publication 800-90A specifies several mechanisms to generate
* sequences of pseudo random numbers, including the HMAC-PRNG one
* which is based on HMAC. TinyCrypt implements HMAC-PRNG with
* certain modifications from the NIST SP 800-90A spec.
*
* Security: A cryptographically secure PRNG depends on the existence of an
* entropy source to provide a truly random seed as well as the
* security of the primitives used as the building blocks (HMAC and
* SHA256, for TinyCrypt).
*
* The NIST SP 800-90A standard tolerates a null personalization,
* while TinyCrypt requires a non-null personalization. This is
* because a personalization string (the host name concatenated
* with a time stamp, for example) is easily computed and might be
* the last line of defense against failure of the entropy source.
*
* Requires: - SHA-256
* - HMAC
*
* Usage: 1) call tc_hmac_prng_init to set the HMAC key and process the
* personalization data.
*
* 2) call tc_hmac_prng_reseed to process the seed and additional
* input.
*
* 3) call tc_hmac_prng_generate to out put the pseudo-random data.
*/
#ifndef __BLE_MESH_TC_HMAC_PRNG_H__
#define __BLE_MESH_TC_HMAC_PRNG_H__
#include <tinycrypt/sha256.h>
#include <tinycrypt/hmac.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TC_HMAC_PRNG_RESEED_REQ -1
struct tc_hmac_prng_struct {
/* the HMAC instance for this PRNG */
struct tc_hmac_state_struct h;
/* the PRNG key */
uint8_t key[TC_SHA256_DIGEST_SIZE];
/* PRNG state */
uint8_t v[TC_SHA256_DIGEST_SIZE];
/* calls to tc_hmac_prng_generate left before re-seed */
unsigned int countdown;
};
typedef struct tc_hmac_prng_struct *TCHmacPrng_t;
/**
* @brief HMAC-PRNG initialization procedure
* Initializes prng with personalization, disables tc_hmac_prng_generate
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* prng == NULL,
* personalization == NULL,
* plen > MAX_PLEN
* @note Assumes: - personalization != NULL.
* The personalization is a platform unique string (e.g., the host
* name) and is the last line of defense against failure of the
* entropy source
* @warning NIST SP 800-90A specifies 3 items as seed material during
* initialization: entropy seed, personalization, and an optional
* nonce. TinyCrypts requires instead a non-null personalization
* (which is easily computed) and indirectly requires an entropy
* seed (since the reseed function is mandatorily called after
* init)
* @param prng IN/OUT -- the PRNG state to initialize
* @param personalization IN -- personalization string
* @param plen IN -- personalization length in bytes
*/
int tc_hmac_prng_init(TCHmacPrng_t prng,
const uint8_t *personalization,
unsigned int plen);
/**
* @brief HMAC-PRNG reseed procedure
* Mixes seed into prng, enables tc_hmac_prng_generate
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* prng == NULL,
* seed == NULL,
* seedlen < MIN_SLEN,
* seendlen > MAX_SLEN,
* additional_input != (const uint8_t *) 0 && additionallen == 0,
* additional_input != (const uint8_t *) 0 && additionallen > MAX_ALEN
* @note Assumes:- tc_hmac_prng_init has been called for prng
* - seed has sufficient entropy.
*
* @param prng IN/OUT -- the PRNG state
* @param seed IN -- entropy to mix into the prng
* @param seedlen IN -- length of seed in bytes
* @param additional_input IN -- additional input to the prng
* @param additionallen IN -- additional input length in bytes
*/
int tc_hmac_prng_reseed(TCHmacPrng_t prng, const uint8_t *seed,
unsigned int seedlen, const uint8_t *additional_input,
unsigned int additionallen);
/**
* @brief HMAC-PRNG generate procedure
* Generates outlen pseudo-random bytes into out buffer, updates prng
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_HMAC_PRNG_RESEED_REQ (-1) if a reseed is needed
* returns TC_CRYPTO_FAIL (0) if:
* out == NULL,
* prng == NULL,
* outlen == 0,
* outlen >= MAX_OUT
* @note Assumes tc_hmac_prng_init has been called for prng
* @param out IN/OUT -- buffer to receive output
* @param outlen IN -- size of out buffer in bytes
* @param prng IN/OUT -- the PRNG state
*/
int tc_hmac_prng_generate(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_HMAC_PRNG_H__ */

View File

@ -0,0 +1,129 @@
/* sha256.h - TinyCrypt interface to a SHA-256 implementation */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to a SHA-256 implementation.
*
* Overview: SHA-256 is a NIST approved cryptographic hashing algorithm
* specified in FIPS 180. A hash algorithm maps data of arbitrary
* size to data of fixed length.
*
* Security: SHA-256 provides 128 bits of security against collision attacks
* and 256 bits of security against pre-image attacks. SHA-256 does
* NOT behave like a random oracle, but it can be used as one if
* the string being hashed is prefix-free encoded before hashing.
*
* Usage: 1) call tc_sha256_init to initialize a struct
* tc_sha256_state_struct before hashing a new string.
*
* 2) call tc_sha256_update to hash the next string segment;
* tc_sha256_update can be called as many times as needed to hash
* all of the segments of a string; the order is important.
*
* 3) call tc_sha256_final to out put the digest from a hashing
* operation.
*/
#ifndef __BLE_MESH_TC_SHA256_H__
#define __BLE_MESH_TC_SHA256_H__
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TC_SHA256_BLOCK_SIZE (64)
#define TC_SHA256_DIGEST_SIZE (32)
#define TC_SHA256_STATE_BLOCKS (TC_SHA256_DIGEST_SIZE/4)
struct tc_sha256_state_struct {
unsigned int iv[TC_SHA256_STATE_BLOCKS];
uint64_t bits_hashed;
uint8_t leftover[TC_SHA256_BLOCK_SIZE];
size_t leftover_offset;
};
typedef struct tc_sha256_state_struct *TCSha256State_t;
/**
* @brief SHA256 initialization procedure
* Initializes s
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if s == NULL
* @param s Sha256 state struct
*/
int tc_sha256_init(TCSha256State_t s);
/**
* @brief SHA256 update procedure
* Hashes data_length bytes addressed by data into state s
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* s == NULL,
* s->iv == NULL,
* data == NULL
* @note Assumes s has been initialized by tc_sha256_init
* @warning The state buffer 'leftover' is left in memory after processing
* If your application intends to have sensitive data in this
* buffer, remind to erase it after the data has been processed
* @param s Sha256 state struct
* @param data message to hash
* @param datalen length of message to hash
*/
int tc_sha256_update (TCSha256State_t s, const uint8_t *data, size_t datalen);
/**
* @brief SHA256 final procedure
* Inserts the completed hash computation into digest
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* s == NULL,
* s->iv == NULL,
* digest == NULL
* @note Assumes: s has been initialized by tc_sha256_init
* digest points to at least TC_SHA256_DIGEST_SIZE bytes
* @warning The state buffer 'leftover' is left in memory after processing
* If your application intends to have sensitive data in this
* buffer, remind to erase it after the data has been processed
* @param digest unsigned eight bit integer
* @param Sha256 state struct
*/
int tc_sha256_final(uint8_t *digest, TCSha256State_t s);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_SHA256_H__ */

View File

@ -0,0 +1,121 @@
/* utils.h - TinyCrypt interface to platform-dependent run-time operations */
/*
* Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief Interface to platform-dependent run-time operations.
*
*/
#ifndef __BLE_MESH_TC_UTILS_H__
#define __BLE_MESH_TC_UTILS_H__
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Copy the the buffer 'from' to the buffer 'to'.
* @return returns TC_CRYPTO_SUCCESS (1)
* returns TC_CRYPTO_FAIL (0) if:
* from_len > to_len.
*
* @param to OUT -- destination buffer
* @param to_len IN -- length of destination buffer
* @param from IN -- origin buffer
* @param from_len IN -- length of origin buffer
*/
unsigned int _copy(uint8_t *to, unsigned int to_len,
const uint8_t *from, unsigned int from_len);
/**
* @brief Set the value 'val' into the buffer 'to', 'len' times.
*
* @param to OUT -- destination buffer
* @param val IN -- value to be set in 'to'
* @param len IN -- number of times the value will be copied
*/
void _set(void *to, uint8_t val, unsigned int len);
/**
* @brief Set the value 'val' into the buffer 'to', 'len' times, in a way
* which does not risk getting optimized out by the compiler
* In cases where the compiler does not set __GNUC__ and where the
* optimization level removes the memset, it may be necessary to
* implement a _set_secure function and define the
* TINYCRYPT_ARCH_HAS_SET_SECURE, which then can ensure that the
* memset does not get optimized out.
*
* @param to OUT -- destination buffer
* @param val IN -- value to be set in 'to'
* @param len IN -- number of times the value will be copied
*/
#ifdef TINYCRYPT_ARCH_HAS_SET_SECURE
extern void _set_secure(void *to, uint8_t val, unsigned int len);
#else /* ! TINYCRYPT_ARCH_HAS_SET_SECURE */
static inline void _set_secure(void *to, uint8_t val, unsigned int len)
{
(void) memset(to, val, len);
#ifdef __GNUC__
__asm__ __volatile__("" :: "g"(to) : "memory");
#endif /* __GNUC__ */
}
#endif /* TINYCRYPT_ARCH_HAS_SET_SECURE */
/*
* @brief AES specific doubling function, which utilizes
* the finite field used by AES.
* @return Returns a^2
*
* @param a IN/OUT -- value to be doubled
*/
uint8_t _double_byte(uint8_t a);
/*
* @brief Constant-time algorithm to compare if two sequences of bytes are equal
* @return Returns 0 if equal, and non-zero otherwise
*
* @param a IN -- sequence of bytes a
* @param b IN -- sequence of bytes b
* @param size IN -- size of sequences a and b
*/
int _compare(const uint8_t *a, const uint8_t *b, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* __BLE_MESH_TC_UTILS_H__ */

View File

@ -0,0 +1,80 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ACCESS_H_
#define _ACCESS_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
/* bt_mesh_model.flags */
enum {
BLE_MESH_MOD_BIND_PENDING = BIT(0),
BLE_MESH_MOD_SUB_PENDING = BIT(1),
BLE_MESH_MOD_PUB_PENDING = BIT(2),
};
void bt_mesh_elem_register(struct bt_mesh_elem *elem, uint8_t count);
uint8_t bt_mesh_elem_count(void);
/* Find local element based on unicast or group address */
struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr);
uint16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, uint16_t addr);
bool bt_mesh_fixed_group_match(uint16_t addr);
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
struct bt_mesh_elem *elem,
bool vnd, bool primary,
void *user_data),
void *user_data);
int32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod);
void bt_mesh_comp_provision(uint16_t addr);
void bt_mesh_comp_unprovision(void);
uint16_t bt_mesh_primary_addr(void);
const struct bt_mesh_comp *bt_mesh_comp_get(void);
struct bt_mesh_model *bt_mesh_model_get(bool vnd, uint8_t elem_idx, uint8_t mod_idx);
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
int bt_mesh_comp_deregister(void);
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(uint8_t role, uint16_t net_idx);
const uint8_t *bt_mesh_tx_devkey_get(uint8_t role, uint16_t dst);
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(uint8_t role, uint16_t app_idx);
size_t bt_mesh_rx_netkey_size(void);
struct bt_mesh_subnet *bt_mesh_rx_netkey_get(size_t index);
size_t bt_mesh_rx_devkey_size(void);
const uint8_t *bt_mesh_rx_devkey_get(size_t index, uint16_t src);
size_t bt_mesh_rx_appkey_size(void);
struct bt_mesh_app_key *bt_mesh_rx_appkey_get(size_t index);
#ifdef __cplusplus
}
#endif
#endif /* _ACCESS_H_ */

View File

@ -0,0 +1,102 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ADV_H_
#define _ADV_H_
#include "mesh_access.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Maximum advertising data payload for a single data type */
#define BLE_MESH_ADV_DATA_SIZE 29
/* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
#define BLE_MESH_ADV_USER_DATA_SIZE 4
#define BLE_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
typedef struct bt_mesh_msg {
bool relay; /* Flag indicates if the packet is a relayed one */
void *arg; /* Pointer to the struct net_buf */
uint16_t src; /* Source address for relay packets */
uint16_t dst; /* Destination address for relay packets */
uint32_t timestamp; /* Timestamp recorded when the relay packet is posted to queue */
} bt_mesh_msg_t;
enum bt_mesh_adv_type {
BLE_MESH_ADV_PROV,
BLE_MESH_ADV_DATA,
BLE_MESH_ADV_BEACON,
BLE_MESH_ADV_URI,
BLE_MESH_ADV_BLE,
};
struct bt_mesh_adv {
const struct bt_mesh_send_cb *cb;
void *cb_data;
uint8_t type:3,
busy:1;
uint8_t xmit;
};
typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
/* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout);
typedef enum {
BLE_MESH_BUF_REF_EQUAL,
BLE_MESH_BUF_REF_SMALL,
BLE_MESH_BUF_REF_MAX,
} bt_mesh_buf_ref_flag_t;
void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
uint8_t ref_cmp, bt_mesh_buf_ref_flag_t flag);
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
bt_mesh_adv_alloc_t get_id,
enum bt_mesh_adv_type type,
uint8_t xmit, int32_t timeout);
void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool);
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data);
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout);
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data, uint16_t src, uint16_t dst);
uint16_t bt_mesh_get_stored_relay_count(void);
void bt_mesh_adv_update(void);
void bt_mesh_adv_init(void);
void bt_mesh_adv_deinit(void);
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data, uint8_t *index);
int bt_mesh_stop_ble_advertising(uint8_t index);
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
#ifdef __cplusplus
}
#endif
#endif /* _ADV_H_ */

View File

@ -0,0 +1,35 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BEACON_H_
#define _BEACON_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
void bt_mesh_beacon_enable(void);
void bt_mesh_beacon_disable(void);
void bt_mesh_beacon_ivu_initiator(bool enable);
void bt_mesh_beacon_recv(struct net_buf_simple *buf, int8_t rssi);
void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
struct net_buf_simple *buf);
void bt_mesh_beacon_init(void);
void bt_mesh_beacon_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _BEACON_H_ */

View File

@ -0,0 +1,174 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _CRYPTO_H_
#define _CRYPTO_H_
#include <string.h>
#include "mesh_buf.h"
#ifdef __cplusplus
extern "C" {
#endif
struct bt_mesh_sg {
const void *data;
size_t len;
};
int bt_mesh_aes_cmac(const uint8_t key[16], struct bt_mesh_sg *sg,
size_t sg_len, uint8_t mac[16]);
static inline int bt_mesh_aes_cmac_one(const uint8_t key[16], const void *m,
size_t len, uint8_t mac[16])
{
struct bt_mesh_sg sg = { m, len };
return bt_mesh_aes_cmac(key, &sg, 1, mac);
}
static inline bool bt_mesh_s1(const char *m, uint8_t salt[16])
{
const uint8_t zero[16] = { 0 };
return bt_mesh_aes_cmac_one(zero, m, strlen(m), salt);
}
int bt_mesh_k1(const uint8_t *ikm, size_t ikm_len, const uint8_t salt[16],
const char *info, uint8_t okm[16]);
#define bt_mesh_k1_str(ikm, ikm_len, salt_str, info, okm) \
({ \
const uint8_t salt[16] = salt_str; \
bt_mesh_k1(ikm, ikm_len, salt, info, okm); \
})
int bt_mesh_k2(const uint8_t n[16], const uint8_t *p, size_t p_len,
uint8_t net_id[1], uint8_t enc_key[16], uint8_t priv_key[16]);
int bt_mesh_k3(const uint8_t n[16], uint8_t out[8]);
int bt_mesh_k4(const uint8_t n[16], uint8_t out[1]);
int bt_mesh_id128(const uint8_t n[16], const char *s, uint8_t out[16]);
static inline int bt_mesh_id_resolving_key(const uint8_t net_key[16],
uint8_t resolving_key[16])
{
return bt_mesh_k1_str(net_key, 16, "smbt", "smbi", resolving_key);
}
static inline int bt_mesh_identity_key(const uint8_t net_key[16],
uint8_t identity_key[16])
{
return bt_mesh_id128(net_key, "nkik", identity_key);
}
static inline int bt_mesh_beacon_key(const uint8_t net_key[16],
uint8_t beacon_key[16])
{
return bt_mesh_id128(net_key, "nkbk", beacon_key);
}
int bt_mesh_beacon_auth(const uint8_t beacon_key[16], uint8_t flags,
const uint8_t net_id[16], uint32_t iv_index,
uint8_t auth[8]);
static inline int bt_mesh_app_id(const uint8_t app_key[16], uint8_t app_id[1])
{
return bt_mesh_k4(app_key, app_id);
}
static inline int bt_mesh_session_key(const uint8_t dhkey[32],
const uint8_t prov_salt[16],
uint8_t session_key[16])
{
return bt_mesh_k1(dhkey, 32, prov_salt, "prsk", session_key);
}
static inline int bt_mesh_prov_nonce(const uint8_t dhkey[32],
const uint8_t prov_salt[16],
uint8_t nonce[13])
{
uint8_t tmp[16];
int err;
err = bt_mesh_k1(dhkey, 32, prov_salt, "prsn", tmp);
if (!err) {
memcpy(nonce, tmp + 3, 13);
}
return err;
}
static inline int bt_mesh_dev_key(const uint8_t dhkey[32],
const uint8_t prov_salt[16],
uint8_t dev_key[16])
{
return bt_mesh_k1(dhkey, 32, prov_salt, "prdk", dev_key);
}
static inline int bt_mesh_prov_salt(const uint8_t conf_salt[16],
const uint8_t prov_rand[16],
const uint8_t dev_rand[16],
uint8_t prov_salt[16])
{
const uint8_t prov_salt_key[16] = { 0 };
struct bt_mesh_sg sg[] = {
{ conf_salt, 16 },
{ prov_rand, 16 },
{ dev_rand, 16 },
};
return bt_mesh_aes_cmac(prov_salt_key, sg, ARRAY_SIZE(sg), prov_salt);
}
int bt_mesh_net_obfuscate(uint8_t *pdu, uint32_t iv_index,
const uint8_t privacy_key[16]);
int bt_mesh_net_encrypt(const uint8_t key[16], struct net_buf_simple *buf,
uint32_t iv_index, bool proxy);
int bt_mesh_net_decrypt(const uint8_t key[16], struct net_buf_simple *buf,
uint32_t iv_index, bool proxy);
int bt_mesh_app_encrypt(const uint8_t key[16], bool dev_key, uint8_t aszmic,
struct net_buf_simple *buf, const uint8_t *ad,
uint16_t src, uint16_t dst, uint32_t seq_num, uint32_t iv_index);
int bt_mesh_app_decrypt(const uint8_t key[16], bool dev_key, uint8_t aszmic,
struct net_buf_simple *buf, struct net_buf_simple *out,
const uint8_t *ad, uint16_t src, uint16_t dst, uint32_t seq_num,
uint32_t iv_index);
uint8_t bt_mesh_fcs_calc(const uint8_t *data, uint8_t data_len);
bool bt_mesh_fcs_check(struct net_buf_simple *buf, uint8_t received_fcs);
int bt_mesh_virtual_addr(const uint8_t virtual_label[16], uint16_t *addr);
int bt_mesh_prov_conf_salt(const uint8_t conf_inputs[145], uint8_t salt[16]);
int bt_mesh_prov_conf_key(const uint8_t dhkey[32], const uint8_t conf_salt[16],
uint8_t conf_key[16]);
int bt_mesh_prov_conf(const uint8_t conf_key[16], const uint8_t rand[16],
const uint8_t auth[16], uint8_t conf[16]);
int bt_mesh_prov_decrypt(const uint8_t key[16], uint8_t nonce[13],
const uint8_t data[25 + 8], uint8_t out[25]);
int bt_mesh_prov_encrypt(const uint8_t key[16], uint8_t nonce[13],
const uint8_t data[25], uint8_t out[33]);
#ifdef __cplusplus
}
#endif
#endif /* _CRYPTO_H_ */

View File

@ -0,0 +1,36 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _FAST_PROV_H_
#define _FAST_PROV_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
const uint8_t *bt_mesh_fast_prov_dev_key_get(uint16_t dst);
struct bt_mesh_subnet *bt_mesh_fast_prov_subnet_get(uint16_t net_idx);
struct bt_mesh_app_key *bt_mesh_fast_prov_app_key_find(uint16_t app_idx);
uint8_t bt_mesh_set_fast_prov_net_idx(uint16_t net_idx);
uint8_t bt_mesh_fast_prov_net_key_add(const uint8_t net_key[16]);
const uint8_t *bt_mesh_fast_prov_net_key_get(uint16_t net_idx);
const uint8_t *bt_mesh_get_fast_prov_app_key(uint16_t net_idx, uint16_t app_idx);
uint8_t bt_mesh_set_fast_prov_action(uint8_t action);
#ifdef __cplusplus
}
#endif
#endif /* _FAST_PROV_H_ */

View File

@ -0,0 +1,183 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _FOUNDATION_H_
#define _FOUNDATION_H_
#include "mesh_byteorder.h"
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OP_APP_KEY_ADD BLE_MESH_MODEL_OP_1(0x00)
#define OP_APP_KEY_UPDATE BLE_MESH_MODEL_OP_1(0x01)
#define OP_DEV_COMP_DATA_STATUS BLE_MESH_MODEL_OP_1(0x02)
#define OP_MOD_PUB_SET BLE_MESH_MODEL_OP_1(0x03)
#define OP_HEALTH_CURRENT_STATUS BLE_MESH_MODEL_OP_1(0x04)
#define OP_HEALTH_FAULT_STATUS BLE_MESH_MODEL_OP_1(0x05)
#define OP_HEARTBEAT_PUB_STATUS BLE_MESH_MODEL_OP_1(0x06)
#define OP_APP_KEY_DEL BLE_MESH_MODEL_OP_2(0x80, 0x00)
#define OP_APP_KEY_GET BLE_MESH_MODEL_OP_2(0x80, 0x01)
#define OP_APP_KEY_LIST BLE_MESH_MODEL_OP_2(0x80, 0x02)
#define OP_APP_KEY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x03)
#define OP_ATTENTION_GET BLE_MESH_MODEL_OP_2(0x80, 0x04)
#define OP_ATTENTION_SET BLE_MESH_MODEL_OP_2(0x80, 0x05)
#define OP_ATTENTION_SET_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x06)
#define OP_ATTENTION_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x07)
#define OP_DEV_COMP_DATA_GET BLE_MESH_MODEL_OP_2(0x80, 0x08)
#define OP_BEACON_GET BLE_MESH_MODEL_OP_2(0x80, 0x09)
#define OP_BEACON_SET BLE_MESH_MODEL_OP_2(0x80, 0x0a)
#define OP_BEACON_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x0b)
#define OP_DEFAULT_TTL_GET BLE_MESH_MODEL_OP_2(0x80, 0x0c)
#define OP_DEFAULT_TTL_SET BLE_MESH_MODEL_OP_2(0x80, 0x0d)
#define OP_DEFAULT_TTL_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x0e)
#define OP_FRIEND_GET BLE_MESH_MODEL_OP_2(0x80, 0x0f)
#define OP_FRIEND_SET BLE_MESH_MODEL_OP_2(0x80, 0x10)
#define OP_FRIEND_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x11)
#define OP_GATT_PROXY_GET BLE_MESH_MODEL_OP_2(0x80, 0x12)
#define OP_GATT_PROXY_SET BLE_MESH_MODEL_OP_2(0x80, 0x13)
#define OP_GATT_PROXY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x14)
#define OP_KRP_GET BLE_MESH_MODEL_OP_2(0x80, 0x15)
#define OP_KRP_SET BLE_MESH_MODEL_OP_2(0x80, 0x16)
#define OP_KRP_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x17)
#define OP_MOD_PUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x18)
#define OP_MOD_PUB_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x19)
#define OP_MOD_PUB_VA_SET BLE_MESH_MODEL_OP_2(0x80, 0x1a)
#define OP_MOD_SUB_ADD BLE_MESH_MODEL_OP_2(0x80, 0x1b)
#define OP_MOD_SUB_DEL BLE_MESH_MODEL_OP_2(0x80, 0x1c)
#define OP_MOD_SUB_DEL_ALL BLE_MESH_MODEL_OP_2(0x80, 0x1d)
#define OP_MOD_SUB_OVERWRITE BLE_MESH_MODEL_OP_2(0x80, 0x1e)
#define OP_MOD_SUB_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x1f)
#define OP_MOD_SUB_VA_ADD BLE_MESH_MODEL_OP_2(0x80, 0x20)
#define OP_MOD_SUB_VA_DEL BLE_MESH_MODEL_OP_2(0x80, 0x21)
#define OP_MOD_SUB_VA_OVERWRITE BLE_MESH_MODEL_OP_2(0x80, 0x22)
#define OP_NET_TRANSMIT_GET BLE_MESH_MODEL_OP_2(0x80, 0x23)
#define OP_NET_TRANSMIT_SET BLE_MESH_MODEL_OP_2(0x80, 0x24)
#define OP_NET_TRANSMIT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x25)
#define OP_RELAY_GET BLE_MESH_MODEL_OP_2(0x80, 0x26)
#define OP_RELAY_SET BLE_MESH_MODEL_OP_2(0x80, 0x27)
#define OP_RELAY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x28)
#define OP_MOD_SUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x29)
#define OP_MOD_SUB_LIST BLE_MESH_MODEL_OP_2(0x80, 0x2a)
#define OP_MOD_SUB_GET_VND BLE_MESH_MODEL_OP_2(0x80, 0x2b)
#define OP_MOD_SUB_LIST_VND BLE_MESH_MODEL_OP_2(0x80, 0x2c)
#define OP_LPN_TIMEOUT_GET BLE_MESH_MODEL_OP_2(0x80, 0x2d)
#define OP_LPN_TIMEOUT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x2e)
#define OP_HEALTH_FAULT_CLEAR BLE_MESH_MODEL_OP_2(0x80, 0x2f)
#define OP_HEALTH_FAULT_CLEAR_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x30)
#define OP_HEALTH_FAULT_GET BLE_MESH_MODEL_OP_2(0x80, 0x31)
#define OP_HEALTH_FAULT_TEST BLE_MESH_MODEL_OP_2(0x80, 0x32)
#define OP_HEALTH_FAULT_TEST_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x33)
#define OP_HEALTH_PERIOD_GET BLE_MESH_MODEL_OP_2(0x80, 0x34)
#define OP_HEALTH_PERIOD_SET BLE_MESH_MODEL_OP_2(0x80, 0x35)
#define OP_HEALTH_PERIOD_SET_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x36)
#define OP_HEALTH_PERIOD_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x37)
#define OP_HEARTBEAT_PUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x38)
#define OP_HEARTBEAT_PUB_SET BLE_MESH_MODEL_OP_2(0x80, 0x39)
#define OP_HEARTBEAT_SUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x3a)
#define OP_HEARTBEAT_SUB_SET BLE_MESH_MODEL_OP_2(0x80, 0x3b)
#define OP_HEARTBEAT_SUB_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x3c)
#define OP_MOD_APP_BIND BLE_MESH_MODEL_OP_2(0x80, 0x3d)
#define OP_MOD_APP_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x3e)
#define OP_MOD_APP_UNBIND BLE_MESH_MODEL_OP_2(0x80, 0x3f)
#define OP_NET_KEY_ADD BLE_MESH_MODEL_OP_2(0x80, 0x40)
#define OP_NET_KEY_DEL BLE_MESH_MODEL_OP_2(0x80, 0x41)
#define OP_NET_KEY_GET BLE_MESH_MODEL_OP_2(0x80, 0x42)
#define OP_NET_KEY_LIST BLE_MESH_MODEL_OP_2(0x80, 0x43)
#define OP_NET_KEY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x44)
#define OP_NET_KEY_UPDATE BLE_MESH_MODEL_OP_2(0x80, 0x45)
#define OP_NODE_IDENTITY_GET BLE_MESH_MODEL_OP_2(0x80, 0x46)
#define OP_NODE_IDENTITY_SET BLE_MESH_MODEL_OP_2(0x80, 0x47)
#define OP_NODE_IDENTITY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x48)
#define OP_NODE_RESET BLE_MESH_MODEL_OP_2(0x80, 0x49)
#define OP_NODE_RESET_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x4a)
#define OP_SIG_MOD_APP_GET BLE_MESH_MODEL_OP_2(0x80, 0x4b)
#define OP_SIG_MOD_APP_LIST BLE_MESH_MODEL_OP_2(0x80, 0x4c)
#define OP_VND_MOD_APP_GET BLE_MESH_MODEL_OP_2(0x80, 0x4d)
#define OP_VND_MOD_APP_LIST BLE_MESH_MODEL_OP_2(0x80, 0x4e)
#define STATUS_SUCCESS 0x00
#define STATUS_INVALID_ADDRESS 0x01
#define STATUS_INVALID_MODEL 0x02
#define STATUS_INVALID_APPKEY 0x03
#define STATUS_INVALID_NETKEY 0x04
#define STATUS_INSUFF_RESOURCES 0x05
#define STATUS_IDX_ALREADY_STORED 0x06
#define STATUS_NVAL_PUB_PARAM 0x07
#define STATUS_NOT_SUB_MOD 0x08
#define STATUS_STORAGE_FAIL 0x09
#define STATUS_FEAT_NOT_SUPP 0x0a
#define STATUS_CANNOT_UPDATE 0x0b
#define STATUS_CANNOT_REMOVE 0x0c
#define STATUS_CANNOT_BIND 0x0d
#define STATUS_TEMP_STATE_CHG_FAIL 0x0e
#define STATUS_CANNOT_SET 0x0f
#define STATUS_UNSPECIFIED 0x10
#define STATUS_INVALID_BINDING 0x11
enum {
BLE_MESH_VA_CHANGED, /* Label information changed */
};
struct label {
uint16_t ref;
uint16_t addr;
uint8_t uuid[16];
bt_mesh_atomic_t flags[1];
};
void bt_mesh_mod_sub_reset(bool store);
void bt_mesh_cfg_reset(bool store);
void bt_mesh_heartbeat(uint16_t src, uint16_t dst, uint8_t hops, uint16_t feat);
void bt_mesh_attention(struct bt_mesh_model *model, uint8_t time);
struct label *get_label(uint16_t index);
uint8_t *bt_mesh_label_uuid_get(uint16_t addr);
struct bt_mesh_hb_pub *bt_mesh_hb_pub_get(void);
void bt_mesh_hb_pub_disable(void);
struct bt_mesh_cfg_srv *bt_mesh_cfg_get(void);
uint8_t bt_mesh_net_transmit_get(void);
uint8_t bt_mesh_relay_get(void);
uint8_t bt_mesh_friend_get(void);
uint8_t bt_mesh_relay_retransmit_get(void);
uint8_t bt_mesh_beacon_get(void);
uint8_t bt_mesh_gatt_proxy_get(void);
uint8_t bt_mesh_default_ttl_get(void);
void bt_mesh_subnet_del(struct bt_mesh_subnet *sub, bool store);
struct bt_mesh_app_key *bt_mesh_app_key_alloc(uint16_t app_idx);
void bt_mesh_app_key_del(struct bt_mesh_app_key *key, bool store);
static inline void key_idx_pack(struct net_buf_simple *buf,
uint16_t idx1, uint16_t idx2)
{
net_buf_simple_add_le16(buf, idx1 | ((idx2 & 0x00f) << 12));
net_buf_simple_add_u8(buf, idx2 >> 4);
}
static inline void key_idx_unpack(struct net_buf_simple *buf,
uint16_t *idx1, uint16_t *idx2)
{
*idx1 = sys_get_le16(&buf->data[0]) & 0xfff;
*idx2 = sys_get_le16(&buf->data[1]) >> 4;
net_buf_simple_pull(buf, 3);
}
#ifdef __cplusplus
}
#endif
#endif /* _FOUNDATION_H_ */

View File

@ -0,0 +1,67 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _FRIEND_H_
#define _FRIEND_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
enum bt_mesh_friend_pdu_type {
BLE_MESH_FRIEND_PDU_SINGLE,
BLE_MESH_FRIEND_PDU_PARTIAL,
BLE_MESH_FRIEND_PDU_COMPLETE,
};
bool bt_mesh_friend_match(uint16_t net_idx, uint16_t addr);
struct bt_mesh_friend *bt_mesh_friend_find(uint16_t net_idx, uint16_t lpn_addr,
bool valid, bool established);
bool bt_mesh_friend_queue_has_space(uint16_t net_idx, uint16_t src, uint16_t dst,
const uint64_t *seq_auth, uint8_t seg_count);
void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx,
enum bt_mesh_friend_pdu_type type,
const uint64_t *seq_auth, uint8_t seg_count,
struct net_buf_simple *sbuf);
bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx,
enum bt_mesh_friend_pdu_type type,
const uint64_t *seq_auth, uint8_t seg_count,
struct net_buf_simple *sbuf);
void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, uint16_t src,
uint16_t dst, const uint64_t *seq_auth);
void bt_mesh_friend_sec_update(uint16_t net_idx);
void bt_mesh_friend_clear_net_idx(uint16_t net_idx);
int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
int bt_mesh_friend_init(void);
int bt_mesh_friend_deinit(void);
void bt_mesh_friend_remove_lpn(uint16_t lpn_addr);
#ifdef __cplusplus
}
#endif
#endif /* _FRIEND_H_ */

View File

@ -0,0 +1,318 @@
/** @file
* @brief Bluetooth Mesh Configuration Client Model APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_CFG_CLI_H_
#define _BLE_MESH_CFG_CLI_H_
#include "client_common.h"
/**
* @brief Bluetooth Mesh
* @defgroup bt_mesh_cfg_cli Bluetooth Mesh Configuration Client Model
* @ingroup bt_mesh
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Config client model common structure */
typedef bt_mesh_client_user_data_t bt_mesh_config_client_t;
typedef bt_mesh_client_internal_data_t config_internal_data_t;
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 BLE_MESH_MODEL_CFG_CLI(cli_data) \
BLE_MESH_MODEL_CB(BLE_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(bt_mesh_client_common_param_t *param, uint8_t page);
int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_beacon_set(bt_mesh_client_common_param_t *param, uint8_t val);
int bt_mesh_cfg_ttl_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_ttl_set(bt_mesh_client_common_param_t *param, uint8_t val);
int bt_mesh_cfg_friend_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_friend_set(bt_mesh_client_common_param_t *param, uint8_t val);
int bt_mesh_cfg_gatt_proxy_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_gatt_proxy_set(bt_mesh_client_common_param_t *param, uint8_t val);
int bt_mesh_cfg_relay_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param,
uint8_t relay, uint8_t retransmit);
int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param,
uint16_t net_idx, const uint8_t net_key[16]);
int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param,
uint16_t net_idx, uint16_t app_idx,
const uint8_t app_key[16]);
int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t app_idx,
uint16_t mod_id, uint16_t cid);
struct bt_mesh_cfg_mod_pub {
uint16_t addr;
uint16_t app_idx;
bool cred_flag;
uint8_t ttl;
uint8_t period;
uint8_t transmit;
};
int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id, uint16_t cid,
struct bt_mesh_cfg_mod_pub *pub);
int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t sub_addr,
uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_sub_del(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t sub_addr,
uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_sub_overwrite(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t sub_addr,
uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, const uint8_t label[16],
uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_sub_va_del(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, const uint8_t label[16],
uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_sub_va_overwrite(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, const uint8_t label[16],
uint16_t mod_id, uint16_t cid);
struct bt_mesh_cfg_hb_sub {
uint16_t src;
uint16_t dst;
uint8_t period;
};
int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_hb_sub *sub);
int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param);
struct bt_mesh_cfg_hb_pub {
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(bt_mesh_client_common_param_t *param,
struct bt_mesh_cfg_hb_pub *pub);
int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param);
/* Configuration Client Status Message Context */
struct bt_mesh_cfg_comp_data_status {
uint8_t page;
struct net_buf_simple *comp_data;
};
struct bt_mesh_cfg_relay_status {
uint8_t relay;
uint8_t retransmit;
};
struct bt_mesh_cfg_netkey_status {
uint8_t status;
uint16_t net_idx;
};
struct bt_mesh_cfg_appkey_status {
uint8_t status;
uint16_t net_idx;
uint16_t app_idx;
};
struct bt_mesh_cfg_mod_app_status {
uint8_t status;
uint16_t elem_addr;
uint16_t app_idx;
uint16_t cid;
uint16_t mod_id;
};
struct bt_mesh_cfg_mod_pub_status {
uint8_t status;
uint16_t elem_addr;
uint16_t addr;
uint16_t app_idx;
bool cred_flag;
uint8_t ttl;
uint8_t period;
uint8_t transmit;
uint16_t cid;
uint16_t mod_id;
};
struct bt_mesh_cfg_mod_sub_status {
uint8_t status;
uint16_t elem_addr;
uint16_t sub_addr;
uint16_t cid;
uint16_t mod_id;
};
struct bt_mesh_cfg_hb_sub_status {
uint8_t status;
uint16_t src;
uint16_t dst;
uint8_t period;
uint8_t count;
uint8_t min;
uint8_t max;
};
struct bt_mesh_cfg_hb_pub_status {
uint8_t status;
uint16_t dst;
uint8_t count;
uint8_t period;
uint8_t ttl;
uint16_t feat;
uint16_t net_idx;
};
struct bt_mesh_cfg_mod_sub_list {
uint8_t status;
uint16_t elem_addr;
uint16_t cid;
uint16_t mod_id;
struct net_buf_simple *addr;
};
struct bt_mesh_cfg_net_key_list {
struct net_buf_simple *net_idx;
};
struct bt_mesh_cfg_app_key_list {
uint8_t status;
uint16_t net_idx;
struct net_buf_simple *app_idx;
};
struct bt_mesh_cfg_node_id_status {
uint8_t status;
uint16_t net_idx;
uint8_t identity;
};
struct bt_mesh_cfg_mod_app_list {
uint8_t status;
uint16_t elem_addr;
uint16_t cid;
uint16_t mod_id;
struct net_buf_simple *app_idx;
};
struct bt_mesh_cfg_key_refresh_status {
uint8_t status;
uint16_t net_idx;
uint8_t phase;
};
struct bt_mesh_cfg_lpn_pollto_status {
uint16_t lpn_addr;
int32_t timeout;
};
int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id,
uint16_t cid, const uint8_t label[16],
struct bt_mesh_cfg_mod_pub *pub);
int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id);
int bt_mesh_cfg_mod_sub_get_vnd(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param,
uint16_t net_idx, const uint8_t net_key[16]);
int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, uint16_t net_idx);
int bt_mesh_cfg_net_key_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param,
uint16_t net_idx, uint16_t app_idx,
const uint8_t app_key[16]);
int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param,
uint16_t net_idx, uint16_t app_idx);
int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, uint16_t net_idx);
int bt_mesh_cfg_node_identity_get(bt_mesh_client_common_param_t *param, uint16_t net_idx);
int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param,
uint16_t net_idx, uint8_t identity);
int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t app_idx,
uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id);
int bt_mesh_cfg_mod_app_get_vnd(bt_mesh_client_common_param_t *param,
uint16_t elem_addr, uint16_t mod_id, uint16_t cid);
int bt_mesh_cfg_kr_phase_get(bt_mesh_client_common_param_t *param, uint16_t net_idx);
int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param,
uint16_t net_idx, uint8_t transition);
int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, uint16_t lpn_addr);
int bt_mesh_cfg_net_transmit_get(bt_mesh_client_common_param_t *param);
int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, uint8_t transmit);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __BLE_MESH_CFG_CLI_H */

View File

@ -0,0 +1,223 @@
/** @file
* @brief Bluetooth Mesh Configuration Server Model APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_CFG_SRV_H_
#define _BLE_MESH_CFG_SRV_H_
#include "mesh_access.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;
uint8_t net_transmit; /* Network Transmit state */
uint8_t relay; /* Relay Mode state */
uint8_t relay_retransmit; /* Relay Retransmit state */
uint8_t beacon; /* Secure Network Beacon state */
uint8_t gatt_proxy; /* GATT Proxy state */
uint8_t frnd; /* Friend state */
uint8_t default_ttl; /* Default TTL */
/* Heartbeat Publication */
struct bt_mesh_hb_pub {
struct k_delayed_work timer;
uint16_t dst;
uint16_t count;
uint8_t period;
uint8_t ttl;
uint16_t feat;
uint16_t net_idx;
} hb_pub;
/* Heartbeat Subscription */
struct bt_mesh_hb_sub {
int64_t expiry;
uint16_t src;
uint16_t dst;
uint16_t count;
uint8_t min_hops;
uint8_t max_hops;
/* Optional subscription tracking function */
void (*func)(uint8_t hops, uint16_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 BLE_MESH_MODEL_CFG_SRV(srv_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_CFG_SRV, \
bt_mesh_cfg_srv_op, NULL, srv_data, &bt_mesh_cfg_srv_cb)
typedef union {
struct {
uint8_t beacon;
} cfg_beacon_set;
struct {
uint8_t ttl;
} cfg_default_ttl_set;
struct {
uint8_t gatt_proxy;
} cfg_gatt_proxy_set;
struct {
uint8_t relay;
uint8_t retransmit;
} cfg_relay_set;
struct {
uint16_t elem_addr;
uint16_t pub_addr;
uint16_t app_idx;
bool cred_flag;
uint8_t ttl;
uint8_t period;
uint8_t transmit;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_pub_set;
struct {
uint16_t elem_addr;
uint8_t pub_addr[16];
uint16_t app_idx;
bool cred_flag;
uint8_t ttl;
uint8_t period;
uint8_t transmit;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_pub_va_set;
struct {
uint16_t elem_addr;
uint16_t sub_addr;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_add;
struct {
uint16_t elem_addr;
uint8_t sub_addr[16];
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_va_add;
struct {
uint16_t elem_addr;
uint16_t sub_addr;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_delete;
struct {
uint16_t elem_addr;
uint8_t sub_addr[16];
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_va_delete;
struct {
uint16_t elem_addr;
uint16_t sub_addr;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_overwrite;
struct {
uint16_t elem_addr;
uint8_t sub_addr[16];
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_va_overwrite;
struct {
uint16_t elem_addr;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_sub_delete_all;
struct {
uint16_t net_idx;
uint8_t net_key[16];
} cfg_netkey_add;
struct {
uint16_t net_idx;
uint8_t net_key[16];
} cfg_netkey_update;
struct {
uint16_t net_idx;
} cfg_netkey_delete;
struct {
uint16_t net_idx;
uint16_t app_idx;
uint8_t app_key[16];
} cfg_appkey_add;
struct {
uint16_t net_idx;
uint16_t app_idx;
uint8_t app_key[16];
} cfg_appkey_update;
struct {
uint16_t net_idx;
uint16_t app_idx;
} cfg_appkey_delete;
struct {
uint16_t net_idx;
uint8_t identity;
} cfg_node_identity_set;
struct {
uint16_t elem_addr;
uint16_t app_idx;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_app_bind;
struct {
uint16_t elem_addr;
uint16_t app_idx;
uint16_t cid;
uint16_t mod_id;
} cfg_mod_app_unbind;
struct {
uint8_t frnd;
} cfg_friend_set;
struct {
uint16_t net_idx;
uint8_t kr_phase;
} cfg_kr_phase_set;
struct {
uint16_t dst;
uint8_t count;
uint8_t period;
uint8_t ttl;
uint16_t feat;
uint16_t net_idx;
} cfg_hb_pub_set;
struct {
uint16_t src;
uint16_t dst;
uint8_t period;
} cfg_hb_sub_set;
struct {
uint8_t transmit;
} cfg_net_transmit_set;
} bt_mesh_cfg_server_state_change_t;
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __BLE_MESH_CFG_SRV_H */

View File

@ -0,0 +1,78 @@
/** @file
* @brief Bluetooth Mesh Health Client Model APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_HEALTH_CLI_H_
#define _BLE_MESH_HEALTH_CLI_H_
#include "client_common.h"
/**
* @brief Bluetooth Mesh
* @defgroup bt_mesh_health_cli Bluetooth Mesh Health Client Model
* @ingroup bt_mesh
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/* Health client model common structure */
typedef bt_mesh_client_user_data_t bt_mesh_health_client_t;
typedef bt_mesh_client_internal_data_t health_internal_data_t;
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 BLE_MESH_MODEL_HEALTH_CLI(cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_HEALTH_CLI, \
bt_mesh_health_cli_op, NULL, cli_data, &bt_mesh_health_cli_cb)
int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, uint16_t cid);
int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param,
uint16_t cid, bool need_ack);
int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param,
uint16_t cid, uint8_t test_id, bool need_ack);
int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param);
int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param,
uint8_t divisor, bool need_ack);
int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param);
int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param,
uint8_t attention, bool need_ack);
/* Health Client Status Message Context */
struct bt_mesh_health_current_status {
uint8_t test_id;
uint16_t cid;
struct net_buf_simple *fault_array;
};
struct bt_mesh_health_fault_status {
uint8_t test_id;
uint16_t cid;
struct net_buf_simple *fault_array;
};
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __BLE_MESH_HEALTH_CLI_H */

View File

@ -0,0 +1,106 @@
/** @file
* @brief Bluetooth Mesh Health Server Model APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_HEALTH_SRV_H_
#define _BLE_MESH_HEALTH_SRV_H_
#include "mesh_access.h"
/**
* @brief Bluetooth Mesh Health Server Model
* @defgroup bt_mesh_health_srv Bluetooth Mesh Health Server Model
* @ingroup bt_mesh
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
struct bt_mesh_health_srv_cb {
/* Clear registered faults */
void (*fault_clear)(struct bt_mesh_model *model, uint16_t company_id);
/* Run a specific test */
void (*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, uint8_t time);
/* Attention off */
void (*attn_off)(struct bt_mesh_model *model);
};
/** @def BLE_MESH_HEALTH_PUB_DEFINE
*
* A helper to define a health publication context
*
* @param _name Name given to the publication context variable.
* @param _max_faults Maximum number of faults the element can have.
*/
#define BLE_MESH_HEALTH_PUB_DEFINE(_name, _max_faults) \
BLE_MESH_MODEL_PUB_DEFINE(_name, NULL, (1 + 3 + (_max_faults)))
struct bt_mesh_health_test {
uint8_t id_count; /* Number of Health self-test ID */
const uint8_t *test_ids; /* Array of Health self-test IDs */
uint16_t company_id; /* Company ID used to identify the Health Fault state */
uint8_t prev_test_id; /* Most currently performed test id */
uint8_t curr_faults[32]; /* Array of current faults */
uint8_t reg_faults[32]; /* Array of registered faults */
} __attribute__((packed));
/** Mesh Health Server Model Context */
struct bt_mesh_health_srv {
struct bt_mesh_model *model;
/* Optional callback struct */
struct bt_mesh_health_srv_cb cb;
/* Attention Timer state */
struct k_delayed_work attn_timer;
/* Attention Timer start flag */
bool attn_timer_start;
/* Health Server fault test */
struct bt_mesh_health_test test;
};
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 BLE_MESH_MODEL_HEALTH_SRV
*
* Define a new health server model. Note that this API needs to be
* repeated for each element which 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 BLE_MESH_MODEL_HEALTH_SRV(srv, pub) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_HEALTH_SRV, \
bt_mesh_health_srv_op, pub, srv, &bt_mesh_health_srv_cb)
int bt_mesh_fault_update(struct bt_mesh_elem *elem);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __BLE_MESH_HEALTH_SRV_H */

View File

@ -0,0 +1,601 @@
/** @file
* @brief Bluetooth Mesh Access Layer APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_ACCESS_H_
#define _BLE_MESH_ACCESS_H_
#include "mesh_config.h"
#include "mesh_buf.h"
#include "mesh_timer.h"
/**
* @brief Bluetooth Mesh Access Layer
* @defgroup bt_mesh_access Bluetooth Mesh Access Layer
* @ingroup bt_mesh
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_CID_NVAL 0xFFFF
#define BLE_MESH_ADDR_UNASSIGNED 0x0000
#define BLE_MESH_ADDR_ALL_NODES 0xffff
#define BLE_MESH_ADDR_PROXIES 0xfffc
#define BLE_MESH_ADDR_FRIENDS 0xfffd
#define BLE_MESH_ADDR_RELAYS 0xfffe
#define BLE_MESH_KEY_UNUSED 0xffff
#define BLE_MESH_KEY_DEV 0xfffe
/** Helper to define a mesh element within an array.
*
* In case the element has no SIG or Vendor models the helper
* macro BLE_MESH_MODEL_NONE can be given instead.
*
* @param _loc Location Descriptor.
* @param _mods Array of models.
* @param _vnd_mods Array of vendor models.
*/
#define BLE_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. */
uint16_t addr;
/* Location Descriptor (GATT Bluetooth Namespace Descriptors) */
const uint16_t loc;
const uint8_t model_count;
const uint8_t vnd_model_count;
struct bt_mesh_model *const models;
struct bt_mesh_model *const vnd_models;
};
/* Foundation Models */
#define BLE_MESH_MODEL_ID_CFG_SRV 0x0000
#define BLE_MESH_MODEL_ID_CFG_CLI 0x0001
#define BLE_MESH_MODEL_ID_HEALTH_SRV 0x0002
#define BLE_MESH_MODEL_ID_HEALTH_CLI 0x0003
/* Models from the Mesh Model Specification */
#define BLE_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
#define BLE_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001
#define BLE_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002
#define BLE_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003
#define BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004
#define BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005
#define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006
#define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007
#define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008
#define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009
#define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a
#define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b
#define BLE_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
#define BLE_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
#define BLE_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
#define BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV 0x100f
#define BLE_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
#define BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
#define BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
#define BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013
#define BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014
#define BLE_MESH_MODEL_ID_GEN_PROP_CLI 0x1015
#define BLE_MESH_MODEL_ID_SENSOR_SRV 0x1100
#define BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101
#define BLE_MESH_MODEL_ID_SENSOR_CLI 0x1102
#define BLE_MESH_MODEL_ID_TIME_SRV 0x1200
#define BLE_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201
#define BLE_MESH_MODEL_ID_TIME_CLI 0x1202
#define BLE_MESH_MODEL_ID_SCENE_SRV 0x1203
#define BLE_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204
#define BLE_MESH_MODEL_ID_SCENE_CLI 0x1205
#define BLE_MESH_MODEL_ID_SCHEDULER_SRV 0x1206
#define BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207
#define BLE_MESH_MODEL_ID_SCHEDULER_CLI 0x1208
#define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300
#define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301
#define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302
#define BLE_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303
#define BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304
#define BLE_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305
#define BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306
#define BLE_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307
#define BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308
#define BLE_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309
#define BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a
#define BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b
#define BLE_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c
#define BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
#define BLE_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
#define BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
#define BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
#define BLE_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. */
uint16_t net_idx;
/** AppKey Index to encrypt the message with. */
uint16_t app_idx;
/** Remote address. */
uint16_t addr;
/** Destination address of a received message. Not used for sending. */
uint16_t recv_dst;
/** RSSI of received packet. Not used for sending. */
int8_t recv_rssi;
/** Received TTL value. Not used for sending. */
uint8_t recv_ttl: 7;
/** Force sending reliably by using segment acknowledgement */
uint8_t send_rel: 1;
/** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */
uint8_t send_ttl;
/** Change by Espressif, opcode of a received message.
* Not used for sending message. */
uint32_t recv_op;
/** Change by Espressif, model corresponds to the message */
struct bt_mesh_model *model;
/** Change by Espressif, if the message is sent by a server
* model. Not used for receiving message. */
bool srv_send;
};
struct bt_mesh_model_op {
/* OpCode encoded using the BLE_MESH_MODEL_OP_* macros */
const uint32_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 net_buf_simple *buf);
};
#define BLE_MESH_MODEL_OP_1(b0) (b0)
#define BLE_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
#define BLE_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
#define BLE_MESH_MODEL_OP_END { 0, 0, NULL }
#define BLE_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
{ BLE_MESH_MODEL_OP_END })
/** Helper to define an empty model array */
#define BLE_MESH_MODEL_NONE ((struct bt_mesh_model []){})
/** Length of a short Mesh MIC. */
#define BLE_MESH_MIC_SHORT 4
/** Length of a long Mesh MIC. */
#define BLE_MESH_MIC_LONG 8
/** @def BLE_MESH_MODEL_OP_LEN
*
* @brief Helper to determine the length of an opcode.
*
* @param _op Opcode.
*/
#define BLE_MESH_MODEL_OP_LEN(_op) ((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)
/** @def BLE_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 BLE_MESH_MODEL_BUF_LEN(_op, _payload_len) \
(BLE_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BLE_MESH_MIC_SHORT)
/** @def BLE_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 BLE_MESH_MODEL_BUF_LEN_LONG_MIC(_op, _payload_len) \
(BLE_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BLE_MESH_MIC_LONG)
/** @def BLE_MESH_MODEL_BUF_DEFINE
*
* @brief Define a Mesh model message buffer using @ref NET_BUF_SIMPLE_DEFINE.
*
* @param _buf Buffer name.
* @param _op Opcode of the message.
* @param _payload_len Length of the model message payload.
*/
#define BLE_MESH_MODEL_BUF_DEFINE(_buf, _op, _payload_len) \
NET_BUF_SIMPLE_DEFINE(_buf, BLE_MESH_MODEL_BUF_LEN((_op), (_payload_len)))
/** @def BLE_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 BLE_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
{ \
.id = (_id), \
.op = (_op), \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
BLE_MESH_KEY_UNUSED }, \
.pub = (_pub), \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
BLE_MESH_ADDR_UNASSIGNED }, \
.user_data = (_user_data), \
.cb = (_cb), \
}
/** @def BLE_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 BLE_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
{ \
.vnd.company = (_company), \
.vnd.id = (_id), \
.op = (_op), \
.pub = (_pub), \
.keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \
BLE_MESH_KEY_UNUSED }, \
.groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \
BLE_MESH_ADDR_UNASSIGNED }, \
.user_data = (_user_data), \
.cb = (_cb), \
}
/** @def BLE_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
* 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 BLE_MESH_TRANSMIT(count, int_ms) ((count) | ((((int_ms) / 10) - 1) << 3))
/** @def BLE_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 BLE_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3)))
/** @def BLE_MESH_TRANSMIT_INT
*
* @brief Decode transmit interval from a transmit value.
*
* @param transmit Encoded transmit count & interval value.
*
* @return Transmission interval in milliseconds.
*/
#define BLE_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
/** @def BLE_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 BLE_MESH_PUB_TRANSMIT(count, int_ms) BLE_MESH_TRANSMIT((count), (int_ms) / 5)
/** @def BLE_MESH_PUB_TRANSMIT_COUNT
*
* @brief Decode Publish Retransmit count from a given value.
*
* @param transmit Encoded Publish Retransmit count & interval value.
*
* @return Retransmission count (actual transmissions is N + 1).
*/
#define BLE_MESH_PUB_TRANSMIT_COUNT(transmit) BLE_MESH_TRANSMIT_COUNT(transmit)
/** @def BLE_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 BLE_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;
uint16_t addr; /**< Publish Address. */
uint16_t key:12, /**< Publish AppKey Index. */
cred:1, /**< Friendship Credentials Flag. */
send_rel:1; /**< Force reliable sending (segment acks) */
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. */
fast_period:1, /**< Use FastPeriodDivisor */
count:3; /**< Retransmissions left. */
uint32_t period_start; /**< Start of the current period. */
/** @brief Publication buffer, containing the publication message.
*
* This will get correctly created when the publication context
* has been defined using the BLE_MESH_MODEL_PUB_DEFINE macro.
*
* BLE_MESH_MODEL_PUB_DEFINE(name, update, size);
*/
struct net_buf_simple *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.
*
* 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 belongs 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;
/* Change by Espressif, role of the device going to publish messages */
uint8_t dev_role;
};
/** @def BLE_MESH_MODEL_PUB_DEFINE
*
* Define a model publication context.
*
* @param _name Variable name given to the context.
* @param _update Optional message update callback (may be NULL).
* @param _msg_len Length of the publication message.
*/
#define BLE_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \
NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
static struct bt_mesh_model_pub _name = { \
.update = _update, \
.msg = &bt_mesh_pub_msg_##_name, \
}
/** Model callback functions. */
struct bt_mesh_model_cb {
/** @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.
*/
int (*const init)(struct bt_mesh_model *model);
#if CONFIG_BLE_MESH_DEINIT
/** @brief Model deinit callback.
*
* Called on every model instance during mesh deinitialization.
* All model data is deleted, and the model should clear its state.
*
* If any of the model deinit callbacks return an error, the mesh
* subsystem deinitialization will be aborted, and the error will
* be returned to the caller of @ref bt_mesh_deinit.
*
* @param model Model to be de-initialized.
*/
int (*const deinit)(struct bt_mesh_model *model);
#endif /* CONFIG_BLE_MESH_DEINIT */
};
/** Abstraction that describes a Mesh Model instance */
struct bt_mesh_model {
union {
const uint16_t id;
struct {
uint16_t company;
uint16_t id;
} vnd;
};
/* Internal information, mainly for persistent storage */
uint8_t elem_idx; /* Belongs to Nth element */
uint8_t model_idx; /* Is the Nth model in the element */
uint16_t flags; /* Information about what has changed */
/* The Element this Model belongs to */
struct bt_mesh_elem *elem;
/* Model Publication */
struct bt_mesh_model_pub *const pub;
/* AppKey List */
uint16_t keys[CONFIG_BLE_MESH_MODEL_KEY_COUNT];
/* Subscription List (group or virtual addresses) */
uint16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT];
/** Opcode handler list */
const struct bt_mesh_model_op *const op;
/** Model callback structure. */
const struct bt_mesh_model_cb *const cb;
/* Model-specific user data */
void *user_data;
};
struct bt_mesh_send_cb {
void (*start)(uint16_t duration, int err, void *cb_data);
void (*end)(int err, void *cb_data);
};
void bt_mesh_model_msg_init(struct net_buf_simple *msg, uint32_t opcode);
/** Special TTL value to request using configured default TTL */
#define BLE_MESH_TTL_DEFAULT 0xff
/** Maximum allowed TTL value */
#define BLE_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 net_buf_simple *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(struct bt_mesh_elem *elem, uint16_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(struct bt_mesh_elem *elem,
uint16_t company, uint16_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);
}
/** Node Composition */
struct bt_mesh_comp {
uint16_t cid;
uint16_t pid;
uint16_t vid;
size_t elem_count;
struct bt_mesh_elem *elem;
};
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __BLE_MESH_ACCESS_H */

View File

@ -0,0 +1,807 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_BEARER_ADAPT_H_
#define _BLE_MESH_BEARER_ADAPT_H_
#include <sys/types.h>
#include "mesh_config.h"
#include "mesh_types.h"
#include "mesh_util.h"
#include "mesh_uuid.h"
#include "mesh_buf.h"
#ifdef __cplusplus
extern "C" {
#endif
/* BLE Mesh Max Connection Count */
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
#endif
#ifdef CONFIG_BT_NIMBLE_ENABLED
#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
#endif
#define BLE_MESH_GAP_ADV_MAX_LEN 31
#define BLE_MESH_GATT_DEF_MTU_SIZE 23
/* BD ADDR types */
#define BLE_MESH_ADDR_PUBLIC 0x00
#define BLE_MESH_ADDR_RANDOM 0x01
#define BLE_MESH_ADDR_PUBLIC_ID 0x02
#define BLE_MESH_ADDR_RANDOM_ID 0x03
/* BD ADDR length */
#define BLE_MESH_ADDR_LEN 0x06
/* Advertising types */
#define BLE_MESH_ADV_IND 0x00
#define BLE_MESH_ADV_DIRECT_IND 0x01
#define BLE_MESH_ADV_SCAN_IND 0x02
#define BLE_MESH_ADV_NONCONN_IND 0x03
#define BLE_MESH_ADV_DIRECT_IND_LOW_DUTY 0x04
/* advertising channel map */
#define BLE_MESH_ADV_CHNL_37 BIT(0)
#define BLE_MESH_ADV_CHNL_38 BIT(1)
#define BLE_MESH_ADV_CHNL_39 BIT(2)
/* Advertising filter policy */
#define BLE_MESH_AP_SCAN_CONN_ALL 0x00
#define BLE_MESH_AP_SCAN_WL_CONN_ALL 0x01
#define BLE_MESH_AP_SCAN_ALL_CONN_WL 0x02
#define BLE_MESH_AP_SCAN_CONN_WL 0x03
/* Scan types */
#define BLE_MESH_SCAN_PASSIVE 0x00
#define BLE_MESH_SCAN_ACTIVE 0x01
/* Scan operation */
#define BLE_MESH_SCAN_DISABLE 0x00
#define BLE_MESH_SCAN_ENABLE 0x01
/* Scan duplicate operation */
#define BLE_MESH_SCAN_FILTER_DUP_DISABLE 0x00
#define BLE_MESH_SCAN_FILTER_DUP_ENABLE 0x01
/* Scan filter policy */
#define BLE_MESH_SP_ADV_ALL 0x00
#define BLE_MESH_SP_ADV_WL 0x01
#define BLE_MESH_SP_ADV_ALL_RPA_DIR_ADV 0x02
#define BLE_MESH_SP_ADV_WL_RPA_DIR_ADV 0x03
/* Error codes for Error response PDU */
#define BLE_MESH_ATT_ERR_INVALID_HANDLE 0x01
#define BLE_MESH_ATT_ERR_READ_NOT_PERMITTED 0x02
#define BLE_MESH_ATT_ERR_WRITE_NOT_PERMITTED 0x03
#define BLE_MESH_ATT_ERR_INVALID_PDU 0x04
#define BLE_MESH_ATT_ERR_AUTHENTICATION 0x05
#define BLE_MESH_ATT_ERR_NOT_SUPPORTED 0x06
#define BLE_MESH_ATT_ERR_INVALID_OFFSET 0x07
#define BLE_MESH_ATT_ERR_AUTHORIZATION 0x08
#define BLE_MESH_ATT_ERR_PREPARE_QUEUE_FULL 0x09
#define BLE_MESH_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a
#define BLE_MESH_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b
#define BLE_MESH_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c
#define BLE_MESH_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d
#define BLE_MESH_ATT_ERR_UNLIKELY 0x0e
#define BLE_MESH_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f
#define BLE_MESH_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10
#define BLE_MESH_ATT_ERR_INSUFFICIENT_RESOURCES 0x11
/* Common Profile Error Codes (from CSS) */
#define BLE_MESH_ATT_ERR_WRITE_REQ_REJECTED 0xfc
#define BLE_MESH_ATT_ERR_CCC_IMPROPER_CONF 0xfd
#define BLE_MESH_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe
#define BLE_MESH_ATT_ERR_OUT_OF_RANGE 0xff
/* EIR/AD data type definitions */
#define BLE_MESH_DATA_FLAGS 0x01 /* AD flags */
#define BLE_MESH_DATA_UUID16_SOME 0x02 /* 16-bit UUID, more available */
#define BLE_MESH_DATA_UUID16_ALL 0x03 /* 16-bit UUID, all listed */
#define BLE_MESH_DATA_UUID32_SOME 0x04 /* 32-bit UUID, more available */
#define BLE_MESH_DATA_UUID32_ALL 0x05 /* 32-bit UUID, all listed */
#define BLE_MESH_DATA_UUID128_SOME 0x06 /* 128-bit UUID, more available */
#define BLE_MESH_DATA_UUID128_ALL 0x07 /* 128-bit UUID, all listed */
#define BLE_MESH_DATA_NAME_SHORTENED 0x08 /* Shortened name */
#define BLE_MESH_DATA_NAME_COMPLETE 0x09 /* Complete name */
#define BLE_MESH_DATA_TX_POWER 0x0a /* Tx Power */
#define BLE_MESH_DATA_SOLICIT16 0x14 /* Solicit UUIDs, 16-bit */
#define BLE_MESH_DATA_SOLICIT128 0x15 /* Solicit UUIDs, 128-bit */
#define BLE_MESH_DATA_SVC_DATA16 0x16 /* Service data, 16-bit UUID */
#define BLE_MESH_DATA_GAP_APPEARANCE 0x19 /* GAP appearance */
#define BLE_MESH_DATA_SOLICIT32 0x1f /* Solicit UUIDs, 32-bit */
#define BLE_MESH_DATA_SVC_DATA32 0x20 /* Service data, 32-bit UUID */
#define BLE_MESH_DATA_SVC_DATA128 0x21 /* Service data, 128-bit UUID */
#define BLE_MESH_DATA_URI 0x24 /* URI */
#define BLE_MESH_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */
#define BLE_MESH_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */
#define BLE_MESH_DATA_MESH_BEACON 0x2b /* Mesh Beacon */
#define BLE_MESH_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */
#define BLE_MESH_AD_LIMITED 0x01 /* Limited Discoverable */
#define BLE_MESH_AD_GENERAL 0x02 /* General Discoverable */
#define BLE_MESH_AD_NO_BREDR 0x04 /* BR/EDR not supported */
/* Client Characteristic Configuration Values */
/** @def BLE_MESH_GATT_CCC_NOTIFY
* @brief Client Characteristic Configuration Notification.
*
* If set, changes to Characteristic Value shall be notified.
*/
#define BLE_MESH_GATT_CCC_NOTIFY 0x0001
/** @def BLE_MESH_GATT_CCC_INDICATE
* @brief Client Characteristic Configuration Indication.
*
* If set, changes to Characteristic Value shall be indicated.
*/
#define BLE_MESH_GATT_CCC_INDICATE 0x0002
/** @def BLE_MESH_GATT_ERR
* @brief Construct error return value for attribute read and write callbacks.
*
* @param _att_err ATT error code
*
* @return Appropriate error code for the attribute callbacks.
*
*/
#define BLE_MESH_GATT_ERR(_att_err) (-(_att_err))
enum {
BLE_MESH_GATT_ITER_STOP = 0,
BLE_MESH_GATT_ITER_CONTINUE,
};
/* GATT attribute permission bit field values */
enum {
/** No operations supported, e.g. for notify-only */
BLE_MESH_GATT_PERM_NONE = 0,
/** Attribute read permission. */
BLE_MESH_GATT_PERM_READ = BIT(0),
/** Attribute write permission. */
BLE_MESH_GATT_PERM_WRITE = BIT(1),
/** Attribute read permission with encryption.
*
* If set, requires encryption for read access.
*/
BLE_MESH_GATT_PERM_READ_ENCRYPT = BIT(2),
/** Attribute write permission with encryption.
*
* If set, requires encryption for write access.
*/
BLE_MESH_GATT_PERM_WRITE_ENCRYPT = BIT(3),
/** Attribute read permission with authentication.
*
* If set, requires encryption using authenticated link-key for read
* access.
*/
BLE_MESH_GATT_PERM_READ_AUTHEN = BIT(4),
/** Attribute write permission with authentication.
*
* If set, requires encryption using authenticated link-key for write
* access.
*/
BLE_MESH_GATT_PERM_WRITE_AUTHEN = BIT(5),
/** Attribute prepare write permission.
*
* If set, allows prepare writes with use of BT_GATT_WRITE_FLAG_PREPARE
* passed to write callback.
*/
BLE_MESH_GATT_PERM_PREPARE_WRITE = BIT(6),
};
/** Advertising options */
enum {
/** Convenience value when no options are specified. */
BLE_MESH_ADV_OPT_NONE = 0,
/** Advertise as connectable. Type of advertising is determined by
* providing SCAN_RSP data and/or enabling local privacy support.
*/
BLE_MESH_ADV_OPT_CONNECTABLE = BIT(0),
/** Don't try to resume connectable advertising after a connection.
* This option is only meaningful when used together with
* BLE_MESH_ADV_OPT_CONNECTABLE. If set the advertising will be stopped
* when bt_le_adv_stop() is called or when an incoming (slave)
* connection happens. If this option is not set the stack will
* take care of keeping advertising enabled even as connections
* occur.
*/
BLE_MESH_ADV_OPT_ONE_TIME = BIT(1),
};
/* Defined GAP timers */
#define BLE_MESH_GAP_SCAN_FAST_INTERVAL 0x0060 /* 60 ms */
#define BLE_MESH_GAP_SCAN_FAST_WINDOW 0x0030 /* 30 ms */
#define BLE_MESH_GAP_SCAN_SLOW_INTERVAL_1 0x0800 /* 1.28 s */
#define BLE_MESH_GAP_SCAN_SLOW_WINDOW_1 0x0012 /* 11.25 ms */
#define BLE_MESH_GAP_SCAN_SLOW_INTERVAL_2 0x1000 /* 2.56 s */
#define BLE_MESH_GAP_SCAN_SLOW_WINDOW_2 0x0012 /* 11.25 ms */
#define BLE_MESH_GAP_ADV_FAST_INT_MIN_0 0x0020 /* 20 ms */
#define BLE_MESH_GAP_ADV_FAST_INT_MAX_0 0x0020 /* 20 ms */
#define BLE_MESH_GAP_ADV_FAST_INT_MIN_1 0x0030 /* 30 ms */
#define BLE_MESH_GAP_ADV_FAST_INT_MAX_1 0x0060 /* 60 ms */
#define BLE_MESH_GAP_ADV_FAST_INT_MIN_2 0x00a0 /* 100 ms */
#define BLE_MESH_GAP_ADV_FAST_INT_MAX_2 0x00f0 /* 150 ms */
#define BLE_MESH_GAP_ADV_SLOW_INT_MIN 0x0320 /* 500 ms */
#define BLE_MESH_GAP_ADV_SLOW_INT_MAX 0x0320 /* 500 ms */
#define BLE_MESH_GAP_INIT_CONN_INT_MIN 0x0018 /* 30 ms */
#define BLE_MESH_GAP_INIT_CONN_INT_MAX 0x0028 /* 50 ms */
/* Characteristic Properties Bit field values */
/** @def BLE_MESH_GATT_CHRC_BROADCAST
* @brief Characteristic broadcast property.
*
* If set, permits broadcasts of the Characteristic Value using Server
* Characteristic Configuration Descriptor.
*/
#define BLE_MESH_GATT_CHRC_BROADCAST 0x01
/** @def BLE_MESH_GATT_CHRC_READ
* @brief Characteristic read property.
*
* If set, permits reads of the Characteristic Value.
*/
#define BLE_MESH_GATT_CHRC_READ 0x02
/** @def BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP
* @brief Characteristic write without response property.
*
* If set, permits write of the Characteristic Value without response.
*/
#define BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
/** @def BLE_MESH_GATT_CHRC_WRITE
* @brief Characteristic write with response property.
*
* If set, permits write of the Characteristic Value with response.
*/
#define BLE_MESH_GATT_CHRC_WRITE 0x08
/** @def BLE_MESH_GATT_CHRC_NOTIFY
* @brief Characteristic notify property.
*
* If set, permits notifications of a Characteristic Value without
* acknowledgment.
*/
#define BLE_MESH_GATT_CHRC_NOTIFY 0x10
/** @def BLE_MESH_GATT_CHRC_INDICATE
* @brief Characteristic indicate property.
*
* If set, permits indications of a Characteristic Value with acknowledgment.
*/
#define BLE_MESH_GATT_CHRC_INDICATE 0x20
/** @def BLE_MESH_GATT_CHRC_AUTH
* @brief Characteristic Authenticated Signed Writes property.
*
* If set, permits signed writes to the Characteristic Value.
*/
#define BLE_MESH_GATT_CHRC_AUTH 0x40
/** @def BLE_MESH_GATT_CHRC_EXT_PROP
* @brief Characteristic Extended Properties property.
*
* If set, additional characteristic properties are defined in the
* Characteristic Extended Properties Descriptor.
*/
#define BLE_MESH_GATT_CHRC_EXT_PROP 0x80
/** @brief Characteristic Attribute Value. */
struct bt_mesh_gatt_char {
/** Characteristic UUID. */
const struct bt_mesh_uuid *uuid;
/** Characteristic properties. */
uint8_t properties;
};
/** @brief GATT Service structure */
struct bt_mesh_gatt_service {
/** Service Attributes */
struct bt_mesh_gatt_attr *attrs;
/** Service Attribute count */
uint16_t attr_count;
sys_snode_t node;
};
typedef struct {
uint8_t type;
uint8_t val[6];
} bt_mesh_addr_t;
/** 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_mesh_adv_data {
uint8_t type;
uint8_t data_len;
const uint8_t *data;
};
/** @brief Helper to declare elements of bt_data arrays
*
* This macro is mainly for creating an array of struct
* bt_mesh_adv_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 BLE_MESH_ADV_DATA(_type, _data, _data_len) \
{ \
.type = (_type), \
.data_len = (_data_len), \
.data = (const uint8_t *)(_data), \
}
/** @brief Helper to declare elements of bt_data arrays
*
* This macro is mainly for creating an array of struct bt_mesh_adv_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 BLE_MESH_ADV_DATA_BYTES(_type, _bytes...) \
BLE_MESH_ADV_DATA(_type, ((uint8_t []) { _bytes }), \
sizeof((uint8_t []) { _bytes }))
/* BLE Mesh Advertising Parameters */
struct bt_mesh_adv_param {
/** Bit-field of advertising options */
uint8_t options;
/** Minimum Advertising Interval (N * 0.625) */
uint16_t interval_min;
/** Maximum Advertising Interval (N * 0.625) */
uint16_t interval_max;
};
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
enum bt_mesh_ble_adv_priority {
BLE_MESH_BLE_ADV_PRIO_LOW,
BLE_MESH_BLE_ADV_PRIO_HIGH,
};
struct bt_mesh_ble_adv_param {
uint16_t interval; /* Advertising interval */
uint8_t adv_type; /* Advertising type */
uint8_t own_addr_type; /* Own address type */
uint8_t peer_addr_type; /* Peer address type */
uint8_t peer_addr[6]; /* Peer address */
uint16_t duration; /* Duration is milliseconds */
uint16_t period; /* Period in milliseconds */
uint16_t count; /* Number of advertising duration */
uint8_t priority:2; /* Priority of BLE advertising packet */
};
struct bt_mesh_ble_adv_data {
uint8_t adv_data_len; /* Advertising data length */
uint8_t adv_data[31]; /* Advertising data */
uint8_t scan_rsp_data_len; /* Scan response data length */
uint8_t scan_rsp_data[31]; /* Scan response data */
};
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
/* BLE Mesh scan parameters */
struct bt_mesh_scan_param {
/** Scan type (BLE_MESH_SCAN_ACTIVE or BLE_MESH_SCAN_PASSIVE) */
uint8_t type;
/** Duplicate filtering (BLE_MESH_SCAN_FILTER_DUP_ENABLE or
* BLE_MESH_SCAN_FILTER_DUP_DISABLE)
*/
uint8_t filter_dup;
/** Scan interval (N * 0.625 ms) */
uint16_t interval;
/** Scan window (N * 0.625 ms) */
uint16_t window;
/** BLE scan filter policy */
uint8_t scan_fil_policy;
};
struct bt_mesh_conn {
uint16_t handle;
bt_mesh_atomic_t ref;
};
/** @typedef bt_mesh_scan_cb_t
* @brief Callback type for reporting LE scan results.
*
* A function of this type is given to the bt_le_scan_start() function
* and will be called for any discovered LE device.
*
* @param addr Advertiser LE address and type.
* @param rssi Strength of advertiser signal.
* @param adv_type Type of advertising response from advertiser.
* @param data Buffer containing advertiser data.
*/
typedef void bt_mesh_scan_cb_t(const bt_mesh_addr_t *addr, int8_t rssi,
uint8_t adv_type, struct net_buf_simple *buf);
/* @typedef bt_mesh_dh_key_cb_t
* @brief Callback type for DH Key calculation.
*
* Used to notify of the calculated DH Key.
*
* @param key Public key.
* @param idx Provisioning link index, only used by Provisioner.
*
* @return The DH Key, or NULL in case of failure.
*/
typedef void (*bt_mesh_dh_key_cb_t)(const uint8_t key[32], const uint8_t idx);
/** @typedef bt_mesh_gatt_attr_func_t
* @brief Attribute iterator callback.
*
* @param attr Attribute found.
* @param user_data Data given.
*
* @return BLE_MESH_GATT_ITER_CONTINUE if should continue to the next attribute
* or BLE_MESH_GATT_ITER_STOP to stop.
*/
typedef uint8_t (*bt_mesh_gatt_attr_func_t)(const struct bt_mesh_gatt_attr *attr,
void *user_data);
/** @brief Connection callback structure.
*
* This structure is used for tracking the state of a connection.
* It is registered with the help of the bt_mesh_gatts_conn_cb_register() API.
* It's permissible to register multiple instances of this @ref bt_conn_cb
* type, in case different modules of an application are interested in
* tracking the connection state. If a callback is not of interest for
* an instance, it may be set to NULL and will as a consequence not be
* used for that instance.
*/
struct bt_mesh_conn_cb {
/** @brief A new connection has been established.
*
* This callback notifies the application of a new connection.
* In case the err parameter is non-zero it means that the
* connection establishment failed.
*
* @param conn New connection object.
* @param err HCI error. Zero for success, non-zero otherwise.
*/
void (*connected)(struct bt_mesh_conn *conn, uint8_t err);
/** @brief A connection has been disconnected.
*
* This callback notifies the application that a connection
* has been disconnected.
*
* @param conn Connection object.
* @param reason HCI reason for the disconnection.
*/
void (*disconnected)(struct bt_mesh_conn *conn, uint8_t reason);
};
struct bt_mesh_prov_conn_cb {
void (*connected)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int id);
void (*disconnected)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, uint8_t reason);
ssize_t (*prov_write_descr)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn);
ssize_t (*prov_notify)(struct bt_mesh_conn *conn, uint8_t *data, uint16_t len);
ssize_t (*proxy_write_descr)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn);
ssize_t (*proxy_notify)(struct bt_mesh_conn *conn, uint8_t *data, uint16_t len);
};
/** @brief GATT Attribute structure. */
struct bt_mesh_gatt_attr {
/** Attribute UUID */
const struct bt_mesh_uuid *uuid;
/** Attribute read callback
*
* @param conn The connection that is requesting to read
* @param attr The attribute that's being read
* @param buf Buffer to place the read result in
* @param len Length of data to read
* @param offset Offset to start reading from
*
* @return Number fo bytes read, or in case of an error
* BLE_MESH_GATT_ERR() with a specific ATT error code.
*/
ssize_t (*read)(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, uint16_t len,
uint16_t offset);
/** Attribute write callback
*
* @param conn The connection that is requesting to write
* @param attr The attribute that's being written
* @param buf Buffer with the data to write
* @param len Number of bytes in the buffer
* @param offset Offset to start writing from
* @param flags Flags (BT_GATT_WRITE_*)
*
* @return Number of bytes written, or in case of an error
* BLE_MESH_GATT_ERR() with a specific ATT error code.
*/
ssize_t (*write)(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
const void *buf, uint16_t len,
uint16_t offset, uint8_t flags);
/** Attribute user data */
void *user_data;
/** Attribute handle */
uint16_t handle;
/** Attribute permissions */
uint8_t perm;
};
/** @def BLE_MESH_GATT_PRIMARY_SERVICE
* @brief Primary Service Declaration Macro.
*
* Helper macro to declare a primary service attribute.
*
* @param _service Service attribute value.
*/
#define BLE_MESH_GATT_PRIMARY_SERVICE(_service) \
{ \
.uuid = BLE_MESH_UUID_GATT_PRIMARY, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_service, \
.user_data = _service, \
}
/** @def BLE_MESH_GATT_SECONDARY_SERVICE
* @brief Secondary Service Declaration Macro.
*
* Helper macro to declare a secondary service attribute.
*
* @param _service Service attribute value.
*/
#define BLE_MESH_GATT_SECONDARY_SERVICE(_service) \
{ \
.uuid = BLE_MESH_UUID_GATT_SECONDARY, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_service, \
.user_data = _service, \
}
/** @def BLE_MESH_GATT_INCLUDE_SERVICE
* @brief Include Service Declaration Macro.
*
* Helper macro to declare database internal include service attribute.
*
* @param _service_incl the first service attribute of service to include
*/
#define BLE_MESH_GATT_INCLUDE_SERVICE(_service_incl) \
{ \
.uuid = BLE_MESH_UUID_GATT_INCLUDE, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_included, \
.user_data = _service_incl, \
}
/** @def BLE_MESH_GATT_CHARACTERISTIC
* @brief Characteristic Declaration Macro.
*
* Helper macro to declare a characteristic attribute.
*
* @param _uuid Characteristic attribute uuid.
* @param _props Characteristic attribute properties.
*/
#define BLE_MESH_GATT_CHARACTERISTIC(_uuid, _props) \
{ \
.uuid = BLE_MESH_UUID_GATT_CHRC, \
.perm = BLE_MESH_GATT_PERM_READ, \
.read = bt_mesh_gatts_attr_read_chrc, \
.user_data = (&(struct bt_mesh_gatt_char) { .uuid = _uuid, \
.properties = _props, }), \
}
/** @def BLE_MESH_GATT_DESCRIPTOR
* @brief Descriptor Declaration Macro.
*
* Helper macro to declare a descriptor attribute.
*
* @param _uuid Descriptor attribute uuid.
* @param _perm Descriptor attribute access permissions.
* @param _read Descriptor attribute read callback.
* @param _write Descriptor attribute write callback.
* @param _value Descriptor attribute value.
*/
#define BLE_MESH_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _value) \
{ \
.uuid = _uuid, \
.perm = _perm, \
.read = _read, \
.write = _write, \
.user_data = _value, \
}
/** @def BLE_MESH_GATT_SERVICE
* @brief Service Structure Declaration Macro.
*
* Helper macro to declare a service structure.
*
* @param _attrs Service attributes.
*/
#define BLE_MESH_GATT_SERVICE(_attrs) \
{ \
.attrs = _attrs, \
.attr_count = ARRAY_SIZE(_attrs), \
}
int bt_mesh_host_init(void);
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
const struct bt_mesh_adv_data *sd, size_t sd_len);
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data);
#endif
int bt_le_adv_stop(void);
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb);
int bt_le_scan_stop(void);
typedef enum {
BLE_MESH_WHITELIST_REMOVE,
BLE_MESH_WHITELIST_ADD,
} bt_mesh_wl_operation;
struct bt_mesh_white_list {
bool add_remove;
uint8_t remote_bda[BLE_MESH_ADDR_LEN];
uint8_t addr_type;
/* For Bluedroid host, this callback is used to notify the
* result of updating white list.
*/
void (*update_wl_comp_cb)(uint8_t status, bt_mesh_wl_operation wl_operation);
};
int bt_le_update_white_list(struct bt_mesh_white_list *wl);
void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb);
void bt_mesh_gatts_conn_cb_deregister(void);
int bt_mesh_gatts_disconnect(struct bt_mesh_conn *conn, uint8_t reason);
int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc);
int bt_mesh_gatts_service_deregister(struct bt_mesh_gatt_service *svc);
int bt_mesh_gatts_service_unregister(struct bt_mesh_gatt_service *svc);
ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset);
ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, uint16_t buf_len, uint16_t offset,
const void *value, uint16_t value_len);
ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset);
ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset);
int bt_mesh_gatts_notify(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
const void *data, uint16_t len);
uint16_t bt_mesh_gatt_get_mtu(struct bt_mesh_conn *conn);
/** APIs added by Espressif */
int bt_mesh_gatts_service_stop(struct bt_mesh_gatt_service *svc);
int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc);
int bt_mesh_gatts_set_local_device_name(const char *name);
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb);
void bt_mesh_gattc_conn_cb_deregister(void);
uint8_t bt_mesh_gattc_get_free_conn_count(void);
uint16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn);
int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid);
void bt_gattc_conn_close(struct bt_mesh_conn *conn);
void bt_mesh_gattc_exchange_mtu(uint8_t index);
uint16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn);
int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
const void *data, uint16_t len);
void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn);
struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn);
void bt_mesh_conn_unref(struct bt_mesh_conn *conn);
void bt_mesh_gatt_init(void);
void bt_mesh_gatt_deinit(void);
void bt_mesh_adapt_init(void);
void bt_mesh_set_private_key(const uint8_t pri_key[32]);
const uint8_t *bt_mesh_pub_key_get(void);
bool bt_mesh_check_public_key(const uint8_t key[64]);
int bt_mesh_dh_key_gen(const uint8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const uint8_t idx);
int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
uint8_t enc_data[16]);
int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
uint8_t enc_data[16]);
enum {
BLE_MESH_EXCEP_LIST_ADD = 0,
BLE_MESH_EXCEP_LIST_REMOVE,
BLE_MESH_EXCEP_LIST_CLEAN,
};
enum {
BLE_MESH_EXCEP_INFO_ADV_ADDR = 0,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID,
BLE_MESH_EXCEP_INFO_MESH_BEACON,
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV,
BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV,
};
enum {
BLE_MESH_EXCEP_CLEAN_ADDR_LIST = BIT(0),
BLE_MESH_EXCEP_CLEAN_MESH_LINK_ID_LIST = BIT(1),
BLE_MESH_EXCEP_CLEAN_MESH_BEACON_LIST = BIT(2),
BLE_MESH_EXCEP_CLEAN_MESH_PROV_ADV_LIST = BIT(3),
BLE_MESH_EXCEP_CLEAN_MESH_PROXY_ADV_LIST = BIT(4),
BLE_MESH_EXCEP_CLEAN_ALL_LIST = 0xFFFF,
};
int bt_mesh_update_exceptional_list(uint8_t sub_code, uint8_t type, void *info);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_BEARER_ADAPT_H_ */

View File

@ -0,0 +1,133 @@
/*
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_HCI_H_
#define _BLE_MESH_HCI_H_
#include "mesh_atomic.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Porting form zephyr/subsys/bluetooth/host/hci_core.h */
#define BLE_MESH_LMP_FEAT_PAGES_COUNT 1
/* bt_mesh_dev flags: the flags defined here represent BT controller state */
enum {
BLE_MESH_DEV_ENABLE,
BLE_MESH_DEV_READY,
BLE_MESH_DEV_ID_STATIC_RANDOM,
BLE_MESH_DEV_HAS_PUB_KEY,
BLE_MESH_DEV_PUB_KEY_BUSY,
BLE_MESH_DEV_ADVERTISING,
BLE_MESH_DEV_KEEP_ADVERTISING,
BLE_MESH_DEV_SCANNING,
BLE_MESH_DEV_EXPLICIT_SCAN,
BLE_MESH_DEV_ACTIVE_SCAN,
BLE_MESH_DEV_SCAN_FILTER_DUP,
BLE_MESH_DEV_RPA_VALID,
BLE_MESH_DEV_ID_PENDING,
/* Total number of flags - must be at the end of the enum */
BLE_MESH_DEV_NUM_FLAGS,
};
struct bt_mesh_dev_le {
/* LE features */
uint8_t features[8];
/* LE states */
uint64_t states;
};
/* State tracking for the local Bluetooth controller */
struct bt_mesh_dev {
/* Flags indicate which functionality is enabled */
BLE_MESH_ATOMIC_DEFINE(flags, BLE_MESH_DEV_NUM_FLAGS);
/* Controller version & manufacturer information */
uint8_t hci_version;
uint8_t lmp_version;
uint16_t hci_revision;
uint16_t lmp_subversion;
uint16_t manufacturer;
/* LMP features (pages 0, 1, 2) */
uint8_t features[BLE_MESH_LMP_FEAT_PAGES_COUNT][8];
/* LE controller specific features */
struct bt_mesh_dev_le le;
};
/*Porting from zephyr/subsys/bluetooth/host/hci_core.h */
/* HCI version from Assigned Numbers */
#define BLE_MESH_HCI_VERSION_1_0B 0
#define BLE_MESH_HCI_VERSION_1_1 1
#define BLE_MESH_HCI_VERSION_1_2 2
#define BLE_MESH_HCI_VERSION_2_0 3
#define BLE_MESH_HCI_VERSION_2_1 4
#define BLE_MESH_HCI_VERSION_3_0 5
#define BLE_MESH_HCI_VERSION_4_0 6
#define BLE_MESH_HCI_VERSION_4_1 7
#define BLE_MESH_HCI_VERSION_4_2 8
#define BLE_MESH_HCI_VERSION_5_0 9
/* OpCode Group Fields */
#define BLE_MESH_OGF_LINK_CTRL 0x01
#define BLE_MESH_OGF_BASEBAND 0x03
#define BLE_MESH_OGF_INFO 0x04
#define BLE_MESH_OGF_STATUS 0x05
#define BLE_MESH_OGF_LE 0x08
#define BLE_MESH_OGF_VS 0x3f
/* Construct OpCode from OGF and OCF */
#define BLE_MESH_OP(ogf, ocf) ((ocf) | ((ogf) << 10))
/* Obtain OGF from OpCode */
#define BLE_MESH_OGF(opcode) (((opcode) >> 10) & BIT_MASK(6))
/* Obtain OCF from OpCode */
#define BLE_MESH_OCF(opcode) ((opcode) & BIT_MASK(10))
#define BLE_MESH_HCI_OP_SET_ADV_PARAM BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0006)
struct bt_mesh_hci_cp_set_adv_param {
uint16_t min_interval;
uint16_t max_interval;
uint8_t type;
uint8_t own_addr_type;
bt_mesh_addr_t direct_addr;
uint8_t channel_map;
uint8_t filter_policy;
} __packed;
#define BLE_MESH_HCI_OP_SET_ADV_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0008)
struct bt_mesh_hci_cp_set_adv_data {
uint8_t len;
uint8_t data[31];
} __packed;
#define BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0009)
struct bt_mesh_hci_cp_set_scan_rsp_data {
uint8_t len;
uint8_t data[31];
} __packed;
/* Added by Espressif */
extern struct bt_mesh_dev bt_mesh_dev;
void bt_mesh_hci_init(void);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_HCI_H_ */

View File

@ -0,0 +1,635 @@
/** @file
* @brief Bluetooth Mesh Profile APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_MAIN_H_
#define _BLE_MESH_MAIN_H_
#include "mesh_access.h"
/**
* @brief Bluetooth Mesh Provisioning
* @defgroup bt_mesh_prov Bluetooth Mesh Provisioning
* @ingroup bt_mesh
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
BLE_MESH_NO_OUTPUT = 0,
BLE_MESH_BLINK = BIT(0),
BLE_MESH_BEEP = BIT(1),
BLE_MESH_VIBRATE = BIT(2),
BLE_MESH_DISPLAY_NUMBER = BIT(3),
BLE_MESH_DISPLAY_STRING = BIT(4),
} bt_mesh_output_action_t;
typedef enum {
BLE_MESH_NO_INPUT = 0,
BLE_MESH_PUSH = BIT(0),
BLE_MESH_TWIST = BIT(1),
BLE_MESH_ENTER_NUMBER = BIT(2),
BLE_MESH_ENTER_STRING = BIT(3),
} bt_mesh_input_action_t;
typedef enum {
BLE_MESH_PROV_ADV = BIT(0),
BLE_MESH_PROV_GATT = BIT(1),
} bt_mesh_prov_bearer_t;
typedef enum {
BLE_MESH_PROV_OOB_OTHER = BIT(0),
BLE_MESH_PROV_OOB_URI = BIT(1),
BLE_MESH_PROV_OOB_2D_CODE = BIT(2),
BLE_MESH_PROV_OOB_BAR_CODE = BIT(3),
BLE_MESH_PROV_OOB_NFC = BIT(4),
BLE_MESH_PROV_OOB_NUMBER = BIT(5),
BLE_MESH_PROV_OOB_STRING = BIT(6),
/* 7 - 10 are reserved */
BLE_MESH_PROV_OOB_ON_BOX = BIT(11),
BLE_MESH_PROV_OOB_IN_BOX = BIT(12),
BLE_MESH_PROV_OOB_ON_PAPER = BIT(13),
BLE_MESH_PROV_OOB_IN_MANUAL = BIT(14),
BLE_MESH_PROV_OOB_ON_DEV = BIT(15),
} bt_mesh_prov_oob_info_t;
#define BLE_MESH_PROV_STATIC_OOB_MAX_LEN 16
#define BLE_MESH_PROV_OUTPUT_OOB_MAX_LEN 8
#define BLE_MESH_PROV_INPUT_OOB_MAX_LEN 8
/** Provisioning properties & capabilities. */
struct bt_mesh_prov {
#if CONFIG_BLE_MESH_NODE
/** The UUID that's used when advertising as unprovisioned */
const uint8_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;
/** Flag indicates whether unprovisioned devices support OOB public key */
bool oob_pub_key;
/** @brief Set device OOB public key.
*
* This callback notifies the application to
* set OOB public key & private key pair.
*/
void (*oob_pub_key_cb)(void);
/** Static OOB value */
const uint8_t *static_val;
/** Static OOB value length */
uint8_t static_val_len;
/** Maximum size of Output OOB supported */
uint8_t output_size;
/** Supported Output OOB Actions */
uint16_t output_actions;
/* Maximum size of Input OOB supported */
uint8_t input_size;
/** Supported Input OOB Actions */
uint16_t input_actions;
/** @brief Output of a number is requested.
*
* This callback notifies the application to
* output the given number using the given action.
*
* @param act Action for outputting the number.
* @param num Number to be out-put.
*
* @return Zero on success or negative error code otherwise
*/
int (*output_number)(bt_mesh_output_action_t act, uint32_t num);
/** @brief Output of a string is requested.
*
* This callback notifies the application to
* 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 to 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 in-put data.
*
* @return Zero on success or negative error code otherwise
*/
int (*input)(bt_mesh_input_action_t act, uint8_t size);
/** @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 net_key NetKey given during provisioning.
* @param addr Primary element address.
* @param flags Key Refresh & IV Update flags
* @param iv_index IV Index.
*/
void (*complete)(uint16_t net_idx, const uint8_t net_key[16], uint16_t addr, uint8_t flags, uint32_t iv_index);
/** @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);
#endif /* CONFIG_BLE_MESH_NODE */
#if CONFIG_BLE_MESH_PROVISIONER
/* Provisioner device uuid */
const uint8_t *prov_uuid;
/*
* Primary element address of the provisioner.
* No need to initialize it for fast provisioning.
*/
const uint16_t prov_unicast_addr;
/*
* Starting unicast address going to assigned.
* No need to initialize it for fast provisioning.
*/
uint16_t prov_start_address;
/* Attention timer contained in Provisioning Invite */
uint8_t prov_attention;
/* Provisioner provisioning Algorithm */
uint8_t prov_algorithm;
/* Provisioner public key oob */
uint8_t prov_pub_key_oob;
/** @brief Input is requested.
*
* This callback notifies the application that it should
* read device's public key with OOB
*
* @param link_idx: The provisioning link index
*
* @return Zero on success or negative error code otherwise
*/
int (*prov_pub_key_oob_cb)(uint8_t link_idx);
/* Provisioner static oob value */
uint8_t *prov_static_oob_val;
/* Provisioner static oob value length */
uint8_t prov_static_oob_len;
/** @brief Provisioner input a number read from device output
*
* This callback notifies the application that it should
* input the number given by the device.
*
* @param method: The OOB authentication method
* @param act: The output action of the device
* @param size: The output size of the device
* @param link_idx: The provisioning link index
*
* @return Zero on success or negative error code otherwise
*/
int (*prov_input_num)(uint8_t method, bt_mesh_output_action_t act, uint8_t size, uint8_t link_idx);
/** @brief Provisioner output a number to the device
*
* This callback notifies the application that it should
* output the number to the device.
*
* @param method: The OOB authentication method
* @param act: The input action of the device
* @param data: The input number/string of the device
* @param size: The input size of the device
* @param link_idx: The provisioning link index
*
* @return Zero on success or negative error code otherwise
*/
int (*prov_output_num)(uint8_t method, bt_mesh_input_action_t act, void *data, uint8_t size, uint8_t link_idx);
/*
* Key refresh and IV update flag.
* No need to initialize it for fast provisioning.
*/
uint8_t flags;
/*
* IV index. No need to initialize it for fast provisioning.
*/
uint32_t iv_index;
/** @brief Provisioner has opened a provisioning link.
*
* This callback notifies the application that a provisioning
* link has been opened on the given provisioning bearer.
*
* @param bearer Provisioning bearer.
*/
void (*prov_link_open)(bt_mesh_prov_bearer_t bearer);
/** @brief Provisioner has closed a provisioning link.
*
* This callback notifies the application that a provisioning
* link has been closed on the given provisioning bearer.
*
* @param bearer Provisioning bearer.
* @param reason Provisioning link close reason(disconnect reason)
*/
void (*prov_link_close)(bt_mesh_prov_bearer_t bearer, uint8_t reason);
/** @brief Provision one device is complete.
*
* This callback notifies the application that provisioner has
* successfully provisioned a device, and the node has been assigned
* the specified NetKeyIndex and primary element address.
*
* @param node_idx Node index within the node(provisioned device) queue.
* @param device_uuid Provisioned device uuid pointer.
* @param unicast_addr Provisioned device assigned unicast address.
* @param element_num Provisioned device element number.
* @param netkey_idx Provisioned device assigned netkey index.
*/
void (*prov_complete)(uint16_t node_idx, const uint8_t device_uuid[16],
uint16_t unicast_addr, uint8_t element_num,
uint16_t netkey_idx);
#endif /* CONFIG_BLE_MESH_PROVISIONER */
};
enum ble_mesh_role {
NODE = 0,
PROVISIONER,
FAST_PROV,
ROLE_NVAL,
};
/* The following APIs are for BLE Mesh Node */
/** @brief Provide provisioning input OOB string.
*
* This is intended to be called after the bt_mesh_prov input callback
* has been called with BLE_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 BLE_MESH_ENTER_NUMBER as the action.
*
* @param num Number.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_input_number(uint32_t num);
/** @brief Enable specific provisioning bearers
*
* Enable one or more provisioning bearers.
*
* @param 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 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);
/* The following APIs are for BLE Mesh Provisioner */
/** @brief Provide provisioning input OOB string.
*
* This is intended to be called after the bt_mesh_prov input callback
* has been called with BLE_MESH_ENTER_STRING as the action.
*
* @param str String.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_prov_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 BLE_MESH_ENTER_NUMBER as the action.
*
* @param num Number.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_prov_input_number(uint32_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_provisioner_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_provisioner_disable(bt_mesh_prov_bearer_t bearers);
/**
* @}
*/
/**
* @brief Bluetooth Mesh
* @defgroup bt_mesh Bluetooth Mesh
* @ingroup bluetooth
* @{
*/
/* Primary Network Key index */
#define BLE_MESH_NET_PRIMARY 0x000
#define BLE_MESH_RELAY_DISABLED 0x00
#define BLE_MESH_RELAY_ENABLED 0x01
#define BLE_MESH_RELAY_NOT_SUPPORTED 0x02
#define BLE_MESH_BEACON_DISABLED 0x00
#define BLE_MESH_BEACON_ENABLED 0x01
#define BLE_MESH_GATT_PROXY_DISABLED 0x00
#define BLE_MESH_GATT_PROXY_ENABLED 0x01
#define BLE_MESH_GATT_PROXY_NOT_SUPPORTED 0x02
#define BLE_MESH_FRIEND_DISABLED 0x00
#define BLE_MESH_FRIEND_ENABLED 0x01
#define BLE_MESH_FRIEND_NOT_SUPPORTED 0x02
#define BLE_MESH_NODE_IDENTITY_STOPPED 0x00
#define BLE_MESH_NODE_IDENTITY_RUNNING 0x01
#define BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02
/* Features */
#define BLE_MESH_FEAT_RELAY BIT(0)
#define BLE_MESH_FEAT_PROXY BIT(1)
#define BLE_MESH_FEAT_FRIEND BIT(2)
#define BLE_MESH_FEAT_LOW_POWER BIT(3)
#define BLE_MESH_FEAT_SUPPORTED (BLE_MESH_FEAT_RELAY | \
BLE_MESH_FEAT_PROXY | \
BLE_MESH_FEAT_FRIEND | \
BLE_MESH_FEAT_LOW_POWER)
/** @brief Check if the mesh stack is initialized.
*
* @return true - yes, false - no.
*/
bool bt_mesh_is_initialized(void);
/** @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 prov Node provisioning information.
* @param comp Node Composition.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_init(const struct bt_mesh_prov *prov,
const struct bt_mesh_comp *comp);
/* BLE Mesh deinit parameters */
struct bt_mesh_deinit_param {
bool erase; /* Indicate if erasing flash when deinit mesh stack */
};
/** @brief De-initialize Mesh support
*
* @param param BLE Mesh deinit parameters.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_deinit(struct bt_mesh_deinit_param *param);
/** @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_node_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 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 Check if the device is an unprovisioned device
* and will act as a node once provisioned.
*
* @return true - yes, false - no.
*/
bool bt_mesh_is_node(void);
/** @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 Check if the device is a Provisioner.
*
* @return true - yes, false - no.
*/
bool bt_mesh_is_provisioner(void);
/** @brief Check if the Provisioner is enabled
*
* @return true - enabled, false - disabled.
*/
bool bt_mesh_is_provisioner_en(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.
* @param force when disable LPN functionality, use this flag to indicate
* whether directly clear corresponding information or sending
* friend clear to disable it.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_lpn_set(bool enable, bool force);
/** @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)(uint16_t friend_addr, bool established));
/** @brief Register a callback for Friendship changes of friend node.
*
* Registers a callback that will be called whenever Friendship gets
* established or is terminated.
*
* @param cb Function to call when the Friendship status of friend node changes.
*/
void bt_mesh_friend_set_cb(void (*cb)(bool establish, uint16_t lpn_addr, uint8_t reason));
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* _BLE_MESH_MAIN_H_ */

View File

@ -0,0 +1,45 @@
/** @file
* @brief Bluetooth Mesh Proxy APIs.
*/
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_PROXY_H_
#define _BLE_MESH_PROXY_H_
#include <stddef.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 /* _BLE_MESH_PROXY_H_ */

View File

@ -0,0 +1,530 @@
/** @file
* @brief Bluetooth UUID handling
*/
/*
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_UUID_H_
#define _BLE_MESH_UUID_H_
/**
* @brief UUIDs
* @defgroup bt_uuid UUIDs
* @ingroup bluetooth
* @{
*/
#include "mesh_util.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Bluetooth UUID types */
enum {
BLE_MESH_UUID_TYPE_16,
BLE_MESH_UUID_TYPE_32,
BLE_MESH_UUID_TYPE_128,
};
/** @brief This is a 'tentative' type and should be used as a pointer only */
struct bt_mesh_uuid {
uint8_t type;
};
struct bt_mesh_uuid_16 {
struct bt_mesh_uuid uuid;
uint16_t val;
};
struct bt_mesh_uuid_32 {
struct bt_mesh_uuid uuid;
uint32_t val;
};
struct bt_mesh_uuid_128 {
struct bt_mesh_uuid uuid;
uint8_t val[16];
};
#define BLE_MESH_UUID_INIT_16(value) \
{ \
.uuid.type = BLE_MESH_UUID_TYPE_16, \
.val = (value), \
}
#define BLE_MESH_UUID_INIT_32(value) \
{ \
.uuid.type = BLE_MESH_UUID_TYPE_32, \
.val = (value), \
}
#define BLE_MESH_UUID_INIT_128(value...) \
{ \
.uuid.type = BLE_MESH_UUID_TYPE_128, \
.val = { value }, \
}
#define BLE_MESH_UUID_DECLARE_16(value) \
((struct bt_mesh_uuid *) (&(struct bt_mesh_uuid_16) BLE_MESH_UUID_INIT_16(value)))
#define BLE_MESH_UUID_DECLARE_32(value) \
((struct bt_mesh_uuid *) (&(struct bt_mesh_uuid_32) BLE_MESH_UUID_INIT_32(value)))
#define BLE_MESH_UUID_DECLARE_128(value...) \
((struct bt_mesh_uuid *) (&(struct bt_mesh_uuid_128) BLE_MESH_UUID_INIT_128(value)))
#define BLE_MESH_UUID_16(__u) CONTAINER_OF(__u, struct bt_mesh_uuid_16, uuid)
#define BLE_MESH_UUID_32(__u) CONTAINER_OF(__u, struct bt_mesh_uuid_32, uuid)
#define BLE_MESH_UUID_128(__u) CONTAINER_OF(__u, struct bt_mesh_uuid_128, uuid)
/** @def BLE_MESH_UUID_GAP
* @brief Generic Access
*/
#define BLE_MESH_UUID_GAP BLE_MESH_UUID_DECLARE_16(0x1800)
#define BLE_MESH_UUID_GAP_VAL 0x1800
/** @def BLE_MESH_UUID_GATT
* @brief Generic Attribute
*/
#define BLE_MESH_UUID_GATT BLE_MESH_UUID_DECLARE_16(0x1801)
#define BLE_MESH_UUID_GATT_VAL 0x1801
/** @def BLE_MESH_UUID_CTS
* @brief Current Time Service
*/
#define BLE_MESH_UUID_CTS BLE_MESH_UUID_DECLARE_16(0x1805)
#define BLE_MESH_UUID_CTS_VAL 0x1805
/** @def BLE_MESH_UUID_DIS
* @brief Device Information Service
*/
#define BLE_MESH_UUID_DIS BLE_MESH_UUID_DECLARE_16(0x180a)
#define BLE_MESH_UUID_DIS_VAL 0x180a
/** @def BLE_MESH_UUID_HRS
* @brief Heart Rate Service
*/
#define BLE_MESH_UUID_HRS BLE_MESH_UUID_DECLARE_16(0x180d)
#define BLE_MESH_UUID_HRS_VAL 0x180d
/** @def BLE_MESH_UUID_BAS
* @brief Battery Service
*/
#define BLE_MESH_UUID_BAS BLE_MESH_UUID_DECLARE_16(0x180f)
#define BLE_MESH_UUID_BAS_VAL 0x180f
/** @def BLE_MESH_UUID_HIDS
* @brief HID Service
*/
#define BLE_MESH_UUID_HIDS BLE_MESH_UUID_DECLARE_16(0x1812)
#define BLE_MESH_UUID_HIDS_VAL 0x1812
/** @def BLE_MESH_UUID_CSC
* @brief Cycling Speed and Cadence Service
*/
#define BLE_MESH_UUID_CSC BLE_MESH_UUID_DECLARE_16(0x1816)
#define BLE_MESH_UUID_CSC_VAL 0x1816
/** @def BLE_MESH_UUID_ESS
* @brief Environmental Sensing Service
*/
#define BLE_MESH_UUID_ESS BLE_MESH_UUID_DECLARE_16(0x181a)
#define BLE_MESH_UUID_ESS_VAL 0x181a
/** @def BLE_MESH_UUID_IPSS
* @brief IP Support Service
*/
#define BLE_MESH_UUID_IPSS BLE_MESH_UUID_DECLARE_16(0x1820)
#define BLE_MESH_UUID_IPSS_VAL 0x1820
/** @def BLE_MESH_UUID_MESH_PROV
* @brief Mesh Provisioning Service
*/
#define BLE_MESH_UUID_MESH_PROV BLE_MESH_UUID_DECLARE_16(0x1827)
#define BLE_MESH_UUID_MESH_PROV_VAL 0x1827
/** @def BLE_MESH_UUID_MESH_PROXY
* @brief Mesh Proxy Service
*/
#define BLE_MESH_UUID_MESH_PROXY BLE_MESH_UUID_DECLARE_16(0x1828)
#define BLE_MESH_UUID_MESH_PROXY_VAL 0x1828
/** @def BLE_MESH_UUID_GATT_PRIMARY
* @brief GATT Primary Service
*/
#define BLE_MESH_UUID_GATT_PRIMARY BLE_MESH_UUID_DECLARE_16(0x2800)
#define BLE_MESH_UUID_GATT_PRIMARY_VAL 0x2800
/** @def BLE_MESH_UUID_GATT_SECONDARY
* @brief GATT Secondary Service
*/
#define BLE_MESH_UUID_GATT_SECONDARY BLE_MESH_UUID_DECLARE_16(0x2801)
#define BLE_MESH_UUID_GATT_SECONDARY_VAL 0x2801
/** @def BLE_MESH_UUID_GATT_INCLUDE
* @brief GATT Include Service
*/
#define BLE_MESH_UUID_GATT_INCLUDE BLE_MESH_UUID_DECLARE_16(0x2802)
#define BLE_MESH_UUID_GATT_INCLUDE_VAL 0x2802
/** @def BLE_MESH_UUID_GATT_CHRC
* @brief GATT Characteristic
*/
#define BLE_MESH_UUID_GATT_CHRC BLE_MESH_UUID_DECLARE_16(0x2803)
#define BLE_MESH_UUID_GATT_CHRC_VAL 0x2803
/** @def BLE_MESH_UUID_GATT_CEP
* @brief GATT Characteristic Extended Properties
*/
#define BLE_MESH_UUID_GATT_CEP BLE_MESH_UUID_DECLARE_16(0x2900)
#define BLE_MESH_UUID_GATT_CEP_VAL 0x2900
/** @def BLE_MESH_UUID_GATT_CUD
* @brief GATT Characteristic User Description
*/
#define BLE_MESH_UUID_GATT_CUD BLE_MESH_UUID_DECLARE_16(0x2901)
#define BLE_MESH_UUID_GATT_CUD_VAL 0x2901
/** @def BLE_MESH_UUID_GATT_CCC
* @brief GATT Client Characteristic Configuration
*/
#define BLE_MESH_UUID_GATT_CCC BLE_MESH_UUID_DECLARE_16(0x2902)
#define BLE_MESH_UUID_GATT_CCC_VAL 0x2902
/** @def BLE_MESH_UUID_GATT_SCC
* @brief GATT Server Characteristic Configuration
*/
#define BLE_MESH_UUID_GATT_SCC BLE_MESH_UUID_DECLARE_16(0x2903)
#define BLE_MESH_UUID_GATT_SCC_VAL 0x2903
/** @def BLE_MESH_UUID_GATT_CPF
* @brief GATT Characteristic Presentation Format
*/
#define BLE_MESH_UUID_GATT_CPF BLE_MESH_UUID_DECLARE_16(0x2904)
#define BLE_MESH_UUID_GATT_CPF_VAL 0x2904
/** @def BLE_MESH_UUID_VALID_RANGE
* @brief Valid Range Descriptor
*/
#define BLE_MESH_UUID_VALID_RANGE BLE_MESH_UUID_DECLARE_16(0x2906)
#define BLE_MESH_UUID_VALID_RANGE_VAL 0x2906
/** @def BLE_MESH_UUID_HIDS_EXT_REPORT
* @brief HID External Report Descriptor
*/
#define BLE_MESH_UUID_HIDS_EXT_REPORT BLE_MESH_UUID_DECLARE_16(0x2907)
#define BLE_MESH_UUID_HIDS_EXT_REPORT_VAL 0x2907
/** @def BLE_MESH_UUID_HIDS_REPORT_REF
* @brief HID Report Reference Descriptor
*/
#define BLE_MESH_UUID_HIDS_REPORT_REF BLE_MESH_UUID_DECLARE_16(0x2908)
#define BLE_MESH_UUID_HIDS_REPORT_REF_VAL 0x2908
/** @def BLE_MESH_UUID_ES_CONFIGURATION
* @brief Environmental Sensing Configuration Descriptor
*/
#define BLE_MESH_UUID_ES_CONFIGURATION BLE_MESH_UUID_DECLARE_16(0x290b)
#define BLE_MESH_UUID_ES_CONFIGURATION_VAL 0x290b
/** @def BLE_MESH_UUID_ES_MEASUREMENT
* @brief Environmental Sensing Measurement Descriptor
*/
#define BLE_MESH_UUID_ES_MEASUREMENT BLE_MESH_UUID_DECLARE_16(0x290c)
#define BLE_MESH_UUID_ES_MEASUREMENT_VAL 0x290c
/** @def BLE_MESH_UUID_ES_TRIGGER_SETTING
* @brief Environmental Sensing Trigger Setting Descriptor
*/
#define BLE_MESH_UUID_ES_TRIGGER_SETTING BLE_MESH_UUID_DECLARE_16(0x290d)
#define BLE_MESH_UUID_ES_TRIGGER_SETTING_VAL 0x290d
/** @def BLE_MESH_UUID_GAP_DEVICE_NAME
* @brief GAP Characteristic Device Name
*/
#define BLE_MESH_UUID_GAP_DEVICE_NAME BLE_MESH_UUID_DECLARE_16(0x2a00)
#define BLE_MESH_UUID_GAP_DEVICE_NAME_VAL 0x2a00
/** @def BLE_MESH_UUID_GAP_APPEARANCE
* @brief GAP Characteristic Appearance
*/
#define BLE_MESH_UUID_GAP_APPEARANCE BLE_MESH_UUID_DECLARE_16(0x2a01)
#define BLE_MESH_UUID_GAP_APPEARANCE_VAL 0x2a01
/** @def BLE_MESH_UUID_GAP_PPCP
* @brief GAP Characteristic Peripheral Preferred Connection Parameters
*/
#define BLE_MESH_UUID_GAP_PPCP BLE_MESH_UUID_DECLARE_16(0x2a04)
#define BLE_MESH_UUID_GAP_PPCP_VAL 0x2a04
/** @def BLE_MESH_UUID_GATT_SC
* @brief GATT Characteristic Service Changed
*/
#define BLE_MESH_UUID_GATT_SC BLE_MESH_UUID_DECLARE_16(0x2a05)
#define BLE_MESH_UUID_GATT_SC_VAL 0x2a05
/** @def BLE_MESH_UUID_BAS_BATTERY_LEVEL
* @brief BAS Characteristic Battery Level
*/
#define BLE_MESH_UUID_BAS_BATTERY_LEVEL BLE_MESH_UUID_DECLARE_16(0x2a19)
#define BLE_MESH_UUID_BAS_BATTERY_LEVEL_VAL 0x2a19
/** @def BLE_MESH_UUID_DIS_SYSTEM_ID
* @brief DIS Characteristic System ID
*/
#define BLE_MESH_UUID_DIS_SYSTEM_ID BLE_MESH_UUID_DECLARE_16(0x2a23)
#define BLE_MESH_UUID_DIS_SYSTEM_ID_VAL 0x2a23
/** @def BLE_MESH_UUID_DIS_MODEL_NUMBER
* @brief DIS Characteristic Model Number String
*/
#define BLE_MESH_UUID_DIS_MODEL_NUMBER BLE_MESH_UUID_DECLARE_16(0x2a24)
#define BLE_MESH_UUID_DIS_MODEL_NUMBER_VAL 0x2a24
/** @def BLE_MESH_UUID_DIS_SERIAL_NUMBER
* @brief DIS Characteristic Serial Number String
*/
#define BLE_MESH_UUID_DIS_SERIAL_NUMBER BLE_MESH_UUID_DECLARE_16(0x2a25)
#define BLE_MESH_UUID_DIS_SERIAL_NUMBER_VAL 0x2a25
/** @def BLE_MESH_UUID_DIS_FIRMWARE_REVISION
* @brief DIS Characteristic Firmware Revision String
*/
#define BLE_MESH_UUID_DIS_FIRMWARE_REVISION BLE_MESH_UUID_DECLARE_16(0x2a26)
#define BLE_MESH_UUID_DIS_FIRMWARE_REVISION_VAL 0x2a26
/** @def BLE_MESH_UUID_DIS_HARDWARE_REVISION
* @brief DIS Characteristic Hardware Revision String
*/
#define BLE_MESH_UUID_DIS_HARDWARE_REVISION BLE_MESH_UUID_DECLARE_16(0x2a27)
#define BLE_MESH_UUID_DIS_HARDWARE_REVISION_VAL 0x2a27
/** @def BLE_MESH_UUID_DIS_SOFTWARE_REVISION
* @brief DIS Characteristic Software Revision String
*/
#define BLE_MESH_UUID_DIS_SOFTWARE_REVISION BLE_MESH_UUID_DECLARE_16(0x2a28)
#define BLE_MESH_UUID_DIS_SOFTWARE_REVISION_VAL 0x2a28
/** @def BLE_MESH_UUID_DIS_MANUFACTURER_NAME
* @brief DIS Characteristic Manufacturer Name String
*/
#define BLE_MESH_UUID_DIS_MANUFACTURER_NAME BLE_MESH_UUID_DECLARE_16(0x2a29)
#define BLE_MESH_UUID_DIS_MANUFACTURER_NAME_VAL 0x2a29
/** @def BLE_MESH_UUID_DIS_PNP_ID
* @brief DIS Characteristic PnP ID
*/
#define BLE_MESH_UUID_DIS_PNP_ID BLE_MESH_UUID_DECLARE_16(0x2a50)
#define BLE_MESH_UUID_DIS_PNP_ID_VAL 0x2a50
/** @def BLE_MESH_UUID_CTS_CURRENT_TIME
* @brief CTS Characteristic Current Time
*/
#define BLE_MESH_UUID_CTS_CURRENT_TIME BLE_MESH_UUID_DECLARE_16(0x2a2b)
#define BLE_MESH_UUID_CTS_CURRENT_TIME_VAL 0x2a2b
/** @def BLE_MESH_UUID_MAGN_DECLINATION
* @brief Magnetic Declination Characteristic
*/
#define BLE_MESH_UUID_MAGN_DECLINATION BLE_MESH_UUID_DECLARE_16(0x2a2c)
#define BLE_MESH_UUID_MAGN_DECLINATION_VAL 0x2a2c
/** @def BLE_MESH_UUID_HRS_MEASUREMENT
* @brief HRS Characteristic Measurement Interval
*/
#define BLE_MESH_UUID_HRS_MEASUREMENT BLE_MESH_UUID_DECLARE_16(0x2a37)
#define BLE_MESH_UUID_HRS_MEASUREMENT_VAL 0x2a37
/** @def BLE_MESH_UUID_HRS_BODY_SENSOR
* @brief HRS Characteristic Body Sensor Location
*/
#define BLE_MESH_UUID_HRS_BODY_SENSOR BLE_MESH_UUID_DECLARE_16(0x2a38)
#define BLE_MESH_UUID_HRS_BODY_SENSOR_VAL 0x2a38
/** @def BLE_MESH_UUID_HRS_CONTROL_POINT
* @brief HRS Characteristic Control Point
*/
#define BLE_MESH_UUID_HRS_CONTROL_POINT BLE_MESH_UUID_DECLARE_16(0x2a39)
#define BLE_MESH_UUID_HRS_CONTROL_POINT_VAL 0x2a39
/** @def BLE_MESH_UUID_HIDS_INFO
* @brief HID Information Characteristic
*/
#define BLE_MESH_UUID_HIDS_INFO BLE_MESH_UUID_DECLARE_16(0x2a4a)
#define BLE_MESH_UUID_HIDS_INFO_VAL 0x2a4a
/** @def BLE_MESH_UUID_HIDS_REPORT_MAP
* @brief HID Report Map Characteristic
*/
#define BLE_MESH_UUID_HIDS_REPORT_MAP BLE_MESH_UUID_DECLARE_16(0x2a4b)
#define BLE_MESH_UUID_HIDS_REPORT_MAP_VAL 0x2a4b
/** @def BLE_MESH_UUID_HIDS_CTRL_POINT
* @brief HID Control Point Characteristic
*/
#define BLE_MESH_UUID_HIDS_CTRL_POINT BLE_MESH_UUID_DECLARE_16(0x2a4c)
#define BLE_MESH_UUID_HIDS_CTRL_POINT_VAL 0x2a4c
/** @def BLE_MESH_UUID_HIDS_REPORT
* @brief HID Report Characteristic
*/
#define BLE_MESH_UUID_HIDS_REPORT BLE_MESH_UUID_DECLARE_16(0x2a4d)
#define BLE_MESH_UUID_HIDS_REPORT_VAL 0x2a4d
/** @def BLE_MESH_UUID_CSC_MEASUREMENT
* @brief CSC Measurement Characteristic
*/
#define BLE_MESH_UUID_CSC_MEASUREMENT BLE_MESH_UUID_DECLARE_16(0x2a5b)
#define BLE_MESH_UUID_CSC_MEASUREMENT_VAL 0x2a5b
/** @def BLE_MESH_UUID_CSC_FEATURE
* @brief CSC Feature Characteristic
*/
#define BLE_MESH_UUID_CSC_FEATURE BLE_MESH_UUID_DECLARE_16(0x2a5c)
#define BLE_MESH_UUID_CSC_FEATURE_VAL 0x2a5c
/** @def BLE_MESH_UUID_SENSOR_LOCATION
* @brief Sensor Location Characteristic
*/
#define BLE_MESH_UUID_SENSOR_LOCATION BLE_MESH_UUID_DECLARE_16(0x2a5d)
#define BLE_MESH_UUID_SENSOR_LOCATION_VAL 0x2a5d
/** @def BLE_MESH_UUID_SC_CONTROL_POINT
* @brief SC Control Point Characteristic
*/
#define BLE_MESH_UUID_SC_CONTROL_POINT BLE_MESH_UUID_DECLARE_16(0x2a55)
#define BLE_MESH_UUID_SC_CONTROL_POINT_VAl 0x2a55
/** @def BLE_MESH_UUID_ELEVATION
* @brief Elevation Characteristic
*/
#define BLE_MESH_UUID_ELEVATION BLE_MESH_UUID_DECLARE_16(0x2a6c)
#define BLE_MESH_UUID_ELEVATION_VAL 0x2a6c
/** @def BLE_MESH_UUID_PRESSURE
* @brief Pressure Characteristic
*/
#define BLE_MESH_UUID_PRESSURE BLE_MESH_UUID_DECLARE_16(0x2a6d)
#define BLE_MESH_UUID_PRESSURE_VAL 0x2a6d
/** @def BLE_MESH_UUID_TEMPERATURE
* @brief Temperature Characteristic
*/
#define BLE_MESH_UUID_TEMPERATURE BLE_MESH_UUID_DECLARE_16(0x2a6e)
#define BLE_MESH_UUID_TEMPERATURE_VAL 0x2a6e
/** @def BLE_MESH_UUID_HUMIDITY
* @brief Humidity Characteristic
*/
#define BLE_MESH_UUID_HUMIDITY BLE_MESH_UUID_DECLARE_16(0x2a6f)
#define BLE_MESH_UUID_HUMIDITY_VAL 0x2a6f
/** @def BLE_MESH_UUID_TRUE_WIND_SPEED
* @brief True Wind Speed Characteristic
*/
#define BLE_MESH_UUID_TRUE_WIND_SPEED BLE_MESH_UUID_DECLARE_16(0x2a70)
#define BLE_MESH_UUID_TRUE_WIND_SPEED_VAL 0x2a70
/** @def BLE_MESH_UUID_TRUE_WIND_DIR
* @brief True Wind Direction Characteristic
*/
#define BLE_MESH_UUID_TRUE_WIND_DIR BLE_MESH_UUID_DECLARE_16(0x2a71)
#define BLE_MESH_UUID_TRUE_WIND_DIR_VAL 0x2a71
/** @def BLE_MESH_UUID_APPARENT_WIND_SPEED
* @brief Apparent Wind Speed Characteristic
*/
#define BLE_MESH_UUID_APPARENT_WIND_SPEED BLE_MESH_UUID_DECLARE_16(0x2a72)
#define BLE_MESH_UUID_APPARENT_WIND_SPEED_VAL 0x2a72
/** @def BLE_MESH_UUID_APPARENT_WIND_DIR
* @brief Apparent Wind Direction Characteristic
*/
#define BLE_MESH_UUID_APPARENT_WIND_DIR BLE_MESH_UUID_DECLARE_16(0x2a73)
#define BLE_MESH_UUID_APPARENT_WIND_DIR_VAL 0x2a73
/** @def BLE_MESH_UUID_GUST_FACTOR
* @brief Gust Factor Characteristic
*/
#define BLE_MESH_UUID_GUST_FACTOR BLE_MESH_UUID_DECLARE_16(0x2a74)
#define BLE_MESH_UUID_GUST_FACTOR_VAL 0x2a74
/** @def BLE_MESH_UUID_POLLEN_CONCENTRATION
* @brief Pollen Concentration Characteristic
*/
#define BLE_MESH_UUID_POLLEN_CONCENTRATION BLE_MESH_UUID_DECLARE_16(0x2a75)
#define BLE_MESH_UUID_POLLEN_CONCENTRATION_VAL 0x2a75
/** @def BLE_MESH_UUID_UV_INDEX
* @brief UV Index Characteristic
*/
#define BLE_MESH_UUID_UV_INDEX BLE_MESH_UUID_DECLARE_16(0x2a76)
#define BLE_MESH_UUID_UV_INDEX_VAL 0x2a76
/** @def BLE_MESH_UUID_IRRADIANCE
* @brief Irradiance Characteristic
*/
#define BLE_MESH_UUID_IRRADIANCE BLE_MESH_UUID_DECLARE_16(0x2a77)
#define BLE_MESH_UUID_IRRADIANCE_VAL 0x2a77
/** @def BLE_MESH_UUID_RAINFALL
* @brief Rainfall Characteristic
*/
#define BLE_MESH_UUID_RAINFALL BLE_MESH_UUID_DECLARE_16(0x2a78)
#define BLE_MESH_UUID_RAINFALL_VAL 0x2a78
/** @def BLE_MESH_UUID_WIND_CHILL
* @brief Wind Chill Characteristic
*/
#define BLE_MESH_UUID_WIND_CHILL BLE_MESH_UUID_DECLARE_16(0x2a79)
#define BLE_MESH_UUID_WIND_CHILL_VAL 0x2a79
/** @def BLE_MESH_UUID_HEAT_INDEX
* @brief Heat Index Characteristic
*/
#define BLE_MESH_UUID_HEAT_INDEX BLE_MESH_UUID_DECLARE_16(0x2a7a)
#define BLE_MESH_UUID_HEAT_INDEX_VAL 0x2a7a
/** @def BLE_MESH_UUID_DEW_POINT
* @brief Dew Point Characteristic
*/
#define BLE_MESH_UUID_DEW_POINT BLE_MESH_UUID_DECLARE_16(0x2a7b)
#define BLE_MESH_UUID_DEW_POINT_VAL 0x2a7b
/** @def BLE_MESH_UUID_DESC_VALUE_CHANGED
* @brief Descriptor Value Changed Characteristic
*/
#define BLE_MESH_UUID_DESC_VALUE_CHANGED BLE_MESH_UUID_DECLARE_16(0x2a7d)
#define BLE_MESH_UUID_DESC_VALUE_CHANGED_VAL 0x2a7d
/** @def BLE_MESH_UUID_MAGN_FLUX_DENSITY_2D
* @brief Magnetic Flux Density - 2D Characteristic
*/
#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_2D BLE_MESH_UUID_DECLARE_16(0x2aa0)
#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_2D_VAL 0x2aa0
/** @def BLE_MESH_UUID_MAGN_FLUX_DENSITY_3D
* @brief Magnetic Flux Density - 3D Characteristic
*/
#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_3D BLE_MESH_UUID_DECLARE_16(0x2aa1)
#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_3D_VAL 0x2aa1
/** @def BLE_MESH_UUID_BAR_PRESSURE_TREND
* @brief Barometric Pressure Trend Characteristic
*/
#define BLE_MESH_UUID_BAR_PRESSURE_TREND BLE_MESH_UUID_DECLARE_16(0x2aa3)
#define BLE_MESH_UUID_BAR_PRESSURE_TREND_VAL 0x2aa3
/** @def BLE_MESH_UUID_MESH_PROV_DATA_IN
* @brief Mesh Provisioning Data In
*/
#define BLE_MESH_UUID_MESH_PROV_DATA_IN BLE_MESH_UUID_DECLARE_16(0x2adb)
#define BLE_MESH_UUID_MESH_PROV_DATA_IN_VAL 0x2adb
/** @def BLE_MESH_UUID_MESH_PROV_DATA_OUT
* @brief Mesh Provisioning Data Out
*/
#define BLE_MESH_UUID_MESH_PROV_DATA_OUT BLE_MESH_UUID_DECLARE_16(0x2adc)
#define BLE_MESH_UUID_MESH_PROV_DATA_OUT_VAL 0x2adc
/** @def BLE_MESH_UUID_MESH_PROXY_DATA_IN
* @brief Mesh Proxy Data In
*/
#define BLE_MESH_UUID_MESH_PROXY_DATA_IN BLE_MESH_UUID_DECLARE_16(0x2add)
#define BLE_MESH_UUID_MESH_PROXY_DATA_IN_VAL 0x2add
/** @def BLE_MESH_UUID_MESH_PROXY_DATA_OUT
* @brief Mesh Proxy Data Out
*/
#define BLE_MESH_UUID_MESH_PROXY_DATA_OUT BLE_MESH_UUID_DECLARE_16(0x2ade)
#define BLE_MESH_UUID_MESH_PROXY_DATA_OUT_VAL 0x2ade
/*
* Protocol UUIDs
*/
#define BLE_MESH_UUID_SDP BLE_MESH_UUID_DECLARE_16(0x0001)
#define BLE_MESH_UUID_SDP_VAL 0x0001
#define BLE_MESH_UUID_UDP BLE_MESH_UUID_DECLARE_16(0x0002)
#define BLE_MESH_UUID_UDP_VAL 0x0002
#define BLE_MESH_UUID_RFCOMM BLE_MESH_UUID_DECLARE_16(0x0003)
#define BLE_MESH_UUID_RFCOMM_VAL 0x0003
#define BLE_MESH_UUID_TCP BLE_MESH_UUID_DECLARE_16(0x0004)
#define BLE_MESH_UUID_TCP_VAL 0x0004
#define BLE_MESH_UUID_TCS_BIN BLE_MESH_UUID_DECLARE_16(0x0005)
#define BLE_MESH_UUID_TCS_BIN_VAL 0x0005
#define BLE_MESH_UUID_TCS_AT BLE_MESH_UUID_DECLARE_16(0x0006)
#define BLE_MESH_UUID_TCS_AT_VAL 0x0006
#define BLE_MESH_UUID_ATT BLE_MESH_UUID_DECLARE_16(0x0007)
#define BLE_MESH_UUID_ATT_VAL 0x0007
#define BLE_MESH_UUID_OBEX BLE_MESH_UUID_DECLARE_16(0x0008)
#define BLE_MESH_UUID_OBEX_VAL 0x0008
#define BLE_MESH_UUID_IP BLE_MESH_UUID_DECLARE_16(0x0009)
#define BLE_MESH_UUID_IP_VAL 0x0009
#define BLE_MESH_UUID_FTP BLE_MESH_UUID_DECLARE_16(0x000a)
#define BLE_MESH_UUID_FTP_VAL 0x000a
#define BLE_MESH_UUID_HTTP BLE_MESH_UUID_DECLARE_16(0x000c)
#define BLE_MESH_UUID_HTTP_VAL 0x000c
#define BLE_MESH_UUID_BNEP BLE_MESH_UUID_DECLARE_16(0x000f)
#define BLE_MESH_UUID_BNEP_VAL 0x000f
#define BLE_MESH_UUID_UPNP BLE_MESH_UUID_DECLARE_16(0x0010)
#define BLE_MESH_UUID_UPNP_VAL 0x0010
#define BLE_MESH_UUID_HIDP BLE_MESH_UUID_DECLARE_16(0x0011)
#define BLE_MESH_UUID_HIDP_VAL 0x0011
#define BLE_MESH_UUID_HCRP_CTRL BLE_MESH_UUID_DECLARE_16(0x0012)
#define BLE_MESH_UUID_HCRP_CTRL_VAL 0x0012
#define BLE_MESH_UUID_HCRP_DATA BLE_MESH_UUID_DECLARE_16(0x0014)
#define BLE_MESH_UUID_HCRP_DATA_VAL 0x0014
#define BLE_MESH_UUID_HCRP_NOTE BLE_MESH_UUID_DECLARE_16(0x0016)
#define BLE_MESH_UUID_HCRP_NOTE_VAL 0x0016
#define BLE_MESH_UUID_AVCTP BLE_MESH_UUID_DECLARE_16(0x0017)
#define BLE_MESH_UUID_AVCTP_VAL 0x0017
#define BLE_MESH_UUID_AVDTP BLE_MESH_UUID_DECLARE_16(0x0019)
#define BLE_MESH_UUID_AVDTP_VAL 0x0019
#define BLE_MESH_UUID_CMTP BLE_MESH_UUID_DECLARE_16(0x001b)
#define BLE_MESH_UUID_CMTP_VAL 0x001b
#define BLE_MESH_UUID_UDI BLE_MESH_UUID_DECLARE_16(0x001d)
#define BLE_MESH_UUID_UDI_VAL 0x001d
#define BLE_MESH_UUID_MCAP_CTRL BLE_MESH_UUID_DECLARE_16(0x001e)
#define BLE_MESH_UUID_MCAP_CTRL_VAL 0x001e
#define BLE_MESH_UUID_MCAP_DATA BLE_MESH_UUID_DECLARE_16(0x001f)
#define BLE_MESH_UUID_MCAP_DATA_VAL 0x001f
#define BLE_MESH_UUID_L2CAP BLE_MESH_UUID_DECLARE_16(0x0100)
#define BLE_MESH_UUID_L2CAP_VAL 0x0100
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* _BLE_MESH_UUID_H_ */

View File

@ -0,0 +1,41 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _LOCAL_OPERATION_H_
#define _LOCAL_OPERATION_H_
#include "mesh_types.h"
#ifdef __cplusplus
extern "C" {
#endif
int bt_mesh_model_subscribe_group_addr(uint16_t elem_addr, uint16_t mod_id,
uint16_t cid, uint16_t group_addr);
int bt_mesh_model_unsubscribe_group_addr(uint16_t elem_addr, uint16_t cid,
uint16_t mod_id, uint16_t group_addr);
const uint8_t *bt_mesh_node_get_local_net_key(uint16_t net_idx);
const uint8_t *bt_mesh_node_get_local_app_key(uint16_t app_idx);
int bt_mesh_node_local_net_key_add(uint16_t net_idx, const uint8_t net_key[16]);
int bt_mesh_node_local_app_key_add(uint16_t net_idx, uint16_t app_idx,
const uint8_t app_key[16]);
int bt_mesh_node_bind_app_key_to_model(uint16_t elem_addr, uint16_t mod_id,
uint16_t cid, uint16_t app_idx);
#ifdef __cplusplus
}
#endif
#endif /* _LOCAL_OPERATION_H_ */

View File

@ -0,0 +1,78 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _LPN_H_
#define _LPN_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf);
static inline bool bt_mesh_lpn_established(void)
{
#if defined(CONFIG_BLE_MESH_LOW_POWER)
return bt_mesh.lpn.established;
#else
return false;
#endif
}
static inline bool bt_mesh_lpn_match(uint16_t addr)
{
#if defined(CONFIG_BLE_MESH_LOW_POWER)
if (bt_mesh_lpn_established()) {
return (addr == bt_mesh.lpn.frnd);
}
#endif
return false;
}
static inline bool bt_mesh_lpn_waiting_update(void)
{
#if defined(CONFIG_BLE_MESH_LOW_POWER)
return (bt_mesh.lpn.state == BLE_MESH_LPN_WAIT_UPDATE);
#else
return false;
#endif
}
static inline bool bt_mesh_lpn_timer(void)
{
#if defined(CONFIG_BLE_MESH_LPN_AUTO)
return (bt_mesh.lpn.state == BLE_MESH_LPN_TIMER);
#else
return false;
#endif
}
void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx);
void bt_mesh_lpn_group_add(uint16_t group);
void bt_mesh_lpn_group_del(uint16_t *groups, size_t group_count);
void bt_mesh_lpn_disable(bool force);
int bt_mesh_lpn_init(void);
int bt_mesh_lpn_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _LPN_H_ */

View File

@ -0,0 +1,33 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _MESH_H_
#define _MESH_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_KEY_PRIMARY 0x0000
#define BLE_MESH_KEY_ANY 0xffff
#define BLE_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000)
#define BLE_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) < 0xff00)
#define BLE_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000)
#define BLE_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb)
struct bt_mesh_net;
#ifdef __cplusplus
}
#endif
#endif /* _MESH_H_ */

View File

@ -0,0 +1,423 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _NET_H_
#define _NET_H_
#include "mesh_access.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_NET_FLAG_KR BIT(0)
#define BLE_MESH_NET_FLAG_IVU BIT(1)
#define BLE_MESH_KR_NORMAL 0x00
#define BLE_MESH_KR_PHASE_1 0x01
#define BLE_MESH_KR_PHASE_2 0x02
#define BLE_MESH_KR_PHASE_3 0x03
#define BLE_MESH_IV_UPDATE(flags) ((flags >> 1) & 0x01)
#define BLE_MESH_KEY_REFRESH(flags) (flags & 0x01)
/* How many hours in between updating IVU duration */
#define BLE_MESH_IVU_MIN_HOURS 96
#define BLE_MESH_IVU_HOURS (BLE_MESH_IVU_MIN_HOURS / CONFIG_BLE_MESH_IVU_DIVIDER)
#define BLE_MESH_IVU_TIMEOUT K_HOURS(BLE_MESH_IVU_HOURS)
struct bt_mesh_app_key {
uint16_t net_idx;
uint16_t app_idx;
bool updated;
struct bt_mesh_app_keys {
uint8_t id;
uint8_t val[16];
} keys[2];
};
struct bt_mesh_subnet {
uint32_t beacon_sent; /* Timestamp of last sent beacon */
uint8_t beacons_last; /* Number of beacons during last observation window. */
uint8_t beacons_cur; /* Number of beacons observed during currently ongoing window. */
uint8_t beacon_cache[21]; /* Cached last authenticated beacon */
uint16_t net_idx; /* NetKeyIndex */
bool kr_flag; /* Key Refresh Flag */
uint8_t kr_phase; /* Key Refresh Phase */
uint8_t node_id; /* Node Identity State */
uint32_t node_id_start; /* Node Identity started timestamp */
uint8_t auth[8]; /* Beacon Authentication Value */
struct bt_mesh_subnet_keys {
uint8_t net[16]; /* NetKey */
uint8_t nid; /* NID */
uint8_t enc[16]; /* EncKey */
uint8_t net_id[8]; /* Network ID */
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
uint8_t identity[16]; /* IdentityKey */
#endif
uint8_t privacy[16]; /* PrivacyKey */
uint8_t beacon[16]; /* BeaconKey */
} keys[2];
};
struct bt_mesh_rpl {
uint16_t src;
bool old_iv;
#if defined(CONFIG_BLE_MESH_SETTINGS)
bool store;
#endif
uint32_t seq;
};
#if defined(CONFIG_BLE_MESH_FRIEND)
#define FRIEND_SEG_RX CONFIG_BLE_MESH_FRIEND_SEG_RX
#define FRIEND_SUB_LIST_SIZE CONFIG_BLE_MESH_FRIEND_SUB_LIST_SIZE
#else
#define FRIEND_SEG_RX 0
#define FRIEND_SUB_LIST_SIZE 0
#endif
struct bt_mesh_friend {
uint16_t lpn;
uint8_t recv_delay;
uint8_t fsn:1,
send_last:1,
pending_req:1,
pending_buf:1,
valid:1,
established:1;
int32_t poll_to;
uint8_t num_elem;
uint16_t lpn_counter;
uint16_t counter;
uint16_t net_idx;
uint16_t sub_list[FRIEND_SUB_LIST_SIZE];
struct k_delayed_work timer;
struct bt_mesh_friend_seg {
sys_slist_t queue;
/* The target number of segments, i.e. not necessarily
* the current number of segments, in the queue. This is
* used for Friend Queue free space calculations.
*/
uint8_t seg_count;
} seg[FRIEND_SEG_RX];
struct net_buf *last;
sys_slist_t queue;
uint32_t queue_size;
/* Friend Clear Procedure */
struct {
uint32_t start; /* Clear Procedure start */
uint16_t frnd; /* Previous Friend's address */
uint16_t repeat_sec; /* Repeat timeout in seconds */
struct k_delayed_work timer; /* Repeat timer */
} clear;
};
#if defined(CONFIG_BLE_MESH_LOW_POWER)
#define LPN_GROUPS CONFIG_BLE_MESH_LPN_GROUPS
#else
#define LPN_GROUPS 0
#endif
/* Low Power Node state */
struct bt_mesh_lpn {
enum __packed {
BLE_MESH_LPN_DISABLED, /* LPN feature is disabled */
BLE_MESH_LPN_CLEAR, /* Clear in progress */
BLE_MESH_LPN_TIMER, /* Waiting for auto timer expiry */
BLE_MESH_LPN_ENABLED, /* LPN enabled, but no Friend */
BLE_MESH_LPN_REQ_WAIT, /* Wait before scanning for offers */
BLE_MESH_LPN_WAIT_OFFER, /* Friend Req sent */
BLE_MESH_LPN_ESTABLISHED, /* Friendship established */
BLE_MESH_LPN_RECV_DELAY, /* Poll sent, waiting ReceiveDelay */
BLE_MESH_LPN_WAIT_UPDATE, /* Waiting for Update or message */
BLE_MESH_LPN_OFFER_RECV, /* Friend offer received */
} state;
/* Transaction Number (used for subscription list) */
uint8_t xact_next;
uint8_t xact_pending;
uint8_t sent_req;
/* Address of our Friend when we're a LPN. Unassigned if we don't
* have a friend yet.
*/
uint16_t frnd;
/* Value from the friend offer */
uint8_t recv_win;
uint8_t req_attempts; /* Number of Request attempts */
int32_t poll_timeout;
uint8_t groups_changed: 1, /* Friend Subscription List needs updating */
pending_poll: 1, /* Poll to be sent after subscription */
disable: 1, /* Disable LPN after clearing */
fsn: 1, /* Friend Sequence Number */
established: 1, /* Friendship established */
clear_success: 1; /* Friend Clear Confirm received */
/* Friend Queue Size */
uint8_t queue_size;
/* LPNCounter */
uint16_t counter;
/* Previous Friend of this LPN */
uint16_t old_friend;
/* Duration reported for last advertising packet */
uint16_t adv_duration;
/* Next LPN related action timer */
struct k_delayed_work timer;
/* Subscribed groups */
uint16_t groups[LPN_GROUPS];
/* Bit fields for tracking which groups the Friend knows about */
BLE_MESH_ATOMIC_DEFINE(added, LPN_GROUPS);
BLE_MESH_ATOMIC_DEFINE(pending, LPN_GROUPS);
BLE_MESH_ATOMIC_DEFINE(to_remove, LPN_GROUPS);
};
/* bt_mesh_net.flags */
enum {
BLE_MESH_NODE, /* Device is a node */
BLE_MESH_PROVISIONER, /* Device is a Provisioner */
BLE_MESH_VALID, /* We have been provisioned */
BLE_MESH_VALID_PROV, /* Provisioner has been enabled */
BLE_MESH_SUSPENDED, /* Network is temporarily suspended */
BLE_MESH_IVU_IN_PROGRESS, /* IV Update in Progress */
BLE_MESH_IVU_INITIATOR, /* IV Update initiated by us */
BLE_MESH_IVU_TEST, /* IV Update test mode */
BLE_MESH_IVU_PENDING, /* Update blocked by SDU in progress */
/* pending storage actions, must reside within first 32 flags */
BLE_MESH_RPL_PENDING,
BLE_MESH_KEYS_PENDING,
BLE_MESH_NET_PENDING,
BLE_MESH_IV_PENDING,
BLE_MESH_SEQ_PENDING,
BLE_MESH_HB_PUB_PENDING,
BLE_MESH_CFG_PENDING,
BLE_MESH_MOD_PENDING,
BLE_MESH_VA_PENDING,
/* Don't touch - intentionally last */
BLE_MESH_FLAG_COUNT,
};
struct bt_mesh_net {
uint32_t iv_index; /* Current IV Index */
uint32_t seq; /* Next outgoing sequence number (24 bits) */
BLE_MESH_ATOMIC_DEFINE(flags, BLE_MESH_FLAG_COUNT);
/* Local network interface */
struct k_work local_work;
sys_slist_t local_queue;
#if defined(CONFIG_BLE_MESH_FRIEND)
/* Friend state, unique for each LPN that we're Friends for */
struct bt_mesh_friend frnd[CONFIG_BLE_MESH_FRIEND_LPN_COUNT];
#endif
#if defined(CONFIG_BLE_MESH_LOW_POWER)
struct bt_mesh_lpn lpn; /* Low Power Node state */
#endif
/* Number of hours in current IV Update state */
uint8_t ivu_duration;
/* Timer to track duration in current IV Update state */
struct k_delayed_work ivu_timer;
uint8_t dev_key[16];
struct bt_mesh_app_key app_keys[CONFIG_BLE_MESH_APP_KEY_COUNT];
struct bt_mesh_subnet sub[CONFIG_BLE_MESH_SUBNET_COUNT];
struct bt_mesh_rpl rpl[CONFIG_BLE_MESH_CRPL];
#if defined(CONFIG_BLE_MESH_PROVISIONER)
/* Application keys stored by provisioner */
struct bt_mesh_app_key *p_app_keys[CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT];
/* Next app_idx can be assigned */
uint16_t p_app_idx_next;
/* Network keys stored by provisioner */
struct bt_mesh_subnet *p_sub[CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT];
/* Next net_idx can be assigned */
uint16_t p_net_idx_next;
#endif
};
/* Network interface */
enum bt_mesh_net_if {
BLE_MESH_NET_IF_ADV,
BLE_MESH_NET_IF_LOCAL,
BLE_MESH_NET_IF_PROXY,
BLE_MESH_NET_IF_PROXY_CFG,
};
/* Decoding context for Network/Transport data */
struct bt_mesh_net_rx {
struct bt_mesh_subnet *sub;
struct bt_mesh_msg_ctx ctx;
uint32_t seq; /* Sequence Number */
uint8_t old_iv:1, /* iv_index - 1 was used */
new_key:1, /* Data was encrypted with updated key */
friend_cred:1, /* Data was encrypted with friend cred */
ctl:1, /* Network Control */
net_if:2, /* Network interface */
local_match:1, /* Matched a local element */
friend_match:1; /* Matched an LPN we're friends for */
uint16_t msg_cache_idx; /* Index of entry in message cache */
};
/* Encoding context for Network/Transport data */
struct bt_mesh_net_tx {
struct bt_mesh_subnet *sub;
struct bt_mesh_msg_ctx *ctx;
uint16_t src;
uint8_t xmit;
uint8_t friend_cred:1,
aszmic:1,
aid: 6;
};
extern struct bt_mesh_net bt_mesh;
#define BLE_MESH_NET_IVI_TX (bt_mesh.iv_index - \
bt_mesh_atomic_test_bit(bt_mesh.flags, \
BLE_MESH_IVU_IN_PROGRESS))
#define BLE_MESH_NET_IVI_RX(rx) (bt_mesh.iv_index - (rx)->old_iv)
#define BLE_MESH_NET_HDR_LEN 9
void bt_mesh_msg_cache_clear(uint16_t unicast_addr, uint8_t elem_num);
int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
const uint8_t key[16]);
int bt_mesh_net_create(uint16_t idx, uint8_t flags, const uint8_t key[16],
uint32_t iv_index);
uint8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub);
bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, uint8_t new_kr, bool new_key);
void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub);
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub);
void bt_mesh_rpl_reset(void);
bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update);
void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub);
struct bt_mesh_subnet *bt_mesh_subnet_get(uint16_t net_idx);
struct bt_mesh_subnet *bt_mesh_subnet_find(const uint8_t net_id[8], uint8_t flags,
uint32_t iv_index, const uint8_t auth[8],
bool *new_key);
int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
bool proxy);
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
bool new_key, const struct bt_mesh_send_cb *cb,
void *cb_data);
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
enum bt_mesh_net_if net_if);
bool bt_mesh_primary_subnet_exist(void);
uint32_t bt_mesh_next_seq(void);
void bt_mesh_net_start(void);
void bt_mesh_net_init(void);
void bt_mesh_net_reset(void);
void bt_mesh_net_deinit(void);
void bt_mesh_net_header_parse(struct net_buf_simple *buf,
struct bt_mesh_net_rx *rx);
/* Friendship Credential Management */
struct friend_cred {
uint16_t net_idx;
uint16_t addr;
uint16_t lpn_counter;
uint16_t frnd_counter;
struct {
uint8_t nid; /* NID */
uint8_t enc[16]; /* EncKey */
uint8_t privacy[16]; /* PrivacyKey */
} cred[2];
};
int friend_cred_get(struct bt_mesh_subnet *sub, uint16_t addr, uint8_t *nid,
const uint8_t **enc, const uint8_t **priv);
int friend_cred_set(struct friend_cred *cred, uint8_t idx, const uint8_t net_key[16]);
void friend_cred_refresh(uint16_t net_idx);
int friend_cred_update(struct bt_mesh_subnet *sub);
struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, uint16_t addr,
uint16_t lpn_counter, uint16_t frnd_counter);
void friend_cred_clear(struct friend_cred *cred);
int friend_cred_del(uint16_t net_idx, uint16_t addr);
static inline void send_cb_finalize(const struct bt_mesh_send_cb *cb,
void *cb_data)
{
if (!cb) {
return;
}
if (cb->start) {
cb->start(0, 0, cb_data);
}
if (cb->end) {
cb->end(0, cb_data);
}
}
#ifdef __cplusplus
}
#endif
#endif /* _NET_H_ */

View File

@ -0,0 +1,43 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROV_H_
#define _PROV_H_
#include "mesh_main.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
void bt_mesh_pb_adv_recv(struct net_buf_simple *buf);
bool bt_prov_active(void);
int bt_mesh_pb_gatt_open(struct bt_mesh_conn *conn);
int bt_mesh_pb_gatt_close(struct bt_mesh_conn *conn);
int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf);
int bt_mesh_set_oob_pub_key(const uint8_t pub_key_x[32], const uint8_t pub_key_y[32],
const uint8_t pri_key[32]);
const struct bt_mesh_prov *bt_mesh_prov_get(void);
int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
int bt_mesh_prov_deinit(void);
void bt_mesh_prov_complete(uint16_t net_idx, const uint8_t net_key[16],
uint16_t addr, uint8_t flags, uint32_t iv_index);
void bt_mesh_prov_reset(void);
#ifdef __cplusplus
}
#endif
#endif /* _PROV_H_ */

View File

@ -0,0 +1,145 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROVISIONER_MAIN_H_
#define _PROVISIONER_MAIN_H_
#include "net.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_INVALID_NODE_INDEX 0xFFFF
#define BLE_MESH_NODE_NAME_SIZE 31
/* Each node information stored by provisioner */
struct bt_mesh_node {
/* Device information */
uint8_t addr[6]; /* Node device address */
uint8_t addr_type; /* Node device address type */
uint8_t dev_uuid[16]; /* Node Device UUID */
uint16_t oob_info; /* Node OOB information */
/* Provisioning information */
uint16_t unicast_addr; /* Node unicast address */
uint8_t element_num; /* Node element number */
uint16_t net_idx; /* Node NetKey Index */
uint8_t flags; /* Node key refresh flag and iv update flag */
uint32_t iv_index; /* Node IV Index */
uint8_t dev_key[16]; /* Node device key */
/* Additional information */
char name[BLE_MESH_NODE_NAME_SIZE + 1]; /* Node name */
uint16_t comp_length; /* Length of Composition Data */
uint8_t *comp_data; /* Value of Composition Data */
} __packed;
int bt_mesh_provisioner_init(void);
int bt_mesh_provisioner_net_create(void);
void bt_mesh_provisioner_main_reset(bool erase);
int bt_mesh_provisioner_deinit(bool erase);
bool bt_mesh_provisioner_check_is_addr_dup(uint16_t addr, uint8_t elem_num, bool comp_with_own);
uint16_t bt_mesh_provisioner_get_node_count(void);
int bt_mesh_provisioner_restore_node_info(struct bt_mesh_node *node);
int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const uint8_t uuid[16],
uint16_t oob_info, uint16_t unicast_addr,
uint8_t element_num, uint16_t net_idx,
uint8_t flags, uint32_t iv_index,
const uint8_t dev_key[16], uint16_t *index);
int bt_mesh_provisioner_remove_node(const uint8_t uuid[16]);
int bt_mesh_provisioner_restore_node_name(uint16_t addr, const char *name);
int bt_mesh_provisioner_restore_node_comp_data(uint16_t addr, const uint8_t *data, uint16_t length);
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
int bt_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16]);
int bt_mesh_provisioner_delete_node_with_node_addr(uint16_t unicast_addr);
int bt_mesh_provisioner_delete_node_with_dev_addr(const bt_mesh_addr_t *addr);
int bt_mesh_provisioner_set_node_name(uint16_t index, const char *name);
const char *bt_mesh_provisioner_get_node_name(uint16_t index);
uint16_t bt_mesh_provisioner_get_node_index(const char *name);
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_name(const char *name);
const struct bt_mesh_node **bt_mesh_provisioner_get_node_table_entry(void);
int bt_mesh_provisioner_store_node_comp_data(uint16_t addr, const uint8_t *data, uint16_t length);
const uint8_t *bt_mesh_provisioner_net_key_get(uint16_t net_idx);
struct bt_mesh_subnet *bt_mesh_provisioner_subnet_get(uint16_t net_idx);
bool bt_mesh_provisioner_check_msg_dst(uint16_t dst);
const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t dst);
struct bt_mesh_app_key *bt_mesh_provisioner_app_key_find(uint16_t app_idx);
int bt_mesh_provisioner_local_app_key_add(const uint8_t app_key[16],
uint16_t net_idx, uint16_t *app_idx);
int bt_mesh_provisioner_local_app_key_update(const uint8_t app_key[16],
uint16_t net_idx, uint16_t app_idx);
const uint8_t *bt_mesh_provisioner_local_app_key_get(uint16_t net_idx, uint16_t app_idx);
int bt_mesh_provisioner_local_app_key_del(uint16_t net_idx, uint16_t app_idx, bool store);
int bt_mesh_provisioner_local_net_key_add(const uint8_t net_key[16], uint16_t *net_idx);
int bt_mesh_provisioner_local_net_key_update(const uint8_t net_key[16], uint16_t net_idx);
const uint8_t *bt_mesh_provisioner_local_net_key_get(uint16_t net_idx);
int bt_mesh_provisioner_local_net_key_del(uint16_t net_idx, bool store);
/* Provisioner bind local client model with proper appkey index */
int bt_mesh_provisioner_bind_local_model_app_idx(uint16_t elem_addr, uint16_t mod_id,
uint16_t cid, uint16_t app_idx);
typedef void (* bt_mesh_heartbeat_recv_cb_t)(uint16_t hb_src, uint16_t hb_dst,
uint8_t init_ttl, uint8_t rx_ttl,
uint8_t hops, uint16_t feat, int8_t rssi);
int bt_mesh_provisioner_recv_heartbeat(bt_mesh_heartbeat_recv_cb_t cb);
int bt_mesh_provisioner_set_heartbeat_filter_type(uint8_t filter_type);
int bt_mesh_provisioner_set_heartbeat_filter_info(uint8_t op, uint16_t src, uint16_t dst);
void bt_mesh_provisioner_heartbeat(uint16_t hb_src, uint16_t hb_dst,
uint8_t init_ttl, uint8_t rx_ttl,
uint8_t hops, uint16_t feat, int8_t rssi);
/* Provisioner print own element information */
int bt_mesh_print_local_composition_data(void);
int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node);
#ifdef __cplusplus
}
#endif
#endif /* _PROVISIONER_MAIN_H_ */

View File

@ -0,0 +1,423 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROVISIONER_PROV_H_
#define _PROVISIONER_PROV_H_
#include "mesh_main.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CONFIG_BLE_MESH_PBA_SAME_TIME
#define CONFIG_BLE_MESH_PBA_SAME_TIME 0
#endif
#ifndef CONFIG_BLE_MESH_PBG_SAME_TIME
#define CONFIG_BLE_MESH_PBG_SAME_TIME 0
#endif
#define RM_AFTER_PROV BIT(0)
#define START_PROV_NOW BIT(1)
#define FLUSHABLE_DEV BIT(2)
struct bt_mesh_unprov_dev_add {
uint8_t addr[6];
uint8_t addr_type;
uint8_t uuid[16];
uint16_t oob_info;
uint8_t bearer;
};
struct bt_mesh_device_delete {
uint8_t addr[6];
uint8_t addr_type;
uint8_t uuid[16];
};
#define NET_IDX_FLAG BIT(0)
#define FLAGS_FLAG BIT(1)
#define IV_INDEX_FLAG BIT(2)
struct bt_mesh_prov_data_info {
union {
uint16_t net_idx;
uint8_t flags;
uint32_t iv_index;
};
uint8_t flag;
};
/* The following APIs are for primary provisioner internal use */
/**
* @brief This function decrements the current PB-GATT count.
*
* @return None
*/
void bt_mesh_provisioner_pbg_count_dec(void);
/**
* @brief This function clears the part of the link info of the proper device.
*
* @param[in] addr: Remote device address
*
* @return None
*/
void bt_mesh_provisioner_clear_link_info(const uint8_t addr[6]);
/**
* @brief This function handles the received PB-ADV PDUs.
*
* @param[in] buf: Pointer to the buffer containing generic provisioning PDUs
*
* @return Zero - success, otherwise - fail
*/
void bt_mesh_provisioner_pb_adv_recv(struct net_buf_simple *buf);
/**
* @brief This function sends provisioning invite to start
* provisioning this unprovisioned device.
*
* @param[in] addr: Remote device address
* @param[in] conn: Pointer to the bt_conn structure
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_prov_conn(const uint8_t addr[6], struct bt_mesh_conn *conn);
/**
* @brief This function sends provisioning invite to start
* provisioning this unprovisioned device.
*
* @param[in] conn: Pointer to the bt_conn structure
* @param[in] addr: Address of the connected device
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, uint8_t *addr);
/**
* @brief This function resets the used information when
* related connection is terminated.
*
* @param[in] conn: Pointer to the bt_conn structure
* @param[in] reason: Connection terminated reason
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_pb_gatt_close(struct bt_mesh_conn *conn, uint8_t reason);
/**
* @brief This function handles the received PB-GATT provision
* PDUs.
*
* @param[in] conn: Pointer to the bt_conn structure
* @param[in] buf: Pointer to the buffer containing provision PDUs
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf);
/**
* @brief This function initializes provisioner's PB-GATT and PB-ADV
* related information.
*
* @param[in] prov_info: Pointer to the application-initialized provisioner info.
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_prov_init(const struct bt_mesh_prov *prov_info);
int bt_mesh_provisioner_prov_reset(bool erase);
/**
* @brief This function de-initializes provisioner's PB-GATT and PB-ADV
* related information.
*
* @param[in] erase: Indicate if erasing provisioning information from flash.
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_prov_deinit(bool erase);
/**
* @brief This function parses the received unprovisioned device
* beacon advertising packets, and if checked, starts to provision this device
* using PB-ADV bearer.
*
* @param[in] buf: Pointer to the buffer containing unprovisioned device beacon
* @param[in] rssi: RSSI of the received unprovisioned device beacon
*
* @return None
*/
void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, int8_t rssi);
void bt_mesh_provisioner_prov_adv_recv(struct net_buf_simple *buf,
const bt_mesh_addr_t *addr, int8_t rssi);
/**
* @brief This function gets the bt_mesh_prov pointer.
*
* @return bt_mesh_prov pointer(prov)
*/
const struct bt_mesh_prov *bt_mesh_provisioner_get_prov_info(void);
void bt_mesh_provisioner_restore_prov_info(uint16_t primary_addr, uint16_t alloc_addr);
/* The following APIs are for primary provisioner application use */
/** @brief Add unprovisioned device info to unprov_dev queue
*
* @param[in] add_dev: Pointer to the structure containing the device information
* @param[in] flags: Flags indicate several operations of the device information
* - Remove device information from queue after it is provisioned (BIT0)
* - Start provisioning as soon as device is added to queue (BIT1)
* - Device can be flushed when device queue is full (BIT2)
*
* @return Zero on success or (negative) error code otherwise.
*
* @note 1. Currently address type only supports public address and static random address.
* 2. If device UUID and/or device address and address type already exist in the
* device queue, but the bearer differs from the existing one, add operation
* will also be successful and it will update the provision bearer supported by
* the device.
*/
int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, uint8_t flags);
/** @brief Provision an unprovisioned device with fixed unicast address.
*
* @param[in] uuid: Device UUID of the unprovisioned device
* @param[in] addr: Device address of the unprovisioned device
* @param[in] addr_type: Device address type of the unprovisioned device
* @param[in] bearer: Provisioning bearer going to be used
* @param[in] oob_info: OOB info of the unprovisioned device
* @param[in] unicast_addr: Unicast address going to be allocated for the unprovisioned device
*
* @return Zero on success or (negative) error code otherwise.
*
* @note 1. Currently address type only supports public address and static random address.
* 2. Bearer must be equal to BLE_MESH_PROV_ADV or BLE_MESH_PROV_GATT
*/
int bt_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16], const uint8_t addr[6],
uint8_t addr_type, bt_mesh_prov_bearer_t bearer,
uint16_t oob_info, uint16_t unicast_addr);
/** @brief Delete device from queue, reset current provisioning link and reset the node
*
* @param[in] del_dev: Pointer to the structure containing the device information
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev);
/**
* @brief This function sets a part of the device UUID for comparison before
* starting to provision the device.
*
* @param[in] offset: offset of the device UUID to be compared
* @param[in] length: length of the device UUID to be compared
* @param[in] match: value to be compared
* @param[in] prov_flag: flags indicate if uuid_match advertising packets are received, after that
* the device will be provisioned at once or reported to the application layer
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_dev_uuid_match(uint8_t offset, uint8_t length,
const uint8_t *match, bool prov_flag);
/** @brief Callback for provisioner receiving advertising packet from unprovisioned devices which are
* not in the unprovisioned device queue.
*
* Report on the unprovisioned device beacon and mesh provisioning service advertising data to application layer
*
* @param addr Unprovisioned device address pointer
* @param addr_type Unprovisioned device address type
* @param dev_uuid Unprovisioned device device UUID pointer
* @param bearer Advertising packet received from PB-GATT or PB-ADV bearer
* @param adv_type Adv packet type, currently this is not used and we can use bearer to device
* the adv_type(ADV_IND or ADV_NONCONN_IND). This parameter will be used, when
* scan response data will be supported.
* @param rssi RSSI of the received advertising packet
*
*/
typedef void (*unprov_adv_pkt_cb_t)(const uint8_t addr[6], const uint8_t addr_type,
const uint8_t adv_type, const uint8_t dev_uuid[16],
uint16_t oob_info, bt_mesh_prov_bearer_t bearer, int8_t rssi);
/**
* @brief This function registers the callback which notifies the application
* layer of the received mesh provisioning or unprovisioned device
* beacon advertizing packets (from devices not in the unprov device queue).
*
* @param[in] cb: Callback of the notifying adv pkts function
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_adv_pkt_cb_register(unprov_adv_pkt_cb_t cb);
/**
* @brief This function changes net_idx or flags or iv_index used in provisioning data.
*
* @param[in] info: Pointer of structure containing net_idx or flags or iv_index
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info);
/**
* @brief This function initializes the provisioning information needed by Provisioner,
* including NetKey Index, flags, IV Index, etc.
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_init_prov_info(void);
/**
* @brief This function sets the provisioning bearer type used by Provisioner.
*
* @param[in] bearers: Provisioning bearer type
* @param[in] clear: Indicate if the corresponding bearer type will be cleared
*
* @return None
*/
void bt_mesh_provisioner_set_prov_bearer(bt_mesh_prov_bearer_t bearers, bool clear);
/**
* @brief This function gets the provisioning bearer type used by Provisioner.
*
* @return Currently supported provisioning bearer type
*/
bt_mesh_prov_bearer_t bt_mesh_provisioner_get_prov_bearer(void);
/**
* @brief This function sets the Static OOB value used by Provisioner.
*
* @param[in] value: Static OOB value
* @param[in] length: Static OOB value length
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_static_oob_value(const uint8_t *value, uint8_t length);
/**
* @brief This function gets the unicast address of primary element of Provisioner.
*
* @return Unicast address of primary element of Provisioner.
*/
uint16_t bt_mesh_provisioner_get_primary_elem_addr(void);
/**
* @brief This function sets the unicast address of primary element of Provisioner.
*
* @param[in] addr: unicast address of primary element
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_primary_elem_addr(uint16_t addr);
/**
* @brief This function is used to update next allocated address by Provisioner.
*
* @note This function is used for mesh internal test.
*
* @param[in] unicast_addr: unicast address of the node
* @param[in] element_num: element count of the node
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_test_provisioner_update_alloc_addr(uint16_t unicast_addr, uint16_t element_num);
/**
* @brief This function is called to input number/string out-put by unprovisioned device.
*
* @param[in] idx The provisioning link index
* @param[in] val Pointer of the input number/string
* @param[in] num_flag Flag indicates if it is a number or string
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_oob_input_data(const uint8_t idx, const uint8_t *val, bool num_flag);
/**
* @brief This function is called to output number/string which will be input by unprovisioned device.
*
* @param[in] idx The provisioning link index
* @param[in] num Pointer of the output number/string
* @param[in] size Size of the output number/string
* @param[in] num_flag Flag indicates if it is a number or string
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_oob_output_data(const uint8_t idx, const uint8_t *num,
uint8_t size, bool num_flag);
/**
* @brief This function is called to read unprovisioned device's oob public key.
*
* @param[in] idx The provisioning link index
* @param[in] pub_key_x Unprovisioned device's Public Key X
* @param[in] pub_key_y Unprovisioned device's Public Key Y
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_read_oob_pub_key(const uint8_t idx, const uint8_t pub_key_x[32],
const uint8_t pub_key_y[32]);
/* The following APIs are for fast provisioning */
/**
* @brief This function is called to set fast_prov_flag.
*
* @param[in] enable: Enable or disable fast provisioning
*
* @return None
*/
void bt_mesh_provisioner_fast_prov_enable(bool enable);
/**
* @brief This function is called to set netkey index used for fast provisioning.
*
* @param[in] net_idx: Netkey index
*
* @return None
*/
void bt_mesh_provisioner_set_fast_prov_net_idx(uint16_t net_idx);
/**
* @brief This function is called to get netkey index used for fast provisioning.
*
* @return net_idx of fast provisioning
*/
uint16_t bt_mesh_provisioner_get_fast_prov_net_idx(void);
/**
* @brief This function is called to set unicast address range used for fast provisioning.
*
* @param[in] min: Minimum unicast address
* @param[in] max: Maximum unicast address
*
* @return status for set unicast address range message
*/
uint8_t bt_mesh_set_fast_prov_unicast_addr_range(uint16_t min, uint16_t max);
/**
* @brief This function is called to set flags & iv_index used for fast provisioning.
*
* @param[in] flags: Key refresh flag and iv update flag
* @param[in] iv_index: IV index
*
* @return None
*/
void bt_mesh_set_fast_prov_flags_iv_index(uint8_t flags, uint32_t iv_index);
#ifdef __cplusplus
}
#endif
#endif /* _PROVISIONER_PROV_H_ */

View File

@ -0,0 +1,112 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROXY_CLIENT_H_
#define _PROXY_CLIENT_H_
#include "net.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_PROXY_ADV_NET_ID 0x00
#define BLE_MESH_PROXY_ADV_NODE_ID 0x01
#define BLE_MESH_PROXY_NET_PDU 0x00
#define BLE_MESH_PROXY_BEACON 0x01
#define BLE_MESH_PROXY_CONFIG 0x02
#define BLE_MESH_PROXY_PROV 0x03
#define BLE_MESH_PROXY_CFG_FILTER_SET 0x00
#define BLE_MESH_PROXY_CFG_FILTER_ADD 0x01
#define BLE_MESH_PROXY_CFG_FILTER_REMOVE 0x02
#define BLE_MESH_PROXY_CFG_FILTER_STATUS 0x03
typedef union {
struct {
uint8_t net_id[8];
uint16_t net_idx;
} net_id;
struct {
uint16_t src;
} node_id;
} bt_mesh_proxy_adv_ctx_t;
struct bt_mesh_proxy_net_pdu {
struct net_buf_simple *val;
};
struct bt_mesh_proxy_cfg_pdu {
uint8_t opcode;
union {
struct cfg_filter_set {
uint8_t filter_type;
} set;
struct cfg_addr_add {
uint16_t *addr;
uint16_t addr_num;
} add;
struct cfg_addr_remove {
uint16_t *addr;
uint16_t addr_num;
} remove;
};
};
typedef struct {
uint8_t type;
union {
struct bt_mesh_proxy_net_pdu net;
struct bt_mesh_proxy_cfg_pdu cfg;
};
} bt_mesh_proxy_client_pdu_t;
int bt_mesh_proxy_client_send(struct bt_mesh_conn *conn, uint8_t type,
struct net_buf_simple *msg);
int bt_mesh_proxy_client_prov_enable(void);
int bt_mesh_proxy_client_prov_disable(void);
int bt_mesh_proxy_client_gatt_enable(void);
int bt_mesh_proxy_client_gatt_disable(void);
typedef void (*proxy_client_recv_adv_cb_t)(const bt_mesh_addr_t *addr, uint8_t type,
bt_mesh_proxy_adv_ctx_t *ctx, int8_t rssi);
typedef void (*proxy_client_connect_cb_t)(const bt_mesh_addr_t *addr,
uint8_t conn_handle, uint16_t net_idx);
typedef void (*proxy_client_disconnect_cb_t)(const bt_mesh_addr_t *addr, uint8_t conn_handle,
uint16_t net_idx, uint8_t reason);
typedef void (*proxy_client_recv_filter_status_cb_t)(uint8_t conn_handle, uint16_t src, uint16_t net_idx,
uint8_t filter_type, uint16_t list_size);
void bt_mesh_proxy_client_set_adv_recv_cb(proxy_client_recv_adv_cb_t cb);
void bt_mesh_proxy_client_set_conn_cb(proxy_client_connect_cb_t cb);
void bt_mesh_proxy_client_set_disconn_cb(proxy_client_disconnect_cb_t cb);
void bt_mesh_proxy_client_set_filter_status_cb(proxy_client_recv_filter_status_cb_t cb);
void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf,
const bt_mesh_addr_t *addr, int8_t rssi);
int bt_mesh_proxy_client_connect(const uint8_t addr[6], uint8_t addr_type, uint16_t net_idx);
int bt_mesh_proxy_client_disconnect(uint8_t conn_handle);
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub);
bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst);
int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,
struct bt_mesh_proxy_cfg_pdu *pdu);
int bt_mesh_proxy_client_init(void);
int bt_mesh_proxy_client_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _PROXY_CLIENT_H_ */

View File

@ -0,0 +1,80 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROXY_H_
#define _PROXY_H_
#include "net.h"
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_PROXY_NET_PDU 0x00
#define BLE_MESH_PROXY_BEACON 0x01
#define BLE_MESH_PROXY_CONFIG 0x02
#define BLE_MESH_PROXY_PROV 0x03
#if CONFIG_BLE_MESH_PROXY
/**
* Device Name Characteristic:
* 1. For iOS, when it tries to get the value of Device Name Characteristic, the PDU
* "Read By Type Request" will be used, and the valid length of corresponding
* response is 19 (23 - 1 - 1 - 2).
* 2. For Android, when it tries to get the value of Device Name Characteristic, the
* PDU "Read Request" will be used, and the valid length of corresponding response
* is 22 (23 - 1).
*/
#define DEVICE_NAME_SIZE MIN((BLE_MESH_GATT_DEF_MTU_SIZE - 4), (BLE_MESH_GAP_ADV_MAX_LEN - 2))
#else
/* For Scan Response Data, the maximum length is 29 (31 - 1 - 1) currently. */
#define DEVICE_NAME_SIZE (BLE_MESH_GAP_ADV_MAX_LEN - 2)
#endif
typedef void (*proxy_server_connect_cb_t)(uint8_t conn_handle);
typedef void (*proxy_server_disconnect_cb_t)(uint8_t conn_handle, uint8_t reason);
int bt_mesh_set_device_name(const char *name);
int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, uint8_t type,
struct net_buf_simple *msg);
int bt_mesh_proxy_server_prov_enable(void);
int bt_mesh_proxy_server_prov_disable(bool disconnect);
void bt_mesh_proxy_server_set_conn_cb(proxy_server_connect_cb_t cb);
void bt_mesh_proxy_server_set_disconn_cb(proxy_server_disconnect_cb_t cb);
int bt_mesh_proxy_server_gatt_enable(void);
int bt_mesh_proxy_server_gatt_disable(void);
void bt_mesh_proxy_server_gatt_disconnect(void);
void bt_mesh_proxy_server_beacon_send(struct bt_mesh_subnet *sub);
struct net_buf_simple *bt_mesh_proxy_server_get_buf(void);
int32_t bt_mesh_proxy_server_adv_start(void);
void bt_mesh_proxy_server_adv_stop(void);
void bt_mesh_proxy_server_identity_start(struct bt_mesh_subnet *sub);
void bt_mesh_proxy_server_identity_stop(struct bt_mesh_subnet *sub);
bool bt_mesh_proxy_server_relay(struct net_buf_simple *buf, uint16_t dst);
void bt_mesh_proxy_server_addr_add(struct net_buf_simple *buf, uint16_t addr);
int bt_mesh_proxy_server_init(void);
int bt_mesh_proxy_server_deinit(void);
#ifdef __cplusplus
}
#endif
#endif /* _PROXY_H_ */

View File

@ -0,0 +1,39 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SCAN_H_
#define _SCAN_H_
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void);
int bt_mesh_scan_enable(void);
int bt_mesh_scan_disable(void);
int bt_mesh_scan_with_wl_enable(void);
struct bt_mesh_ble_scan_param {
uint32_t duration;
};
int bt_mesh_start_ble_scan(struct bt_mesh_ble_scan_param *param);
int bt_mesh_stop_ble_scan(void);
#ifdef __cplusplus
}
#endif
#endif /* _SCAN_H_ */

View File

@ -0,0 +1,79 @@
/*
* SPDX-FileCopyrightText: 2018 Intel Corporation
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SETTINGS_H_
#define _SETTINGS_H_
#include "net.h"
#include "provisioner_main.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_SETTINGS_ROLE_NONE 0
#define BLE_MESH_SETTINGS_ROLE_NODE (BIT(BLE_MESH_NODE))
#define BLE_MESH_SETTINGS_ROLE_PROV (BIT(BLE_MESH_PROVISIONER))
#define BLE_MESH_SETTINGS_ROLE_BIT_MASK (BIT(BLE_MESH_NODE) | BIT(BLE_MESH_PROVISIONER))
void bt_mesh_store_role(void);
void bt_mesh_store_net(void);
void bt_mesh_store_iv(bool only_duration);
void bt_mesh_store_seq(void);
void bt_mesh_clear_seq(void);
void bt_mesh_store_rpl(struct bt_mesh_rpl *rpl);
void bt_mesh_store_subnet(struct bt_mesh_subnet *sub);
void bt_mesh_store_app_key(struct bt_mesh_app_key *key);
void bt_mesh_store_hb_pub(void);
void bt_mesh_store_cfg(void);
void bt_mesh_store_mod_bind(struct bt_mesh_model *mod);
void bt_mesh_store_mod_sub(struct bt_mesh_model *mod);
void bt_mesh_store_mod_pub(struct bt_mesh_model *mod);
void bt_mesh_store_label(void);
void bt_mesh_clear_role(void);
void bt_mesh_clear_net(void);
void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub);
void bt_mesh_clear_app_key(struct bt_mesh_app_key *key);
void bt_mesh_clear_rpl(void);
#if CONFIG_BLE_MESH_PROVISIONER
void bt_mesh_store_prov_info(uint16_t primary_addr, uint16_t alloc_addr);
void bt_mesh_clear_prov_info(void);
void bt_mesh_store_p_net_idx(void);
void bt_mesh_clear_p_net_idx(void);
void bt_mesh_store_p_app_idx(void);
void bt_mesh_clear_p_app_idx(void);
void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub);
void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key);
void bt_mesh_clear_p_subnet(uint16_t net_idx);
void bt_mesh_clear_p_app_key(uint16_t app_idx);
void bt_mesh_clear_rpl_single(uint16_t src);
void bt_mesh_store_node_info(struct bt_mesh_node *node);
void bt_mesh_clear_node_info(uint16_t unicast_addr);
void bt_mesh_store_node_name(struct bt_mesh_node *node);
void bt_mesh_store_node_comp_data(struct bt_mesh_node *node);
#endif
void bt_mesh_settings_lock(void);
void bt_mesh_settings_unlock(void);
int settings_core_init(void);
int settings_core_load(void);
int settings_core_commit(void);
int settings_core_deinit(void);
int settings_core_erase(void);
int bt_mesh_settings_init(void);
int bt_mesh_settings_deinit(bool erase);
void bt_mesh_settings_reset(bool erase);
#ifdef __cplusplus
}
#endif
#endif /* _SETTINGS_H_ */

View File

@ -0,0 +1,39 @@
/*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SETTINGS_UID_H_
#define _SETTINGS_UID_H_
#include "mesh_types.h"
#include "settings_nvs.h"
#ifdef __cplusplus
extern "C" {
#endif
int settings_uid_init(void);
int settings_uid_load(void);
int settings_uid_deinit(void);
int settings_uid_erase(void);
int bt_mesh_provisioner_open_settings_with_index(uint8_t index);
int bt_mesh_provisioner_open_settings_with_uid(const char *id, uint8_t *index);
int bt_mesh_provisioner_close_settings_with_index(uint8_t index, bool erase);
int bt_mesh_provisioner_close_settings_with_uid(const char *id, bool erase, uint8_t *index);
int bt_mesh_provisioner_delete_settings_with_index(uint8_t index);
int bt_mesh_provisioner_delete_settings_with_uid(const char *id, uint8_t *index);
const char *bt_mesh_provisioner_get_settings_uid(uint8_t index);
uint8_t bt_mesh_provisioner_get_settings_index(const char *id);
uint8_t bt_mesh_provisioner_get_free_settings_count(void);
int bt_mesh_provisioner_direct_erase_settings(void);
#ifdef __cplusplus
}
#endif
#endif /* _SETTINGS_UID_H_ */

View File

@ -0,0 +1,67 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_SETTINGS_NVS_H_
#define _BLE_MESH_SETTINGS_NVS_H_
#include "nvs_flash.h"
#include "mesh_buf.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef nvs_handle_t bt_mesh_nvs_handle_t;
#define SETTINGS_ITEM_SIZE sizeof(uint16_t)
#define BLE_MESH_GET_ELEM_IDX(x) ((uint8_t)((x) >> 8))
#define BLE_MESH_GET_MODEL_IDX(x) ((uint8_t)(x))
#define BLE_MESH_GET_MODEL_KEY(a, b) ((uint16_t)(((uint16_t)((a) << 8)) | (b)))
int bt_mesh_settings_nvs_open(const char* name, bt_mesh_nvs_handle_t *handle);
void bt_mesh_settings_nvs_close(bt_mesh_nvs_handle_t handle);
void bt_mesh_settings_init_foreach(void);
void bt_mesh_settings_deinit_foreach(bool erase);
int bt_mesh_settings_direct_open(bt_mesh_nvs_handle_t *handle);
void bt_mesh_settings_direct_close(void);
int bt_mesh_save_settings(bt_mesh_nvs_handle_t handle, const char *key,
const uint8_t *val, size_t len);
int bt_mesh_save_core_settings(const char *key, const uint8_t *val, size_t len);
int bt_mesh_save_uid_settings(const char *key, const uint8_t *val, size_t len);
int bt_mesh_erase_settings(bt_mesh_nvs_handle_t handle, const char *key);
int bt_mesh_erase_core_settings(const char *key);
int bt_mesh_erase_uid_settings(const char *name);
int bt_mesh_load_settings(bt_mesh_nvs_handle_t handle, const char *key,
uint8_t *buf, size_t buf_len, bool *exist);
int bt_mesh_load_core_settings(const char *key, uint8_t *buf, size_t buf_len, bool *exist);
int bt_mesh_load_uid_settings(const char *key, uint8_t *buf, size_t buf_len, bool *exist);
struct net_buf_simple *bt_mesh_get_settings_item(bt_mesh_nvs_handle_t handle, const char *key);
struct net_buf_simple *bt_mesh_get_core_settings_item(const char *key);
struct net_buf_simple *bt_mesh_get_uid_settings_item(const char *key);
int bt_mesh_add_settings_item(bt_mesh_nvs_handle_t handle, const char *key, const uint16_t val);
int bt_mesh_add_core_settings_item(const char *key, const uint16_t val);
int bt_mesh_add_uid_settings_item(const char *key, const uint16_t val);
int bt_mesh_remove_settings_item(bt_mesh_nvs_handle_t handle, const char *key, const uint16_t val);
int bt_mesh_remove_core_settings_item(const char *key, const uint16_t val);
int bt_mesh_remove_uid_settings_item(const char *key, const uint16_t val);
int bt_mesh_settings_erase_key(bt_mesh_nvs_handle_t handle, const char *key);
int bt_mesh_settings_erase_all(bt_mesh_nvs_handle_t handle);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_SETTINGS_NVS_H_ */

View File

@ -0,0 +1,52 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BLE_MESH_TEST_H_
#define _BLE_MESH_TEST_H_
#include "mesh_bearer_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
int bt_mesh_test(void);
struct bt_mesh_device_network_info {
uint8_t net_key[16];
uint16_t net_idx;
uint8_t flags;
uint32_t iv_index;
uint16_t unicast_addr;
uint8_t dev_key[16];
uint8_t app_key[16];
uint16_t app_idx;
uint16_t group_addr;
};
int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info);
/* Before trying to update the white list, users need to make sure that
* one of the following conditions is satisfied:
* 1. BLE scanning is disabled;
* 2. BLE scanning is enabled with scan filter policy disabled;
* If BLE scanning is enabled with scan filter policy enabled, users need
* to stop BLE scanning firstly, then the white list can be updated.
*/
int bt_mesh_test_update_white_list(struct bt_mesh_white_list *wl);
int bt_mesh_test_start_scanning(bool wl_en);
int bt_mesh_test_stop_scanning(void);
#ifdef __cplusplus
}
#endif
#endif /* _BLE_MESH_TEST_H_ */

View File

@ -0,0 +1,128 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _TRANSPORT_H_
#define _TRANSPORT_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff
#define BLE_MESH_SDU_UNSEG_MAX 11
#define BLE_MESH_CTL_SEG_SDU_MAX 8
#define BLE_MESH_APP_SEG_SDU_MAX 12
#define BLE_MESH_TX_SDU_MAX (CONFIG_BLE_MESH_TX_SEG_MAX * 12)
#define TRANS_SEQ_ZERO_MASK ((uint16_t)BIT_MASK(13))
#define TRANS_CTL_OP_MASK ((uint8_t)BIT_MASK(7))
#define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK)
#define TRANS_CTL_HDR(op, seg) ((op & TRANS_CTL_OP_MASK) | (seg << 7))
#define TRANS_CTL_OP_ACK 0x00
#define TRANS_CTL_OP_FRIEND_POLL 0x01
#define TRANS_CTL_OP_FRIEND_UPDATE 0x02
#define TRANS_CTL_OP_FRIEND_REQ 0x03
#define TRANS_CTL_OP_FRIEND_OFFER 0x04
#define TRANS_CTL_OP_FRIEND_CLEAR 0x05
#define TRANS_CTL_OP_FRIEND_CLEAR_CFM 0x06
#define TRANS_CTL_OP_FRIEND_SUB_ADD 0x07
#define TRANS_CTL_OP_FRIEND_SUB_REM 0x08
#define TRANS_CTL_OP_FRIEND_SUB_CFM 0x09
#define TRANS_CTL_OP_HEARTBEAT 0x0a
struct bt_mesh_ctl_friend_poll {
uint8_t fsn;
} __packed;
struct bt_mesh_ctl_friend_update {
uint8_t flags;
uint32_t iv_index;
uint8_t md;
} __packed;
struct bt_mesh_ctl_friend_req {
uint8_t criteria;
uint8_t recv_delay;
uint8_t poll_to[3];
uint16_t prev_addr;
uint8_t num_elem;
uint16_t lpn_counter;
} __packed;
struct bt_mesh_ctl_friend_offer {
uint8_t recv_win;
uint8_t queue_size;
uint8_t sub_list_size;
int8_t rssi;
uint16_t frnd_counter;
} __packed;
struct bt_mesh_ctl_friend_clear {
uint16_t lpn_addr;
uint16_t lpn_counter;
} __packed;
struct bt_mesh_ctl_friend_clear_confirm {
uint16_t lpn_addr;
uint16_t lpn_counter;
} __packed;
#define BLE_MESH_FRIEND_SUB_MIN_LEN (1 + 2)
struct bt_mesh_ctl_friend_sub {
uint8_t xact;
uint16_t addr_list[5];
} __packed;
struct bt_mesh_ctl_friend_sub_confirm {
uint8_t xact;
} __packed;
uint8_t bt_mesh_get_seg_retrans_num(void);
int32_t bt_mesh_get_seg_retrans_timeout(uint8_t ttl);
void bt_mesh_set_hb_sub_dst(uint16_t addr);
struct bt_mesh_app_key *bt_mesh_app_key_find(uint16_t app_idx);
bool bt_mesh_tx_in_progress(void);
void bt_mesh_rx_reset(bool erase);
void bt_mesh_tx_reset(void);
void bt_mesh_rx_reset_single(uint16_t src);
void bt_mesh_tx_reset_single(uint16_t dst);
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, uint8_t ctl_op, void *data,
size_t data_len, const struct bt_mesh_send_cb *cb,
void *cb_data);
int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx);
void bt_mesh_trans_init(void);
void bt_mesh_trans_deinit(bool erase);
bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match);
void bt_mesh_heartbeat_send(void);
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx,
const uint8_t **key, uint8_t *aid, uint8_t role, uint16_t dst);
#ifdef __cplusplus
}
#endif
#endif /* _TRANSPORT_H_ */

View File

@ -0,0 +1,122 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _CLIENT_COMMON_H_
#define _CLIENT_COMMON_H_
#include "mesh_access.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Client model opcode pair table */
typedef struct {
uint32_t cli_op; /* Client message opcode */
uint32_t status_op; /* Corresponding status message opcode */
} bt_mesh_client_op_pair_t;
/** Client model user data context */
typedef struct {
/** Pointer to the client model */
struct bt_mesh_model *model;
/** Size of the opcode pair table */
int op_pair_size;
/** Pointer to the opcode pair table */
const bt_mesh_client_op_pair_t *op_pair;
/**
* @brief This function is a callback function used to push the received unsolicited
* messages to the application layer.
*
* @param[in] opcode: Opcode of received status message
* @param[in] model: Model associated with the status message
* @param[in] ctx: Context information of the status message
* @param[in] buf: Buffer contains the status message value
*
* @return None
*/
void (*publish_status)(uint32_t opcode, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
/** Pointer to the internal data of client model */
void *internal_data;
/** Role of the device to which the client model belongs */
uint8_t msg_role;
} bt_mesh_client_user_data_t;
/** Client model internal data context */
typedef struct {
sys_slist_t queue;
} bt_mesh_client_internal_data_t;
/** Client model sending message related context */
typedef struct {
sys_snode_t client_node;
struct bt_mesh_msg_ctx ctx; /* Message context */
uint32_t opcode; /* Message opcode */
uint32_t op_pending; /* Expected status message opcode */
int32_t timeout; /* Calculated message timeout value */
struct k_delayed_work timer; /* Time used to get response. Only for internal use. */
} bt_mesh_client_node_t;
/** Client model sending message parameters */
typedef struct {
uint32_t opcode; /* Message opcode */
struct bt_mesh_model *model; /* Pointer to the client model */
struct bt_mesh_msg_ctx ctx; /* Message context */
int32_t msg_timeout; /* Time to get corresponding response */
uint8_t msg_role; /* Role (Node/Provisioner) of the device */
const struct bt_mesh_send_cb *cb; /* User defined callback function */
void *cb_data; /* User defined callback value */
} bt_mesh_client_common_param_t;
void bt_mesh_client_model_lock(void);
void bt_mesh_client_model_unlock(void);
int bt_mesh_client_init(struct bt_mesh_model *model);
int bt_mesh_client_deinit(struct bt_mesh_model *model);
/**
* @brief Check if the msg received by client model is a publish msg or not
*
* @param model Mesh (client) Model that the message belongs to.
* @param ctx Message context, includes keys, TTL, etc.
* @param buf The message buffer
* @param need_pub Indicate if the msg sent to app layer as a publish msg
* @return 0 on success, or (negative) error code on failure.
*/
bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub);
int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
struct net_buf_simple *msg, bool need_ack,
k_work_handler_t timer_handler);
int bt_mesh_client_free_node(bt_mesh_client_node_t *node);
int bt_mesh_client_clear_list(void *data);
/**
* @brief Set role of the client model for internal use.
*
* @param[in] model: Pointer to the client model
* @param[in] role: Role of the device
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_set_client_model_role(struct bt_mesh_model *model, uint8_t role);
#ifdef __cplusplus
}
#endif
#endif /* _CLIENT_COMMON_H_ */

View File

@ -0,0 +1,408 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Generic Client Model APIs.
*/
#ifndef _GENERIC_CLIENT_H_
#define _GENERIC_CLIENT_H_
#include "client_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Generic client model common structure */
typedef bt_mesh_client_user_data_t bt_mesh_generic_client_t;
typedef bt_mesh_client_internal_data_t generic_internal_data_t;
/* Generic Client Model Callback */
extern const struct bt_mesh_model_cb bt_mesh_generic_client_cb;
/* Generic OnOff Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[];
/** @def BLE_MESH_MODEL_GEN_ONOFF_CLI
*
* Define a new generic onoff client model. Note that this API
* needs to be repeated for each element which the application
* wants to have a generic onoff client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_onoff_cli.
*
* @return New generic onoff client model instance.
*/
#define BLE_MESH_MODEL_GEN_ONOFF_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, \
bt_mesh_gen_onoff_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_onoff_client_t;
struct bt_mesh_gen_onoff_status {
bool op_en; /* Indicate whether optional parameters included */
uint8_t present_onoff; /* Present value of Generic OnOff state */
uint8_t target_onoff; /* Target value of Generic OnOff state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_gen_onoff_set {
bool op_en; /* Indicate whether optional parameters included */
uint8_t onoff; /* Target value of Generic OnOff state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
/* Generic Level Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[];
/** @def BLE_MESH_MODEL_GEN_LEVEL_CLI
*
* Define a new generic level client model. Note that this API
* needs to be repeated for each element which the application
* wants to have a generic level client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_level_cli.
*
* @return New generic level client model instance.
*/
#define BLE_MESH_MODEL_GEN_LEVEL_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, \
bt_mesh_gen_level_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_level_client_t;
struct bt_mesh_gen_level_status {
bool op_en; /* Indicate whether optional parameters included */
int16_t present_level; /* Present value of Generic Level state */
int16_t target_level; /* Target value of the Generic Level state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_gen_level_set {
bool op_en; /* Indicate whether optional parameters included */
int16_t level; /* Target value of Generic Level state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_gen_delta_set {
bool op_en; /* Indicate whether optional parameters included */
int32_t delta_level; /* Delta change of Generic Level state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_gen_move_set {
bool op_en; /* Indicate whether optional parameters included */
int16_t delta_level; /* Delta Level step to calculate Move speed for Generic Level state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
/* Generic Default Transition Time Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[];
/** @def BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI
*
* Define a new generic default transition time client model. Note
* that this API needs to be repeated for each element that the
* application wants to have a generic default transition client
* model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_def_trans_time_cli.
*
* @return New generic default transition time client model instance.
*/
#define BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \
bt_mesh_gen_def_trans_time_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_def_trans_time_client_t;
struct bt_mesh_gen_def_trans_time_set {
uint8_t trans_time; /* The value of the Generic Default Transition Time state */
};
struct bt_mesh_gen_def_trans_time_status {
uint8_t trans_time; /* The value of the Generic Default Transition Time state */
};
/* Generic Power OnOff Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[];
/** @def BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI
*
* Define a new generic power onoff client model. Note that this API
* needs to be repeated for each element which the application wants
* to have a generic power onoff client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_power_onoff_cli.
*
* @return New generic power onoff client model instance.
*/
#define BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \
bt_mesh_gen_power_onoff_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_power_onoff_client_t;
struct bt_mesh_gen_onpowerup_set {
uint8_t onpowerup; /* The value of the Generic OnPowerUp state */
};
struct bt_mesh_gen_onpowerup_status {
uint8_t onpowerup; /* The value of the Generic OnPowerUp state */
};
/* Generic Power Level Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[];
/** @def BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI
*
* Define a new generic power level client model. Note that this API
* needs to be repeated for each element which the application wants
* to have a generic power level client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_power_level_cli.
*
* @return New generic power level client model instance.
*/
#define BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, \
bt_mesh_gen_power_level_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_power_level_client_t;
struct bt_mesh_gen_power_level_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_power; /* Present value of Generic Power Actual state */
uint16_t target_power; /* Target value of Generic Power Actual state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_gen_power_last_status {
uint16_t power; /* The value of the Generic Power Last state */
};
struct bt_mesh_gen_power_default_status {
uint16_t power; /* The value of the Generic Default Last state */
};
struct bt_mesh_gen_power_range_status {
uint8_t status_code; /* Status Code for the requesting message */
uint16_t range_min; /* Value of Range Min field of Generic Power Range state */
uint16_t range_max; /* Value of Range Max field of Generic Power Range state */
};
struct bt_mesh_gen_power_level_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t power; /* Target value of Generic Power Actual state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_gen_power_default_set {
uint16_t power; /* The value of the Generic Power Default state */
};
struct bt_mesh_gen_power_range_set {
uint16_t range_min; /* Value of Range Min field of Generic Power Range state */
uint16_t range_max; /* Value of Range Max field of Generic Power Range state */
};
/* Generic Battery Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[];
/** @def BLE_MESH_MODEL_GEN_BATTERY_CLI
*
* Define a new generic battery client model. Note that this API
* needs to be repeated for each element which the application
* wants to have a generic battery client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_battery_cli.
*
* @return New generic battery client model instance.
*/
#define BLE_MESH_MODEL_GEN_BATTERY_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, \
bt_mesh_gen_battery_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_battery_client_t;
struct bt_mesh_gen_battery_status {
uint32_t battery_level : 8; /* Value of Generic Battery Level state */
uint32_t time_to_discharge : 24; /* Value of Generic Battery Time to Discharge state */
uint32_t time_to_charge : 24; /* Value of Generic Battery Time to Charge state */
uint32_t flags : 8; /* Value of Generic Battery Flags state */
};
/* Generic Location Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[];
/** @def BLE_MESH_MODEL_GEN_LOCATION_CLI
*
* Define a new generic location client model. Note that this API
* needs to be repeated for each element which the application
* wants to have a generic location client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_location_cli.
*
* @return New generic location client model instance.
*/
#define BLE_MESH_MODEL_GEN_LOCATION_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, \
bt_mesh_gen_location_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_location_client_t;
struct bt_mesh_gen_loc_global_status {
int32_t global_latitude; /* Global Coordinates (Latitude) */
int32_t global_longitude; /* Global Coordinates (Longitude) */
int16_t global_altitude; /* Global Altitude */
};
struct bt_mesh_gen_loc_local_status {
int16_t local_north; /* Local Coordinates (North) */
int16_t local_east; /* Local Coordinates (East) */
int16_t local_altitude; /* Local Altitude */
uint8_t floor_number; /* Floor Number */
uint16_t uncertainty; /* Uncertainty */
};
struct bt_mesh_gen_loc_global_set {
int32_t global_latitude; /* Global Coordinates (Latitude) */
int32_t global_longitude; /* Global Coordinates (Longitude) */
int16_t global_altitude; /* Global Altitude */
};
struct bt_mesh_gen_loc_local_set {
int16_t local_north; /* Local Coordinates (North) */
int16_t local_east; /* Local Coordinates (East) */
int16_t local_altitude; /* Local Altitude */
uint8_t floor_number; /* Floor Number */
uint16_t uncertainty; /* Uncertainty */
};
/* Generic Property Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[];
/** @def BLE_MESH_MODEL_GEN_LOCATION_CLI
*
* Define a new generic location client model. Note that this API
* needs to be repeated for each element which the application
* wants to have a generic location client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_gen_location_cli.
*
* @return New generic location client model instance.
*/
#define BLE_MESH_MODEL_GEN_PROPERTY_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_PROP_CLI, \
bt_mesh_gen_property_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_gen_property_client_t;
struct bt_mesh_gen_user_properties_status {
struct net_buf_simple *user_property_ids; /* Buffer contains a sequence of N User Property IDs */
};
struct bt_mesh_gen_user_property_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t user_property_id; /* Property ID identifying a Generic User Property */
uint8_t user_access; /* Enumeration indicating user access (optional) */
struct net_buf_simple *user_property_value; /* Raw value for the User Property (C.1) */
};
struct bt_mesh_gen_admin_properties_status {
struct net_buf_simple *admin_property_ids; /* Buffer contains a sequence of N Admin Property IDs */
};
struct bt_mesh_gen_admin_property_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t admin_property_id; /* Property ID identifying a Generic Admin Property */
uint8_t admin_user_access; /* Enumeration indicating user access (optional) */
struct net_buf_simple *admin_property_value; /* Raw value for the Admin Property (C.1) */
};
struct bt_mesh_gen_manu_properties_status {
struct net_buf_simple *manu_property_ids; /* Buffer contains a sequence of N Manufacturer Property IDs */
};
struct bt_mesh_gen_manu_property_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t manu_property_id; /* Property ID identifying a Generic Manufacturer Property */
uint8_t manu_user_access; /* Enumeration indicating user access (optional) */
struct net_buf_simple *manu_property_value; /* Raw value for the Manufacturer Property (C.1) */
};
struct bt_mesh_gen_client_properties_status {
struct net_buf_simple *client_property_ids; /* Buffer contains a sequence of N Client Property IDs */
};
struct bt_mesh_gen_user_property_get {
uint16_t user_property_id; /* Property ID identifying a Generic User Property */
};
struct bt_mesh_gen_user_property_set {
uint16_t user_property_id; /* Property ID identifying a Generic User Property */
struct net_buf_simple *user_property_value; /* Raw value for the User Property */
};
struct bt_mesh_gen_admin_property_get {
uint16_t admin_property_id; /* Property ID identifying a Generic Admin Property */
};
struct bt_mesh_gen_admin_property_set {
uint16_t admin_property_id; /* Property ID identifying a Generic Admin Property */
uint8_t admin_user_access; /* Enumeration indicating user access */
struct net_buf_simple *admin_property_value; /* Raw value for the Admin Property */
};
struct bt_mesh_gen_manu_property_get {
uint16_t manu_property_id; /* Property ID identifying a Generic Manufacturer Property */
};
struct bt_mesh_gen_manu_property_set {
uint16_t manu_property_id; /* Property ID identifying a Generic Manufacturer Property */
uint8_t manu_user_access; /* Enumeration indicating user access */
};
struct bt_mesh_gen_client_properties_get {
uint16_t client_property_id; /* A starting Client Property ID present within an element */
};
/**
* @brief This function is called to get generic states.
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of generic get message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set generic states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of generic set message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}
#endif
#endif /* _GENERIC_CLIENT_H_ */

View File

@ -0,0 +1,440 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Lighting Client Model APIs.
*/
#ifndef _LIGHTING_CLIENT_H_
#define _LIGHTING_CLIENT_H_
#include "client_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Light client model common structure */
typedef bt_mesh_client_user_data_t bt_mesh_light_client_t;
typedef bt_mesh_client_internal_data_t light_internal_data_t;
/* Lighting Client Model Callback */
extern const struct bt_mesh_model_cb bt_mesh_lighting_client_cb;
/* Light Lightness Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[];
/** @def BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI
*
* Define a new light lightness client model. Note that this API
* needs to be repeated for each element which the application
* wants to have a light lightness client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_light_lightness_cli.
*
* @return New light lightness client model instance.
*/
#define BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, \
bt_mesh_light_lightness_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_light_lightness_client_t;
struct bt_mesh_light_lightness_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_lightness; /* Present value of light lightness actual state */
uint16_t target_lightness; /* Target value of light lightness actual state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_lightness_linear_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_lightness; /* Present value of light lightness linear state */
uint16_t target_lightness; /* Target value of light lightness linear state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_lightness_last_status {
uint16_t lightness; /* The value of the Light Lightness Last state */
};
struct bt_mesh_light_lightness_default_status {
uint16_t lightness; /* The value of the Light Lightness default state */
};
struct bt_mesh_light_lightness_range_status {
uint8_t status_code; /* Status Code for the requesting message */
uint16_t range_min; /* Value of range min field of light lightness range state */
uint16_t range_max; /* Value of range max field of light lightness range state */
};
struct bt_mesh_light_lightness_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t lightness; /* Target value of light lightness actual state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_lightness_linear_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t lightness; /* Target value of light lightness linear state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_lightness_default_set {
uint16_t lightness; /* The value of the Light Lightness Default state */
};
struct bt_mesh_light_lightness_range_set {
uint16_t range_min; /* Value of range min field of light lightness range state */
uint16_t range_max; /* Value of range max field of light lightness range state */
};
/* Light CTL Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[];
/** @def BLE_MESH_MODEL_LIGHT_CTL_CLI
*
* Define a new light CTL client model. Note that this API needs
* to be repeated for each element which the application wants to
* have a light CTL client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_light_ctl_cli.
*
* @return New light CTL client model instance.
*/
#define BLE_MESH_MODEL_LIGHT_CTL_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, \
bt_mesh_light_ctl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_light_ctl_client_t;
struct bt_mesh_light_ctl_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_ctl_lightness; /* Present value of light ctl lightness state */
uint16_t present_ctl_temperature; /* Present value of light ctl temperature state */
uint16_t target_ctl_lightness; /* Target value of light ctl lightness state (optional) */
uint16_t target_ctl_temperature; /* Target value of light ctl temperature state (C.1) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_ctl_temperature_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_ctl_temperature; /* Present value of light ctl temperature state */
uint16_t present_ctl_delta_uv; /* Present value of light ctl delta UV state */
uint16_t target_ctl_temperature; /* Target value of light ctl temperature state (optional) */
uint16_t target_ctl_delta_uv; /* Target value of light ctl delta UV state (C.1) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_ctl_temperature_range_status {
uint8_t status_code; /* Status code for the requesting message */
uint16_t range_min; /* Value of temperature range min field of light ctl temperature range state */
uint16_t range_max; /* Value of temperature range max field of light ctl temperature range state */
};
struct bt_mesh_light_ctl_default_status {
uint16_t lightness; /* Value of light lightness default state */
uint16_t temperature; /* Value of light temperature default state */
int16_t delta_uv; /* Value of light delta UV default state */
};
struct bt_mesh_light_ctl_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t ctl_lightness; /* Target value of light ctl lightness state */
uint16_t ctl_temperature; /* Target value of light ctl temperature state */
int16_t ctl_delta_uv; /* Target value of light ctl delta UV state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_ctl_temperature_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t ctl_temperature; /* Target value of light ctl temperature state */
int16_t ctl_delta_uv; /* Target value of light ctl delta UV state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_ctl_temperature_range_set {
uint16_t range_min; /* Value of temperature range min field of light ctl temperature range state */
uint16_t range_max; /* Value of temperature range max field of light ctl temperature range state */
};
struct bt_mesh_light_ctl_default_set {
uint16_t lightness; /* Value of light lightness default state */
uint16_t temperature; /* Value of light temperature default state */
int16_t delta_uv; /* Value of light delta UV default state */
};
/* Light HSL Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[];
/** @def BLE_MESH_MODEL_LIGHT_HSL_CLI
*
* Define a new light HSL client model. Note that this API needs
* to be repeated for each element which the application wants to
* have a light HSL client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_light_hsl_cli.
*
* @return New light HSL client model instance.
*/
#define BLE_MESH_MODEL_LIGHT_HSL_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, \
bt_mesh_light_hsl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_light_hsl_client_t;
struct bt_mesh_light_hsl_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t hsl_lightness; /* Present value of light hsl lightness state */
uint16_t hsl_hue; /* Present value of light hsl hue state */
uint16_t hsl_saturation; /* Present value of light hsl saturation state */
uint8_t remain_time; /* Time to complete state transition (optional) */
};
struct bt_mesh_light_hsl_target_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t hsl_lightness_target; /* Target value of light hsl lightness state */
uint16_t hsl_hue_target; /* Target value of light hsl hue state */
uint16_t hsl_saturation_target; /* Target value of light hsl saturation state */
uint8_t remain_time; /* Time to complete state transition (optional) */
};
struct bt_mesh_light_hsl_hue_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_hue; /* Present value of light hsl hue state */
uint16_t target_hue; /* Target value of light hsl hue state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_hsl_saturation_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t present_saturation; /* Present value of light hsl saturation state */
uint16_t target_saturation; /* Target value of light hsl saturation state (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_hsl_default_status {
uint16_t lightness; /* Value of light lightness default state */
uint16_t hue; /* Value of light hue default state */
uint16_t saturation; /* Value of light saturation default state */
};
struct bt_mesh_light_hsl_range_status {
uint8_t status_code; /* Status code for the requesting message */
uint16_t hue_range_min; /* Value of hue range min field of light hsl hue range state */
uint16_t hue_range_max; /* Value of hue range max field of light hsl hue range state */
uint16_t saturation_range_min; /* Value of saturation range min field of light hsl saturation range state */
uint16_t saturation_range_max; /* Value of saturation range max field of light hsl saturation range state */
};
struct bt_mesh_light_hsl_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t hsl_lightness; /* Target value of light hsl lightness state */
uint16_t hsl_hue; /* Target value of light hsl hue state */
uint16_t hsl_saturation; /* Target value of light hsl saturation state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_hsl_hue_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t hue; /* Target value of light hsl hue state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_hsl_saturation_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t saturation; /* Target value of light hsl hue state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_hsl_default_set {
uint16_t lightness; /* Value of light lightness default state */
uint16_t hue; /* Value of light hue default state */
uint16_t saturation; /* Value of light saturation default state */
};
struct bt_mesh_light_hsl_range_set {
uint16_t hue_range_min; /* Value of hue range min field of light hsl hue range state */
uint16_t hue_range_max; /* Value of hue range max field of light hsl hue range state */
uint16_t saturation_range_min; /* Value of saturation range min field of light hsl saturation range state */
uint16_t saturation_range_max; /* Value of saturation range max field of light hsl saturation range state */
};
/* Light xyL Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[];
/** @def BLE_MESH_MODEL_LIGHT_XYL_CLI
*
* Define a new light xyL client model. Note that this API needs
* to be repeated for each element which the application wants
* to have a light xyL client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_light_xyl_cli.
*
* @return New light xyL client model instance.
*/
#define BLE_MESH_MODEL_LIGHT_XYL_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, \
bt_mesh_light_xyl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_light_xyl_client_t;
struct bt_mesh_light_xyl_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t xyl_lightness; /* The present value of the Light xyL Lightness state */
uint16_t xyl_x; /* The present value of the Light xyL x state */
uint16_t xyl_y; /* The present value of the Light xyL y state */
uint8_t remain_time; /* Time to complete state transition (optional) */
};
struct bt_mesh_light_xyl_target_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t target_xyl_lightness; /* The target value of the Light xyL Lightness state */
uint16_t target_xyl_x; /* The target value of the Light xyL x state */
uint16_t target_xyl_y; /* The target value of the Light xyL y state */
uint8_t remain_time; /* Time to complete state transition (optional) */
};
struct bt_mesh_light_xyl_default_status {
uint16_t lightness; /* The value of the Light Lightness Default state */
uint16_t xyl_x; /* The value of the Light xyL x Default state */
uint16_t xyl_y; /* The value of the Light xyL y Default state */
};
struct bt_mesh_light_xyl_range_status {
uint8_t status_code; /* Status Code for the requesting message */
uint16_t xyl_x_range_min; /* The value of the xyL x Range Min field of the Light xyL x Range state */
uint16_t xyl_x_range_max; /* The value of the xyL x Range Max field of the Light xyL x Range state */
uint16_t xyl_y_range_min; /* The value of the xyL y Range Min field of the Light xyL y Range state */
uint16_t xyl_y_range_max; /* The value of the xyL y Range Max field of the Light xyL y Range state */
};
struct bt_mesh_light_xyl_set {
bool op_en; /* Indicate whether optional parameters included */
uint16_t xyl_lightness; /* The target value of the Light xyL Lightness state */
uint16_t xyl_x; /* The target value of the Light xyL x state */
uint16_t xyl_y; /* The target value of the Light xyL y state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_xyl_default_set {
uint16_t lightness; /* The value of the Light Lightness Default state */
uint16_t xyl_x; /* The value of the Light xyL x Default state */
uint16_t xyl_y; /* The value of the Light xyL y Default state */
};
struct bt_mesh_light_xyl_range_set {
uint16_t xyl_x_range_min; /* The value of the xyL x Range Min field of the Light xyL x Range state */
uint16_t xyl_x_range_max; /* The value of the xyL x Range Max field of the Light xyL x Range state */
uint16_t xyl_y_range_min; /* The value of the xyL y Range Min field of the Light xyL y Range state */
uint16_t xyl_y_range_max; /* The value of the xyL y Range Max field of the Light xyL y Range state */
};
/* Light LC Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[];
/** @def BLE_MESH_MODEL_LIGHT_LC_CLI
*
* Define a new light lc client model. Note that this API needs
* to be repeated for each element which the application wants
* to have a light lc client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_light_lc_cli.
*
* @return New light lc client model instance.
*/
#define BLE_MESH_MODEL_LIGHT_LC_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LC_CLI, \
bt_mesh_light_lc_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_light_lc_client_t;
struct bt_mesh_light_lc_mode_status {
uint8_t mode; /* The present value of the Light LC Mode state */
};
struct bt_mesh_light_lc_om_status {
uint8_t mode; /* The present value of the Light LC Occupancy Mode state */
};
struct bt_mesh_light_lc_light_onoff_status {
bool op_en; /* Indicate whether optional parameters included */
uint8_t present_light_onoff; /* The present value of the Light LC Light OnOff state */
uint8_t target_light_onoff; /* The target value of the Light LC Light OnOff state (Optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_light_lc_property_status {
uint16_t light_lc_property_id; /* Property ID identifying a Light LC Property */
struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */
};
struct bt_mesh_light_lc_mode_set {
uint8_t mode; /* The target value of the Light LC Mode state */
};
struct bt_mesh_light_lc_om_set {
uint8_t mode; /* The target value of the Light LC Occupancy Mode state */
};
struct bt_mesh_light_lc_light_onoff_set {
bool op_en; /* Indicate whether optional parameters included */
uint8_t light_onoff; /* The target value of the Light LC Light OnOff state */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_light_lc_property_get {
uint16_t light_lc_property_id; /* Property ID identifying a Light LC Property */
};
struct bt_mesh_light_lc_property_set {
uint16_t light_lc_property_id; /* Property ID identifying a Light LC Property */
struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */
};
/**
* @brief This function is called to get light states.
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of light get message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set light states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of light set message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}
#endif
#endif /* _LIGHTING_CLIENT_H_ */

View File

@ -0,0 +1,155 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Sensor Client Model APIs.
*/
#ifndef _SENSOR_CLIENT_H_
#define _SENSOR_CLIENT_H_
#include "client_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Sensor Client Model Callback */
extern const struct bt_mesh_model_cb bt_mesh_sensor_client_cb;
/* Sensor Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_sensor_cli_op[];
/** @def BLE_MESH_MODEL_SENSOR_CLI
*
* Define a new sensor client model. Note that this API needs to
* be repeated for each element which the application wants to
* have a sensor client model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_sensor_cli.
*
* @return New sensor client model instance.
*/
#define BLE_MESH_MODEL_SENSOR_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SENSOR_CLI, \
bt_mesh_sensor_cli_op, cli_pub, cli_data, &bt_mesh_sensor_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_sensor_client_t;
typedef bt_mesh_client_internal_data_t sensor_internal_data_t;
struct bt_mesh_sensor_descriptor_status {
struct net_buf_simple *descriptor; /* Sequence of 8-octet sensor descriptors (optional) */
};
struct bt_mesh_sensor_cadence_status {
uint16_t property_id; /* Property for the sensor */
struct net_buf_simple *sensor_cadence_value; /* Value of sensor cadence state */
};
struct bt_mesh_sensor_settings_status {
uint16_t sensor_property_id; /* Property ID identifying a sensor */
struct net_buf_simple *sensor_setting_property_ids; /* A sequence of N sensor setting property IDs (optional) */
};
struct bt_mesh_sensor_setting_status {
bool op_en; /* Indicate whether optional parameters included */
uint16_t sensor_property_id; /* Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /* Setting ID identifying a setting within a sensor */
uint8_t sensor_setting_access; /* Read/Write access rights for the setting (optional) */
struct net_buf_simple *sensor_setting_raw; /* Raw value for the setting */
};
struct bt_mesh_sensor_status {
struct net_buf_simple *marshalled_sensor_data; /* Value of sensor data state (optional) */
};
struct bt_mesh_sensor_column_status {
uint16_t property_id; /* Property identifying a sensor and the Y axis */
struct net_buf_simple *sensor_column_value; /* Left values of sensor column status */
};
struct bt_mesh_sensor_series_status {
uint16_t property_id; /* Property identifying a sensor and the Y axis */
struct net_buf_simple *sensor_series_value; /* Left values of sensor series status */
};
struct bt_mesh_sensor_descriptor_get {
bool op_en; /* Indicate whether optional parameters included */
uint16_t property_id; /* Property ID for the sensor (optional) */
};
struct bt_mesh_sensor_cadence_get {
uint16_t property_id; /* Property ID for the sensor */
};
struct bt_mesh_sensor_cadence_set {
uint16_t property_id; /* Property ID for the sensor */
uint8_t fast_cadence_period_divisor : 7, /* Divisor for the publish period */
status_trigger_type : 1; /* The unit and format of the Status Trigger Delta fields */
struct net_buf_simple *status_trigger_delta_down; /* Delta down value that triggers a status message */
struct net_buf_simple *status_trigger_delta_up; /* Delta up value that triggers a status message */
uint8_t status_min_interval; /* Minimum interval between two consecutive Status messages */
struct net_buf_simple *fast_cadence_low; /* Low value for the fast cadence range */
struct net_buf_simple *fast_cadence_high; /* Fast value for the fast cadence range */
};
struct bt_mesh_sensor_settings_get {
uint16_t sensor_property_id; /* Property ID for the sensor */
};
struct bt_mesh_sensor_setting_get {
uint16_t sensor_property_id; /* Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /* Setting ID identifying a setting within a sensor */
};
struct bt_mesh_sensor_setting_set {
uint16_t sensor_property_id; /* Property ID identifying a sensor */
uint16_t sensor_setting_property_id; /* Setting ID identifying a setting within a sensor */
struct net_buf_simple *sensor_setting_raw; /* Raw value for the setting */
};
struct bt_mesh_sensor_get {
bool op_en; /* Indicate whether optional parameters included */
uint16_t property_id; /* Property ID for the sensor (optional) */
};
struct bt_mesh_sensor_column_get {
uint16_t property_id; /* Property identifying a sensor */
struct net_buf_simple *raw_value_x; /* Raw value identifying a column */
};
struct bt_mesh_sensor_series_get {
bool op_en; /* Indicate whether optional parameters included */
uint16_t property_id; /* Property identifying a sensor */
struct net_buf_simple *raw_value_x1; /* Raw value identifying a starting column (optional) */
struct net_buf_simple *raw_value_x2; /* Raw value identifying a ending column (C.1) */
};
/**
* @brief This function is called to get sensor states.
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of sensor get message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set sensor states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of sensor set message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}
#endif
#endif /* _SENSOR_CLIENT_H_ */

View File

@ -0,0 +1,225 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief Bluetooth Mesh Time and Scene Client Model APIs.
*/
#ifndef _TIME_SCENE_CLIENT_H_
#define _TIME_SCENE_CLIENT_H_
#include "client_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Time scene client model common structure */
typedef bt_mesh_client_user_data_t bt_mesh_time_scene_client_t;
typedef bt_mesh_client_internal_data_t time_scene_internal_data_t;
/* Time Scene Client Model Callback */
extern const struct bt_mesh_model_cb bt_mesh_time_scene_client_cb;
/* Time Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_time_cli_op[];
/** @def BLE_MESH_MODEL_TIME_CLI
*
* Define a new time client model. Note that this API needs to
* be repeated for each element which the application wants to
* have a time model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_time_cli.
*
* @return New time client model instance.
*/
#define BLE_MESH_MODEL_TIME_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_TIME_CLI, \
bt_mesh_time_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_time_client_t;
struct bt_mesh_time_status {
uint8_t tai_seconds[5]; /* The current TAI time in seconds */
uint8_t sub_second; /* The sub-second time in units of 1/256 second */
uint8_t uncertainty; /* The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /* 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /* Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /* The local time zone offset in 15-minute increments */
};
struct bt_mesh_time_zone_status {
uint8_t time_zone_offset_curr; /* Current local time zone offset */
uint8_t time_zone_offset_new; /* Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /* TAI Seconds time of the upcoming Time Zone Offset change */
};
struct bt_mesh_tai_utc_delta_status {
uint16_t tai_utc_delta_curr : 15; /* Current difference between TAI and UTC in seconds */
uint16_t padding_1 : 1; /* Always 0b0. Other values are Prohibited. */
uint16_t tai_utc_delta_new : 15; /* Upcoming difference between TAI and UTC in seconds */
uint16_t padding_2 : 1; /* Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /* TAI Seconds time of the upcoming TAI-UTC Delta change */
};
struct bt_mesh_time_role_status {
uint8_t time_role; /* The Time Role for the element */
};
struct bt_mesh_time_set {
uint8_t tai_seconds[5]; /* The current TAI time in seconds */
uint8_t sub_second; /* The sub-second time in units of 1/256 second */
uint8_t uncertainty; /* The estimated uncertainty in 10-millisecond steps */
uint16_t time_authority : 1; /* 0 = No Time Authority, 1 = Time Authority */
uint16_t tai_utc_delta : 15; /* Current difference between TAI and UTC in seconds */
uint8_t time_zone_offset; /* The local time zone offset in 15-minute increments */
};
struct bt_mesh_time_zone_set {
uint8_t time_zone_offset_new; /* Upcoming local time zone offset */
uint8_t tai_zone_change[5]; /* TAI Seconds time of the upcoming Time Zone Offset change */
};
struct bt_mesh_tai_utc_delta_set {
uint16_t tai_utc_delta_new : 15; /* Upcoming difference between TAI and UTC in seconds */
uint16_t padding : 1; /* Always 0b0. Other values are Prohibited. */
uint8_t tai_delta_change[5]; /* TAI Seconds time of the upcoming TAI-UTC Delta change */
};
struct bt_mesh_time_role_set {
uint8_t time_role; /* The Time Role for the element */
};
/* Scene Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_scene_cli_op[];
/** @def BLE_MESH_MODEL_SCENE_CLI
*
* Define a new scene client model. Note that this API needs to
* be repeated for each element which the application wants to
* have a scene model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_scene_cli.
*
* @return New scene client model instance.
*/
#define BLE_MESH_MODEL_SCENE_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SCENE_CLI, \
bt_mesh_scene_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_scene_client_t;
struct bt_mesh_scene_status {
bool op_en; /* Indicate whether optional parameters included */
uint8_t status_code; /* Status code for the last operation */
uint16_t current_scene; /* Scene Number of a current scene */
uint16_t target_scene; /* Scene Number of a target scene (optional) */
uint8_t remain_time; /* Time to complete state transition (C.1) */
};
struct bt_mesh_scene_register_status {
uint8_t status_code; /* Status code for the previous operation */
uint16_t current_scene; /* Scene Number of a current scene */
struct net_buf_simple *scenes; /* A list of scenes stored within an element */
};
struct bt_mesh_scene_store {
uint16_t scene_number; /* The number of the scene to be stored */
};
struct bt_mesh_scene_recall {
bool op_en; /* Indicate whether optional parameters included */
uint16_t scene_number; /* The number of the scene to be recalled */
uint8_t tid; /* Transaction Identifier */
uint8_t trans_time; /* Time to complete state transition (optional) */
uint8_t delay; /* Indicate message execution delay (C.1) */
};
struct bt_mesh_scene_delete {
uint16_t scene_number; /* The number of the scene to be deleted */
};
/* Scheduler Client Model Context */
extern const struct bt_mesh_model_op bt_mesh_scheduler_cli_op[];
/** @def BLE_MESH_MODEL_SCHEDULER_CLI
*
* Define a new scheduler client model. Note that this API needs to
* be repeated for each element which the application wants to
* have a scheduler model on.
* @param cli_pub Pointer to a unique struct bt_mesh_model_pub.
* @param cli_data Pointer to a unique struct bt_mesh_scheduler_cli.
*
* @return New scheduler client model instance.
*/
#define BLE_MESH_MODEL_SCHEDULER_CLI(cli_pub, cli_data) \
BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SCHEDULER_CLI, \
bt_mesh_scheduler_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb)
typedef bt_mesh_client_user_data_t bt_mesh_scheduler_client_t;
struct bt_mesh_scheduler_status {
uint16_t schedules; /* Bit field indicating defined Actions in the Schedule Register */
};
struct bt_mesh_scheduler_act_status {
uint64_t index : 4; /* Enumerates (selects) a Schedule Register entry */
uint64_t year : 7; /* Scheduled year for the action */
uint64_t month : 12; /* Scheduled month for the action */
uint64_t day : 5; /* Scheduled day of the month for the action */
uint64_t hour : 5; /* Scheduled hour for the action */
uint64_t minute : 6; /* Scheduled minute for the action */
uint64_t second : 6; /* Scheduled second for the action */
uint64_t day_of_week : 7; /* Schedule days of the week for the action */
uint64_t action : 4; /* Action to be performed at the scheduled time */
uint64_t trans_time : 8; /* Transition time for this action */
uint16_t scene_number; /* Transition time for this action */
};
struct bt_mesh_scheduler_act_get {
uint8_t index; /* Index of the Schedule Register entry to get */
};
struct bt_mesh_scheduler_act_set {
uint64_t index : 4; /* Index of the Schedule Register entry to set */
uint64_t year : 7; /* Scheduled year for the action */
uint64_t month : 12; /* Scheduled month for the action */
uint64_t day : 5; /* Scheduled day of the month for the action */
uint64_t hour : 5; /* Scheduled hour for the action */
uint64_t minute : 6; /* Scheduled minute for the action */
uint64_t second : 6; /* Scheduled second for the action */
uint64_t day_of_week : 7; /* Schedule days of the week for the action */
uint64_t action : 4; /* Action to be performed at the scheduled time */
uint64_t trans_time : 8; /* Transition time for this action */
uint16_t scene_number; /* Transition time for this action */
};
/**
* @brief This function is called to get scene states.
*
* @param[in] common: Message common information structure
* @param[in] get: Pointer of time scene get message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get);
/**
* @brief This function is called to set scene states.
*
* @param[in] common: Message common information structure
* @param[in] set: Pointer of time scene set message value
*
* @return Zero-success, other-fail
*/
int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set);
#ifdef __cplusplus
}
#endif
#endif /* _TIME_SCENE_CLIENT_H_ */

View File

@ -0,0 +1,276 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _MODEL_OPCODE_H_
#define _MODEL_OPCODE_H_
#include "mesh_access.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Generic OnOff Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_ONOFF_GET BLE_MESH_MODEL_OP_2(0x82, 0x01)
#define BLE_MESH_MODEL_OP_GEN_ONOFF_SET BLE_MESH_MODEL_OP_2(0x82, 0x02)
#define BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x03)
#define BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x04)
/* Generic Level Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_LEVEL_GET BLE_MESH_MODEL_OP_2(0x82, 0x05)
#define BLE_MESH_MODEL_OP_GEN_LEVEL_SET BLE_MESH_MODEL_OP_2(0x82, 0x06)
#define BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x07)
#define BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x08)
#define BLE_MESH_MODEL_OP_GEN_DELTA_SET BLE_MESH_MODEL_OP_2(0x82, 0x09)
#define BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x0A)
#define BLE_MESH_MODEL_OP_GEN_MOVE_SET BLE_MESH_MODEL_OP_2(0x82, 0x0B)
#define BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x0C)
/* Generic Default Transition Time Message Opcode*/
#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET BLE_MESH_MODEL_OP_2(0x82, 0x0D)
#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET BLE_MESH_MODEL_OP_2(0x82, 0x0E)
#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x0F)
#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x10)
/* Generic Power OnOff Message Opcode*/
#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET BLE_MESH_MODEL_OP_2(0x82, 0x11)
#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x12)
/* Generic Power OnOff Setup Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET BLE_MESH_MODEL_OP_2(0x82, 0x13)
#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x14)
/* Generic Power Level Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET BLE_MESH_MODEL_OP_2(0x82, 0x15)
#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET BLE_MESH_MODEL_OP_2(0x82, 0x16)
#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x17)
#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x18)
#define BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET BLE_MESH_MODEL_OP_2(0x82, 0x19)
#define BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x1A)
#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x1B)
#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x1C)
#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x1D)
#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x1E)
/* Generic Power Level Setup Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x1F)
#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x20)
#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x21)
#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x22)
/* Generic Battery Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_BATTERY_GET BLE_MESH_MODEL_OP_2(0x82, 0x23)
#define BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x24)
/* Generic Location Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET BLE_MESH_MODEL_OP_2(0x82, 0x25)
#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS BLE_MESH_MODEL_OP_1(0x40)
#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET BLE_MESH_MODEL_OP_2(0x82, 0x26)
#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x27)
/* Generic Location Setup Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET BLE_MESH_MODEL_OP_1(0x41)
#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK BLE_MESH_MODEL_OP_1(0x42)
#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET BLE_MESH_MODEL_OP_2(0x82, 0x28)
#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x29)
/* Generic Manufacturer Property Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x2A)
#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x43)
#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x2B)
#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x44)
#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x45)
#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x46)
/* Generic Admin Property Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x2C)
#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x47)
#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x2D)
#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x48)
#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x49)
#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x4A)
/* Generic User Property Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x2E)
#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x4B)
#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x2F)
#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x4C)
#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x4D)
#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x4E)
/* Generic Client Property Message Opcode */
#define BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET BLE_MESH_MODEL_OP_1(0x4F)
#define BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x50)
/* Sensor Message Opcode */
#define BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET BLE_MESH_MODEL_OP_2(0x82, 0x30)
#define BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS BLE_MESH_MODEL_OP_1(0x51)
#define BLE_MESH_MODEL_OP_SENSOR_GET BLE_MESH_MODEL_OP_2(0x82, 0x31)
#define BLE_MESH_MODEL_OP_SENSOR_STATUS BLE_MESH_MODEL_OP_1(0x52)
#define BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET BLE_MESH_MODEL_OP_2(0x82, 0x32)
#define BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS BLE_MESH_MODEL_OP_1(0x53)
#define BLE_MESH_MODEL_OP_SENSOR_SERIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x33)
#define BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS BLE_MESH_MODEL_OP_1(0x54)
/* Sensor Setup Message Opcode */
#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET BLE_MESH_MODEL_OP_2(0x82, 0x34)
#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET BLE_MESH_MODEL_OP_1(0x55)
#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK BLE_MESH_MODEL_OP_1(0x56)
#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS BLE_MESH_MODEL_OP_1(0x57)
#define BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET BLE_MESH_MODEL_OP_2(0x82, 0x35)
#define BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS BLE_MESH_MODEL_OP_1(0x58)
#define BLE_MESH_MODEL_OP_SENSOR_SETTING_GET BLE_MESH_MODEL_OP_2(0x82, 0x36)
#define BLE_MESH_MODEL_OP_SENSOR_SETTING_SET BLE_MESH_MODEL_OP_1(0x59)
#define BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK BLE_MESH_MODEL_OP_1(0x5A)
#define BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS BLE_MESH_MODEL_OP_1(0x5B)
/* Time Message Opcode */
#define BLE_MESH_MODEL_OP_TIME_GET BLE_MESH_MODEL_OP_2(0x82, 0x37)
#define BLE_MESH_MODEL_OP_TIME_SET BLE_MESH_MODEL_OP_1(0x5C)
#define BLE_MESH_MODEL_OP_TIME_STATUS BLE_MESH_MODEL_OP_1(0x5D)
#define BLE_MESH_MODEL_OP_TIME_ROLE_GET BLE_MESH_MODEL_OP_2(0x82, 0x38)
#define BLE_MESH_MODEL_OP_TIME_ROLE_SET BLE_MESH_MODEL_OP_2(0x82, 0x39)
#define BLE_MESH_MODEL_OP_TIME_ROLE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x3A)
#define BLE_MESH_MODEL_OP_TIME_ZONE_GET BLE_MESH_MODEL_OP_2(0x82, 0x3B)
#define BLE_MESH_MODEL_OP_TIME_ZONE_SET BLE_MESH_MODEL_OP_2(0x82, 0x3C)
#define BLE_MESH_MODEL_OP_TIME_ZONE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x3D)
#define BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET BLE_MESH_MODEL_OP_2(0x82, 0x3E)
#define BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET BLE_MESH_MODEL_OP_2(0x82, 0x3F)
#define BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x40)
/* Scene Message Opcode */
#define BLE_MESH_MODEL_OP_SCENE_GET BLE_MESH_MODEL_OP_2(0x82, 0x41)
#define BLE_MESH_MODEL_OP_SCENE_RECALL BLE_MESH_MODEL_OP_2(0x82, 0x42)
#define BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x43)
#define BLE_MESH_MODEL_OP_SCENE_STATUS BLE_MESH_MODEL_OP_1(0x5E)
#define BLE_MESH_MODEL_OP_SCENE_REGISTER_GET BLE_MESH_MODEL_OP_2(0x82, 0x44)
#define BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x45)
/* Scene Setup Message Opcode */
#define BLE_MESH_MODEL_OP_SCENE_STORE BLE_MESH_MODEL_OP_2(0x82, 0x46)
#define BLE_MESH_MODEL_OP_SCENE_STORE_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x47)
#define BLE_MESH_MODEL_OP_SCENE_DELETE BLE_MESH_MODEL_OP_2(0x82, 0x9E)
#define BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x9F)
/* Scheduler Message Opcode */
#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET BLE_MESH_MODEL_OP_2(0x82, 0x48)
#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS BLE_MESH_MODEL_OP_1(0x5F)
#define BLE_MESH_MODEL_OP_SCHEDULER_GET BLE_MESH_MODEL_OP_2(0x82, 0x49)
#define BLE_MESH_MODEL_OP_SCHEDULER_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x4A)
/* Scheduler Setup Message Opcode */
#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET BLE_MESH_MODEL_OP_1(0x60)
#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK BLE_MESH_MODEL_OP_1(0x61)
/* Light Lightness Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET BLE_MESH_MODEL_OP_2(0x82, 0x4B)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET BLE_MESH_MODEL_OP_2(0x82, 0x4C)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x4D)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x4E)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET BLE_MESH_MODEL_OP_2(0x82, 0x4F)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET BLE_MESH_MODEL_OP_2(0x82, 0x50)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x51)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x52)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET BLE_MESH_MODEL_OP_2(0x82, 0x53)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x54)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x55)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x56)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x57)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x58)
/* Light Lightness Setup Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x59)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x5A)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x5B)
#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x5C)
/* Light CTL Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_CTL_GET BLE_MESH_MODEL_OP_2(0x82, 0x5D)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_SET BLE_MESH_MODEL_OP_2(0x82, 0x5E)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x5F)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x60)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET BLE_MESH_MODEL_OP_2(0x82, 0x61)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x62)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x63)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET BLE_MESH_MODEL_OP_2(0x82, 0x64)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x65)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x66)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x67)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x68)
/* Light CTL Setup Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x69)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x6A)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x6B)
#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x6C)
/* Light HSL Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_HSL_GET BLE_MESH_MODEL_OP_2(0x82, 0x6D)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET BLE_MESH_MODEL_OP_2(0x82, 0x6E)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET BLE_MESH_MODEL_OP_2(0x82, 0x6F)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x70)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x71)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET BLE_MESH_MODEL_OP_2(0x82, 0x72)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET BLE_MESH_MODEL_OP_2(0x82, 0x73)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x74)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x75)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_SET BLE_MESH_MODEL_OP_2(0x82, 0x76)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x77)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x78)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET BLE_MESH_MODEL_OP_2(0x82, 0x79)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x7A)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x7B)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x7C)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x7D)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x7E)
/* Light HSL Setup Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x7F)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x80)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x81)
#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x82)
/* Light xyL Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_XYL_GET BLE_MESH_MODEL_OP_2(0x82, 0x83)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_SET BLE_MESH_MODEL_OP_2(0x82, 0x84)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x85)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x86)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET BLE_MESH_MODEL_OP_2(0x82, 0x87)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x88)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x89)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x8A)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x8B)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x8C)
/* Light xyL Setup Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x8D)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x8E)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x8F)
#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x90)
/* Light Control Message Opcode */
#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET BLE_MESH_MODEL_OP_2(0x82, 0x91)
#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET BLE_MESH_MODEL_OP_2(0x82, 0x92)
#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x93)
#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x94)
#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET BLE_MESH_MODEL_OP_2(0x82, 0x95)
#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET BLE_MESH_MODEL_OP_2(0x82, 0x96)
#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x97)
#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x98)
#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET BLE_MESH_MODEL_OP_2(0x82, 0x99)
#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET BLE_MESH_MODEL_OP_2(0x82, 0x9A)
#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x9B)
#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x9C)
#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x9D)
#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x62)
#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x63)
#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x64)
#ifdef __cplusplus
}
#endif
#endif /* _MODEL_OPCODE_H_ */

View File

@ -0,0 +1,367 @@
/* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models
*
* SPDX-FileCopyrightText: 2018 Vikrant More
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _GENERIC_SERVER_H_
#define _GENERIC_SERVER_H_
#include "server_common.h"
#ifdef __cplusplus
extern "C" {
#endif
struct bt_mesh_gen_onoff_state {
uint8_t onoff;
uint8_t target_onoff;
};
struct bt_mesh_gen_onoff_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_onoff_state state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
};
struct bt_mesh_gen_level_state {
int16_t level;
int16_t target_level;
int16_t last_level;
int32_t last_delta;
bool move_start;
bool positive;
};
struct bt_mesh_gen_level_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_level_state state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_level;
};
struct bt_mesh_gen_def_trans_time_state {
uint8_t trans_time;
};
struct bt_mesh_gen_def_trans_time_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_def_trans_time_state state;
};
struct bt_mesh_gen_onpowerup_state {
uint8_t onpowerup;
};
struct bt_mesh_gen_power_onoff_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_onpowerup_state *state;
};
struct bt_mesh_gen_power_onoff_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_onpowerup_state *state;
};
struct bt_mesh_gen_power_level_state {
uint16_t power_actual;
uint16_t target_power_actual;
uint16_t power_last;
uint16_t power_default;
uint8_t status_code;
uint16_t power_range_min;
uint16_t power_range_max;
};
struct bt_mesh_gen_power_level_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_power_level_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_level;
};
struct bt_mesh_gen_power_level_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_power_level_state *state;
};
struct bt_mesh_gen_battery_state {
uint32_t battery_level : 8,
time_to_discharge : 24;
uint32_t time_to_charge : 24,
battery_flags : 8;
};
struct bt_mesh_gen_battery_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_battery_state state;
};
struct bt_mesh_gen_location_state {
int32_t global_latitude;
int32_t global_longitude;
int16_t global_altitude;
int16_t local_north;
int16_t local_east;
int16_t local_altitude;
uint8_t floor_number;
uint16_t uncertainty;
};
struct bt_mesh_gen_location_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_location_state *state;
};
struct bt_mesh_gen_location_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_gen_location_state *state;
};
/**
* According to the hierarchy of Generic Property states (Model Spec section 3.1.8),
* the Manufacturer Properties and Admin Properties may contain multiple Property
* states. User Properties just a collection of which can be accessed.
*
* property_count: Number of the properties contained in the table
* properties: Table of the properties
*
* These variables need to be initialized in the application layer, the precise
* number of the properties should be set and memories used to store the property
* values should be allocated.
*/
enum bt_mesh_gen_user_prop_access {
USER_ACCESS_PROHIBIT,
USER_ACCESS_READ,
USER_ACCESS_WRITE,
USER_ACCESS_READ_WRITE,
};
enum bt_mesh_gen_admin_prop_access {
ADMIN_NOT_USER_PROP,
ADMIN_ACCESS_READ,
ADMIN_ACCESS_WRITE,
ADMIN_ACCESS_READ_WRITE,
};
enum bt_mesh_gen_manu_prop_access {
MANU_NOT_USER_PROP,
MANU_ACCESS_READ,
};
struct bt_mesh_generic_property {
uint16_t id;
uint8_t user_access;
uint8_t admin_access;
uint8_t manu_access;
struct net_buf_simple *val;
};
struct bt_mesh_gen_user_prop_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
uint8_t property_count;
struct bt_mesh_generic_property *properties;
};
struct bt_mesh_gen_admin_prop_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
uint8_t property_count;
struct bt_mesh_generic_property *properties;
};
struct bt_mesh_gen_manu_prop_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
uint8_t property_count;
struct bt_mesh_generic_property *properties;
};
struct bt_mesh_gen_client_prop_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
uint8_t id_count;
uint16_t *property_ids;
};
typedef union {
struct {
uint8_t onoff;
} gen_onoff_set;
struct {
int16_t level;
} gen_level_set;
struct {
int16_t level;
} gen_delta_set;
struct {
int16_t level;
} gen_move_set;
struct {
uint8_t trans_time;
} gen_def_trans_time_set;
struct {
uint8_t onpowerup;
} gen_onpowerup_set;
struct {
uint16_t power;
} gen_power_level_set;
struct {
uint16_t power;
} gen_power_default_set;
struct {
uint16_t range_min;
uint16_t range_max;
} gen_power_range_set;
struct {
int32_t latitude;
int32_t longitude;
int16_t altitude;
} gen_loc_global_set;
struct {
int16_t north;
int16_t east;
int16_t altitude;
uint8_t floor_number;
uint16_t uncertainty;
} gen_loc_local_set;
struct {
uint16_t id;
struct net_buf_simple *value;
} gen_user_prop_set;
struct {
uint16_t id;
uint8_t access;
struct net_buf_simple *value;
} gen_admin_prop_set;
struct {
uint16_t id;
uint8_t access;
} gen_manu_prop_set;
} bt_mesh_gen_server_state_change_t;
typedef union {
struct {
uint16_t id;
} user_property_get;
struct {
uint16_t id;
} admin_property_get;
struct {
uint16_t id;
} manu_property_get;
struct {
uint16_t id;
} client_properties_get;
} bt_mesh_gen_server_recv_get_msg_t;
typedef union {
struct {
bool op_en;
uint8_t onoff;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} onoff_set;
struct {
bool op_en;
int16_t level;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} level_set;
struct {
bool op_en;
int32_t delta_level;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} delta_set;
struct {
bool op_en;
int16_t delta_level;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} move_set;
struct {
uint8_t trans_time;
} def_trans_time_set;
struct {
uint8_t onpowerup;
} onpowerup_set;
struct {
bool op_en;
uint16_t power;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} power_level_set;
struct {
uint16_t power;
} power_default_set;
struct {
uint16_t range_min;
uint16_t range_max;
} power_range_set;
struct {
int32_t latitude;
int32_t longitude;
int16_t altitude;
} loc_global_set;
struct {
int16_t north;
int16_t east;
int16_t altitude;
uint8_t floor_number;
uint16_t uncertainty;
} loc_local_set;
struct {
uint16_t id;
struct net_buf_simple *value;
} user_property_set;
struct {
uint16_t id;
uint8_t access;
struct net_buf_simple *value;
} admin_property_set;
struct {
uint16_t id;
uint8_t access;
} manu_property_set;
} bt_mesh_gen_server_recv_set_msg_t;
void bt_mesh_generic_server_lock(void);
void bt_mesh_generic_server_unlock(void);
void gen_onoff_publish(struct bt_mesh_model *model);
void gen_level_publish(struct bt_mesh_model *model);
void gen_onpowerup_publish(struct bt_mesh_model *model);
void gen_power_level_publish(struct bt_mesh_model *model, uint16_t opcode);
#ifdef __cplusplus
}
#endif
#endif /* _GENERIC_SERVER_H_ */

View File

@ -0,0 +1,510 @@
/* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models
*
* SPDX-FileCopyrightText: 2018 Vikrant More
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _LIGHTING_SERVER_H_
#define _LIGHTING_SERVER_H_
#include "server_common.h"
#ifdef __cplusplus
extern "C" {
#endif
struct bt_mesh_light_lightness_state {
uint16_t lightness_linear;
uint16_t target_lightness_linear;
uint16_t lightness_actual;
uint16_t target_lightness_actual;
uint16_t lightness_last;
uint16_t lightness_default;
uint8_t status_code;
uint16_t lightness_range_min;
uint16_t lightness_range_max;
};
struct bt_mesh_light_lightness_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_lightness_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition actual_transition;
struct bt_mesh_state_transition linear_transition;
int32_t tt_delta_lightness_actual;
int32_t tt_delta_lightness_linear;
};
struct bt_mesh_light_lightness_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_lightness_state *state;
};
struct bt_mesh_light_ctl_state {
uint16_t lightness;
uint16_t target_lightness;
uint16_t temperature;
uint16_t target_temperature;
int16_t delta_uv;
int16_t target_delta_uv;
uint8_t status_code;
uint16_t temperature_range_min;
uint16_t temperature_range_max;
uint16_t lightness_default;
uint16_t temperature_default;
int16_t delta_uv_default;
};
struct bt_mesh_light_ctl_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_ctl_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_lightness;
int32_t tt_delta_temperature;
int32_t tt_delta_delta_uv;
};
struct bt_mesh_light_ctl_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_ctl_state *state;
};
struct bt_mesh_light_ctl_temp_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_ctl_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_temperature;
int32_t tt_delta_delta_uv;
};
struct bt_mesh_light_hsl_state {
uint16_t lightness;
uint16_t target_lightness;
uint16_t hue;
uint16_t target_hue;
uint16_t saturation;
uint16_t target_saturation;
uint16_t lightness_default;
uint16_t hue_default;
uint16_t saturation_default;
uint8_t status_code;
uint16_t hue_range_min;
uint16_t hue_range_max;
uint16_t saturation_range_min;
uint16_t saturation_range_max;
};
struct bt_mesh_light_hsl_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_hsl_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_lightness;
int32_t tt_delta_hue;
int32_t tt_delta_saturation;
};
struct bt_mesh_light_hsl_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_hsl_state *state;
};
struct bt_mesh_light_hsl_hue_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_hsl_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_hue;
};
struct bt_mesh_light_hsl_sat_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_hsl_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_saturation;
};
struct bt_mesh_light_xyl_state {
uint16_t lightness;
uint16_t target_lightness;
uint16_t x;
uint16_t target_x;
uint16_t y;
uint16_t target_y;
uint16_t lightness_default;
uint16_t x_default;
uint16_t y_default;
uint8_t status_code;
uint16_t x_range_min;
uint16_t x_range_max;
uint16_t y_range_min;
uint16_t y_range_max;
};
struct bt_mesh_light_xyl_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_xyl_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
int32_t tt_delta_lightness;
int32_t tt_delta_x;
int32_t tt_delta_y;
};
struct bt_mesh_light_xyl_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_xyl_state *state;
};
struct bt_mesh_light_lc_state {
uint32_t mode : 1, /* default 0 */
occupancy_mode : 1, /* default 1 */
light_onoff : 1,
target_light_onoff : 1,
occupancy : 1,
ambient_luxlevel : 24; /* 0x000000 ~ 0xFFFFFF */
uint16_t linear_output; /* 0x0000 ~ 0xFFFF */
};
struct bt_mesh_light_lc_property_state {
uint32_t time_occupancy_delay; /* 0x003A */
uint32_t time_fade_on; /* 0x0037 */
uint32_t time_run_on; /* 0x003C */
uint32_t time_fade; /* 0x0036 */
uint32_t time_prolong; /* 0x003B */
uint32_t time_fade_standby_auto; /* 0x0038 */
uint32_t time_fade_standby_manual; /* 0x0039 */
uint16_t lightness_on; /* 0x002E */
uint16_t lightness_prolong; /* 0x002F */
uint16_t lightness_standby; /* 0x0030 */
uint16_t ambient_luxlevel_on; /* 0x002B, 0x0000 ~ 0xFFFF */
uint16_t ambient_luxlevel_prolong; /* 0x002C, 0x0000 ~ 0xFFFF */
uint16_t ambient_luxlevel_standby; /* 0x002D, 0x0000 ~ 0xFFFF */
float regulator_kiu; /* 0x0033, 0.0 ~ 1000.0, default 250.0 */
float regulator_kid; /* 0x0032, 0.0 ~ 1000.0, default 25.0 */
float regulator_kpu; /* 0x0035, 0.0 ~ 1000.0, default 80.0 */
float regulator_kpd; /* 0x0034, 0.0 ~ 1000.0, default 80.0 */
int8_t regulator_accuracy; /* 0x0031, 0.0 ~ 100.0, default 2.0 */
uint32_t set_occupancy_to_1_delay;
};
typedef enum {
LC_OFF,
LC_STANDBY,
LC_FADE_ON,
LC_RUN,
LC_FADE,
LC_PROLONG,
LC_FADE_STANDBY_AUTO,
LC_FADE_STANDBY_MANUAL,
} bt_mesh_lc_state;
struct bt_mesh_light_lc_state_machine {
struct {
uint8_t fade_on;
uint8_t fade;
uint8_t fade_standby_auto;
uint8_t fade_standby_manual;
} trans_time;
bt_mesh_lc_state state;
struct k_delayed_work timer;
};
struct bt_mesh_light_control {
struct bt_mesh_light_lc_state state;
struct bt_mesh_light_lc_property_state prop_state;
struct bt_mesh_light_lc_state_machine state_machine;
};
struct bt_mesh_light_lc_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_control *lc;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
};
struct bt_mesh_light_lc_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_light_control *lc;
};
typedef union {
struct {
uint16_t lightness;
} lightness_set;
struct {
uint16_t lightness;
} lightness_linear_set;
struct {
uint16_t lightness;
} lightness_default_set;
struct {
uint16_t range_min;
uint16_t range_max;
} lightness_range_set;
struct {
uint16_t lightness;
uint16_t temperature;
int16_t delta_uv;
} ctl_set;
struct {
uint16_t temperature;
int16_t delta_uv;
} ctl_temp_set;
struct {
uint16_t range_min;
uint16_t range_max;
} ctl_temp_range_set;
struct {
uint16_t lightness;
uint16_t temperature;
int16_t delta_uv;
} ctl_default_set;
struct {
uint16_t lightness;
uint16_t hue;
uint16_t saturation;
} hsl_set;
struct {
uint16_t hue;
} hsl_hue_set;
struct {
uint16_t saturation;
} hsl_saturation_set;
struct {
uint16_t lightness;
uint16_t hue;
uint16_t saturation;
} hsl_default_set;
struct {
uint16_t hue_range_min;
uint16_t hue_range_max;
uint16_t sat_range_min;
uint16_t sat_range_max;
} hsl_range_set;
struct {
uint16_t lightness;
uint16_t x;
uint16_t y;
} xyl_set;
struct {
uint16_t lightness;
uint16_t x;
uint16_t y;
} xyl_default_set;
struct {
uint16_t x_range_min;
uint16_t x_range_max;
uint16_t y_range_min;
uint16_t y_range_max;
} xyl_range_set;
struct {
uint8_t mode;
} lc_mode_set;
struct {
uint8_t mode;
} lc_om_set;
struct {
uint8_t onoff;
} lc_light_onoff_set;
struct {
uint16_t id;
struct net_buf_simple *value;
} lc_property_set;
struct {
uint16_t property_id;
union {
uint8_t occupancy;
uint32_t set_occupancy_to_1_delay;
uint32_t ambient_luxlevel;
} state;
} sensor_status;
} bt_mesh_light_server_state_change_t;
typedef union {
struct {
uint16_t id;
} lc_property_get;
} bt_mesh_light_server_recv_get_msg_t;
typedef union {
struct {
bool op_en;
uint16_t lightness;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} lightness_set;
struct {
bool op_en;
uint16_t lightness;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} lightness_linear_set;
struct {
uint16_t lightness;
} lightness_default_set;
struct {
uint16_t range_min;
uint16_t range_max;
} lightness_range_set;
struct {
bool op_en;
uint16_t lightness;
uint16_t temperature;
int16_t delta_uv;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} ctl_set;
struct {
bool op_en;
uint16_t temperature;
int16_t delta_uv;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} ctl_temp_set;
struct {
uint16_t range_min;
uint16_t range_max;
} ctl_temp_range_set;
struct {
uint16_t lightness;
uint16_t temperature;
int16_t delta_uv;
} ctl_default_set;
struct {
bool op_en;
uint16_t lightness;
uint16_t hue;
uint16_t saturation;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} hsl_set;
struct {
bool op_en;
uint16_t hue;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} hsl_hue_set;
struct {
bool op_en;
uint16_t saturation;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} hsl_saturation_set;
struct {
uint16_t lightness;
uint16_t hue;
uint16_t saturation;
} hsl_default_set;
struct {
uint16_t hue_range_min;
uint16_t hue_range_max;
uint16_t sat_range_min;
uint16_t sat_range_max;
} hsl_range_set;
struct {
bool op_en;
uint16_t lightness;
uint16_t x;
uint16_t y;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} xyl_set;
struct {
uint16_t lightness;
uint16_t x;
uint16_t y;
} xyl_default_set;
struct {
uint16_t x_range_min;
uint16_t x_range_max;
uint16_t y_range_min;
uint16_t y_range_max;
} xyl_range_set;
struct {
uint8_t mode;
} lc_mode_set;
struct {
uint8_t mode;
} lc_om_set;
struct {
bool op_en;
uint8_t light_onoff;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} lc_light_onoff_set;
struct {
uint16_t id;
struct net_buf_simple *value;
} lc_property_set;
} bt_mesh_light_server_recv_set_msg_t;
typedef union {
struct {
struct net_buf_simple *data;
} sensor_status;
} bt_mesh_light_server_recv_status_msg_t;
void bt_mesh_light_server_lock(void);
void bt_mesh_light_server_unlock(void);
uint8_t *bt_mesh_get_lc_prop_value(struct bt_mesh_model *model, uint16_t prop_id);
void light_lightness_publish(struct bt_mesh_model *model, uint16_t opcode);
void light_ctl_publish(struct bt_mesh_model *model, uint16_t opcode);
void light_hsl_publish(struct bt_mesh_model *model, uint16_t opcode);
void light_xyl_publish(struct bt_mesh_model *model, uint16_t opcode);
void light_lc_publish(struct bt_mesh_model *model, uint16_t opcode);
#ifdef __cplusplus
}
#endif
#endif /* _LIGHTING_SERVER_H_ */

View File

@ -0,0 +1,246 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SENSOR_SERVER_H_
#define _SENSOR_SERVER_H_
#include "server_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Sensor Property ID related */
#define INVALID_SENSOR_PROPERTY_ID 0x0000
#define SENSOR_PROPERTY_ID_LEN 0x02
/* Sensor Descriptor state related */
#define SENSOR_DESCRIPTOR_LEN 0x08
#define SENSOR_UNSPECIFIED_POS_TOLERANCE 0x000
#define SENSOR_UNSPECIFIED_NEG_TOLERANCE 0x000
#define SENSOR_NOT_APPL_MEASURE_PERIOD 0x00
#define SENSOR_NOT_APPL_UPDATE_INTERVAL 0x00
/* Sensor Setting state related */
#define INVALID_SENSOR_SETTING_PROPERTY_ID 0x0000
#define SENSOR_SETTING_PROPERTY_ID_LEN 0x02
#define SENSOR_SETTING_ACCESS_LEN 0x01
#define SENSOR_SETTING_ACCESS_READ 0x01
#define SENSOR_SETTING_ACCESS_READ_WRITE 0x03
/* Sensor Cadence state related */
#define SENSOR_DIVISOR_TRIGGER_TYPE_LEN 0x01
#define SENSOR_STATUS_MIN_INTERVAL_LEN 0x01
#define SENSOR_PERIOD_DIVISOR_MAX_VALUE 15
#define SENSOR_STATUS_MIN_INTERVAL_MAX 26
#define SENSOR_STATUS_TRIGGER_TYPE_CHAR 0
#define SENSOR_STATUS_TRIGGER_TYPE_UINT16 1
#define SENSOR_STATUS_TRIGGER_UINT16_LEN 0x02
/* Sensor Data state related */
#define SENSOR_DATA_FORMAT_A 0x00
#define SENSOR_DATA_FORMAT_B 0x01
#define SENSOR_DATA_FORMAT_A_MPID_LEN 0x02
#define SENSOR_DATA_FORMAT_B_MPID_LEN 0x03
#define SENSOR_DATA_ZERO_LEN 0x7F
enum bt_mesh_sensor_sample_func {
UNSPECIFIED,
INSTANTANEOUS,
ARITHMETIC_MEAN,
RMS,
MAXIMUM,
MINIMUM,
ACCUMULATED,
COUNT,
};
struct sensor_descriptor {
uint32_t positive_tolerance : 12,
negative_tolerance : 12,
sample_function : 8;
uint8_t measure_period;
uint8_t update_interval;
};
struct sensor_setting {
uint16_t property_id;
uint8_t access;
/* Or use union to include all possible types */
struct net_buf_simple *raw;
};
struct sensor_cadence {
uint8_t period_divisor : 7,
trigger_type : 1;
struct net_buf_simple *trigger_delta_down;
struct net_buf_simple *trigger_delta_up;
uint8_t min_interval;
struct net_buf_simple *fast_cadence_low;
struct net_buf_simple *fast_cadence_high;
};
struct sensor_data {
/**
* Format A: The Length field is a 1-based uint4 value (valid range 0x00xF,
* representing range of 1 16).
* Format B: The Length field is a 1-based uint7 value (valid range 0x00x7F,
* representing range of 1 127). The value 0x7F represents a
* length of zero.
*/
uint8_t format : 1,
length : 7;
struct net_buf_simple *raw_value;
};
struct sensor_series_column {
struct net_buf_simple *raw_value_x;
struct net_buf_simple *column_width;
struct net_buf_simple *raw_value_y;
};
struct bt_mesh_sensor_state {
uint16_t sensor_property_id;
/* Constant throughout the lifetime of an element */
struct sensor_descriptor descriptor;
/* Multiple Sensor Setting states may be present for each sensor.
* The Sensor Setting Property ID values shall be unique for each
* Sensor Property ID that identifies a sensor within an element.
*/
const uint8_t setting_count;
struct sensor_setting *settings;
/* The Sensor Cadence state may be not supported by sensors based
* on device properties referencing "non-scalar characteristics"
* such as "histograms" or "composite characteristics".
*/
struct sensor_cadence *cadence;
struct sensor_data sensor_data;
/* Values measured by sensors may be organized as arrays (and
* represented as series of columns, such as histograms).
* 1. The Sensor Raw Value X field has a size and representation
* defined by the Sensor Property ID and represents the left
* corner of the column on the X axis.
* 2. The Sensor Column Width field has a size and representation
* defined by the Sensor Property ID and represents the width
* of the column on the X axis.
* 3. The Sensor Raw Value Y field has a size and representation
* defined by the Sensor Property ID and represents the height
* of the column on the Y axis.
* Note: Values outside the bins defined by a Sensor Property are
* not included. For example, if the histogram is defined as 3 bins
* representing “lamp operating hours in a given temperature range”
* and the bins are [40,60), [60, 80), and [80,100], then any hours
* outside that [40, 100] range would not be included.
*/
struct sensor_series_column series_column;
};
/* 1. Multiple instances of the Sensor states may be present within the
* same model, provided that each instance has a unique value of the
* Sensor Property ID to allow the instances to be differentiated.
* 2. Note: The number of sensors within a multisensor is limited by the
* size of the message payload for the Sensor Descriptor Status message.
* A single Sensor Descriptor may be sent using a single Unsegmented
* Access message. Using Segmentation and Reassembly (SAR), up to 38
* Sensor Descriptor states may be sent.
*/
struct bt_mesh_sensor_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
const uint8_t state_count;
struct bt_mesh_sensor_state *states;
};
struct bt_mesh_sensor_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
const uint8_t state_count;
struct bt_mesh_sensor_state *states;
};
typedef union {
struct {
uint16_t id;
uint8_t period_divisor : 7,
trigger_type : 1;
struct net_buf_simple *trigger_delta_down;
struct net_buf_simple *trigger_delta_up;
uint8_t min_interval;
struct net_buf_simple *fast_cadence_low;
struct net_buf_simple *fast_cadence_high;
} sensor_cadence_set;
struct {
uint16_t id;
uint16_t setting_id;
struct net_buf_simple *value;
} sensor_setting_set;
} bt_mesh_sensor_server_state_change_t;
typedef union {
struct {
bool op_en;
uint16_t id;
} sensor_descriptor_get;
struct {
uint16_t id;
} sensor_cadence_get;
struct {
uint16_t id;
} sensor_settings_get;
struct {
uint16_t id;
uint16_t setting_id;
} sensor_setting_get;
struct {
bool op_en;
uint16_t id;
} sensor_get;
struct {
uint16_t id;
struct net_buf_simple *raw_x;
} sensor_column_get;
struct {
bool op_en;
uint16_t id;
struct net_buf_simple *raw;
} sensor_series_get;
} bt_mesh_sensor_server_recv_get_msg_t;
typedef union {
struct {
uint16_t id;
struct net_buf_simple *cadence;
} sensor_cadence_set;
struct {
uint16_t id;
uint16_t setting_id;
struct net_buf_simple *raw;
} sensor_setting_set;
} bt_mesh_sensor_server_recv_set_msg_t;
#ifdef __cplusplus
}
#endif
#endif /* _SENSOR_SERVER_H_ */

View File

@ -0,0 +1,124 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _SERVER_COMMON_H_
#define _SERVER_COMMON_H_
#include <string.h>
#include <stdint.h>
#include "mesh_access.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_SERVER_RSP_MAX_LEN 384
#define BLE_MESH_SERVER_TRANS_MIC_SIZE 4
#define BLE_MESH_CHECK_SEND_STATUS(_func) do { \
int __status = (_func); \
if (__status) { \
BT_ERR("%s, Send failed, err %d", __func__, __status); \
} \
} while(0);
#define BLE_MESH_STATE_OFF 0x00
#define BLE_MESH_STATE_ON 0x01
#define BLE_MESH_STATE_RESTORE 0x02
/* Following 4 values are as per Mesh Model specification */
#define BLE_MESH_LIGHTNESS_MIN 0x0001
#define BLE_MESH_LIGHTNESS_MAX 0xFFFF
#define BLE_MESH_TEMPERATURE_MIN 0x0320
#define BLE_MESH_TEMPERATURE_MAX 0x4E20
#define BLE_MESH_TEMPERATURE_UNKNOWN 0xFFFF
/* Refer 7.2 of Mesh Model Specification */
#define BLE_MESH_RANGE_UPDATE_SUCCESS 0x00
#define BLE_MESH_CANNOT_SET_RANGE_MIN 0x01
#define BLE_MESH_CANNOT_SET_RANGE_MAX 0x02
#define BLE_MESH_UNKNOWN_REMAIN_TIME 0x3F
#define BLE_MESH_DEVICE_SPECIFIC_RESOLUTION 10
enum {
BLE_MESH_TRANS_TIMER_START, /* Proper transition timer has been started */
BLE_MESH_TRANS_FLAG_MAX,
};
struct bt_mesh_state_transition {
bool just_started;
uint8_t trans_time;
uint8_t remain_time;
uint8_t delay;
uint32_t quo_tt;
uint32_t counter;
uint32_t total_duration;
int64_t start_timestamp;
BLE_MESH_ATOMIC_DEFINE(flag, BLE_MESH_TRANS_FLAG_MAX);
struct k_delayed_work timer;
};
struct bt_mesh_last_msg_info {
uint8_t tid;
uint16_t src;
uint16_t dst;
int64_t timestamp;
};
#define BLE_MESH_SERVER_RSP_BY_APP 0
#define BLE_MESH_SERVER_AUTO_RSP 1
struct bt_mesh_server_rsp_ctrl {
/**
* @brief BLE Mesh Server Response Option
* 1. If get_auto_rsp is set to BLE_MESH_SERVER_RSP_BY_APP, then the response
* of Client Get messages need to be replied by the application;
* 2. If get_auto_rsp is set to BLE_MESH_SERVER_AUTO_RSP, then the response
* of Client Get messages will be replied by the server models;
* 3. If set_auto_rsp is set to BLE_MESH_SERVER_RSP_BY_APP, then the response
* of Client Set messages need to be replied by the application;
* 4. If set_auto_rsp is set to BLE_MESH_SERVER_AUTO_RSP, then the response
* of Client Set messages will be replied by the server models;
* 5. If status_auto_rsp is set to BLE_MESH_SERVER_RSP_BY_APP, then the response
* of Server Status messages need to be replied by the application;
* 6. If status_auto_rsp is set to BLE_MESH_SERVER_AUTO_RSP, then the response
* of Server status messages will be replied by the server models;
*/
uint8_t get_auto_rsp : 1, /* Response for Client Get messages */
set_auto_rsp : 1, /* Response for Client Set messages */
status_auto_rsp : 1; /* Response for Server Status messages */
};
uint8_t bt_mesh_get_default_trans_time(struct bt_mesh_model *model);
int bt_mesh_get_light_lc_trans_time(struct bt_mesh_model *model, uint8_t *trans_time);
int bt_mesh_server_get_optional(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf,
uint8_t *trans_time, uint8_t *delay,
bool *optional);
void bt_mesh_server_alloc_ctx(struct k_work *work);
void bt_mesh_server_free_ctx(struct k_work *work);
bool bt_mesh_is_server_recv_last_msg(struct bt_mesh_last_msg_info *last,
uint8_t tid, uint16_t src, uint16_t dst, int64_t *now);
void bt_mesh_server_update_last_msg(struct bt_mesh_last_msg_info *last,
uint8_t tid, uint16_t src, uint16_t dst, int64_t *now);
struct net_buf_simple *bt_mesh_server_get_pub_msg(struct bt_mesh_model *model, uint16_t msg_len);
#ifdef __cplusplus
}
#endif
#endif /* _SERVER_COMMON_H_ */

View File

@ -0,0 +1,108 @@
/* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models
*
* SPDX-FileCopyrightText: 2018 Vikrant More
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _STATE_BINDING_H_
#define _STATE_BINDING_H_
#include "mesh_access.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
GENERIC_ONOFF_STATE,
GENERIC_LEVEL_STATE,
GENERIC_ONPOWERUP_STATE,
GENERIC_POWER_ACTUAL_STATE,
LIGHT_LIGHTNESS_ACTUAL_STATE,
LIGHT_LIGHTNESS_LINEAR_STATE,
LIGHT_CTL_LIGHTNESS_STATE,
LIGHT_CTL_TEMP_DELTA_UV_STATE,
LIGHT_HSL_STATE,
LIGHT_HSL_LIGHTNESS_STATE,
LIGHT_HSL_HUE_STATE,
LIGHT_HSL_SATURATION_STATE,
LIGHT_XYL_LIGHTNESS_STATE,
LIGHT_LC_LIGHT_ONOFF_STATE,
BIND_STATE_MAX,
} bt_mesh_server_state_type_t;
typedef union {
struct {
uint8_t onoff;
} gen_onoff;
struct {
int16_t level;
} gen_level;
struct {
uint8_t onpowerup;
} gen_onpowerup;
struct {
uint16_t power;
} gen_power_actual;
struct {
uint16_t lightness;
} light_lightness_actual;
struct {
uint16_t lightness;
} light_lightness_linear;
struct {
uint16_t lightness;
} light_ctl_lightness;
struct {
uint16_t temperature;
int16_t delta_uv;
} light_ctl_temp_delta_uv;
struct {
uint16_t lightness;
uint16_t hue;
uint16_t saturation;
} light_hsl;
struct {
uint16_t lightness;
} light_hsl_lightness;
struct {
uint16_t hue;
} light_hsl_hue;
struct {
uint16_t saturation;
} light_hsl_saturation;
struct {
uint16_t lightness;
} light_xyl_lightness;
struct {
uint8_t onoff;
} light_lc_light_onoff;
} bt_mesh_server_state_value_t;
uint16_t bt_mesh_convert_lightness_actual_to_linear(uint16_t actual);
uint16_t bt_mesh_convert_lightness_linear_to_actual(uint16_t linear);
int16_t bt_mesh_convert_temperature_to_gen_level(uint16_t temp, uint16_t min, uint16_t max);
uint16_t bt_mesh_covert_gen_level_to_temperature(int16_t level, uint16_t min, uint16_t max);
int16_t bt_mesh_convert_hue_to_level(uint16_t hue);
uint16_t bt_mesh_convert_level_to_hue(int16_t level);
int16_t bt_mesh_convert_saturation_to_level(uint16_t saturation);
uint16_t bt_mesh_convert_level_to_saturation(int16_t level);
int bt_mesh_update_binding_state(struct bt_mesh_model *model,
bt_mesh_server_state_type_t type,
bt_mesh_server_state_value_t *value);
#ifdef __cplusplus
}
#endif
#endif /* _STATE_BINDING_H_ */

View File

@ -0,0 +1,100 @@
/* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models
*
* SPDX-FileCopyrightText: 2018 Vikrant More
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _STATE_TRANSITION_H_
#define _STATE_TRANSITION_H_
#include "server_common.h"
#include "generic_server.h"
#include "sensor_server.h"
#include "lighting_server.h"
#include "time_scene_server.h"
#ifdef __cplusplus
extern "C" {
#endif
void bt_mesh_server_calc_remain_time(struct bt_mesh_state_transition *transition);
/* APIs used to get server model transition time values */
void generic_onoff_tt_values(struct bt_mesh_gen_onoff_srv *srv,
uint8_t trans_time, uint8_t delay);
void generic_level_tt_values(struct bt_mesh_gen_level_srv *srv,
uint8_t trans_time, uint8_t delay);
void generic_power_level_tt_values(struct bt_mesh_gen_power_level_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_lightness_actual_tt_values(struct bt_mesh_light_lightness_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_lightness_linear_tt_values(struct bt_mesh_light_lightness_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_ctl_tt_values(struct bt_mesh_light_ctl_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_ctl_temp_tt_values(struct bt_mesh_light_ctl_temp_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_hsl_tt_values(struct bt_mesh_light_hsl_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_hsl_hue_tt_values(struct bt_mesh_light_hsl_hue_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_hsl_sat_tt_values(struct bt_mesh_light_hsl_sat_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_xyl_tt_values(struct bt_mesh_light_xyl_srv *srv,
uint8_t trans_time, uint8_t delay);
void light_lc_tt_values(struct bt_mesh_light_lc_srv *srv,
uint8_t trans_time, uint8_t delay);
void scene_tt_values(struct bt_mesh_scene_srv *srv, uint8_t trans_time, uint8_t delay);
/* Server model transition timer handlers */
void generic_onoff_work_handler(struct k_work *work);
void generic_level_work_handler(struct k_work *work);
void generic_power_level_work_handler(struct k_work *work);
void light_lightness_actual_work_handler(struct k_work *work);
void light_lightness_linear_work_handler(struct k_work *work);
void light_ctl_work_handler(struct k_work *work);
void light_ctl_temp_work_handler(struct k_work *work);
void light_hsl_work_handler(struct k_work *work);
void light_hsl_hue_work_handler(struct k_work *work);
void light_hsl_sat_work_handler(struct k_work *work);
void light_xyl_work_handler(struct k_work *work);
void light_lc_work_handler(struct k_work *work);
void scene_recall_work_handler(struct k_work *work);
void bt_mesh_server_stop_transition(struct bt_mesh_state_transition *transition);
void bt_mesh_server_start_transition(struct bt_mesh_state_transition *transition);
#ifdef __cplusplus
}
#endif
#endif /* _STATE_TRANSITION_H_ */

View File

@ -0,0 +1,384 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _TIME_SCENE_SERVER_H_
#define _TIME_SCENE_SERVER_H_
#include "server_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* 1. Mesh defines times based on International Atomic Time (TAI). The base
* representation of times is the number of seconds after 00:00:00 TAI
* on 2000-01-01 (that is, 1999-12-31 T23:59:28 UTC).
* 2. UTC: Coordinated Universal Time. For more information, please refer
* to https://time.is/zh/UTC
* 3. For the algorithm used for the transfer between TAI and UTC, please
* refer to Mesh Model Spec Section 5.1.1
*/
#define UNKNOWN_TAI_SECONDS 0x0000000000
#define UNKNOWN_TAI_ZONE_CHANGE 0x0000000000
#define UNKNOWN_TAI_DELTA_CHANGE 0x0000000000
#define TAI_UTC_DELTA_MAX_VALUE 0x7FFF
#define TAI_SECONDS_LEN 0x05
#define TAI_OF_ZONE_CHANGE_LEN 0x05
#define TAI_OF_DELTA_CHANGE_LEN 0x05
#define INVALID_SCENE_NUMBER 0x0000
#define SCENE_NUMBER_LEN 0x02
#define SCHEDULE_YEAR_ANY_YEAR 0x64
#define SCHEDULE_DAY_ANY_DAY 0x00
#define SCHEDULE_HOUR_ANY_HOUR 0x18
#define SCHEDULE_HOUR_ONCE_A_DAY 0x19
#define SCHEDULE_SEC_ANY_OF_HOUR 0x3C
#define SCHEDULE_SEC_EVERY_15_MIN 0x3D
#define SCHEDULE_SEC_EVERY_20_MIN 0x3E
#define SCHEDULE_SEC_ONCE_AN_HOUR 0x3F
#define SCHEDULE_SEC_ANY_OF_MIN 0x3C
#define SCHEDULE_SEC_EVERY_15_SEC 0x3D
#define SCHEDULE_SEC_EVERY_20_SEC 0x3E
#define SCHEDULE_SEC_ONCE_AN_MIN 0x3F
#define SCHEDULE_ACT_TURN_OFF 0x00
#define SCHEDULE_ACT_TURN_ON 0x01
#define SCHEDULE_ACT_SCENE_RECALL 0x02
#define SCHEDULE_ACT_NO_ACTION 0x0F
#define SCHEDULE_SCENE_NO_SCENE 0x0000
#define SCHEDULE_ENTRY_MAX_INDEX 0x0F
#define TIME_NONE 0x00
#define TIME_AUTHORITY 0x01
#define TIME_RELAY 0x02
#define TIME_CLINET 0x03
#define SCENE_SUCCESS 0x00
#define SCENE_REG_FULL 0x01
#define SCENE_NOT_FOUND 0x02
/**
* The Time state represents the present TAI time, the current TAI-UTC Delta
* and local time zone offset, and the next change to each of the latter
* (e.g., because of a switch from winter to summer time or an announced leap
* second). It consists of 10 fields with a total size of 183 bits.
*/
struct bt_mesh_time_state {
struct {
uint8_t tai_seconds[5];
uint8_t subsecond;
uint8_t uncertainty;
uint8_t time_zone_offset_curr;
uint8_t time_zone_offset_new;
uint8_t tai_zone_change[5];
uint16_t time_authority : 1,
tai_utc_delta_curr : 15;
uint16_t tai_utc_delta_new : 15;
uint8_t tai_delta_change[5];
} time;
uint8_t time_role;
};
struct bt_mesh_time_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_time_state *state;
};
struct bt_mesh_time_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_time_state *state;
};
struct scene_register {
uint16_t scene_number;
uint8_t scene_type; /* Indicate the type of scene value */
/**
* Scene value may use a union to represent later, the union contains
* structures of all the model states which can be stored in a scene.
*/
struct net_buf_simple *scene_value;
};
/**
* Scenes serve as memory banks for storage of states (e.g., a power level
* or a light level/color). Values of states of an element can be stored
* as a scene and can be recalled later from the scene memory.
*
* A scene is represented by a Scene Number, which is a 16-bit non-zero,
* mesh-wide value. (There can be a maximum of 65535 scenes in a mesh
* network.) The meaning of a scene, as well as the state storage container
* associated with it, are determined by a model.
*
* The Scenes state change may start numerous parallel model transitions.
* In that case, each individual model handles the transition internally.
*
* The scene transition is defined as a group of individual model transitions
* started by a Scene Recall operation. The scene transition is in progress
* when at least one transition from the group of individual model transitions
* is in progress.
*/
struct bt_mesh_scenes_state {
const uint16_t scene_count;
struct scene_register *scenes;
/**
* The Current Scene state is a 16-bit value that contains either the Scene
* Number of the currently active scene or a value of 0x0000 when no scene
* is active.
*
* When a Scene Store operation or a Scene Recall operation completes with
* success, the Current Scene state value shall be to the Scene Number used
* during that operation.
*
* When the Current Scene Number is deleted from a Scene Register state as a
* result of Scene Delete operation, the Current Scene state shall be set to
* 0x0000.
*
* When any of the element's state that is marked as “Stored with Scene” has
* changed not as a result of a Scene Recall operation, the value of the
* Current Scene state shall be set to 0x0000.
*
* When a scene transition is in progress, the value of the Current Scene
* state shall be set to 0x0000.
*/
uint16_t current_scene;
/**
* The Target Scene state is a 16-bit value that contains the target Scene
* Number when a scene transition is in progress.
*
* When the scene transition is in progress and the target Scene Number is
* deleted from a Scene Register state as a result of Scene Delete operation,
* the Target Scene state shall be set to 0x0000.
*
* When the scene transition is in progress and a new Scene Number is stored
* in the Scene Register as a result of Scene Store operation, the Target
* Scene state shall be set to the new Scene Number.
*
* When the scene transition is not in progress, the value of the Target Scene
* state shall be set to 0x0000.
*/
uint16_t target_scene;
/* Indicate the status code for the last operation */
uint8_t status_code;
/* Indicate if scene transition is in progress */
bool in_progress;
};
struct bt_mesh_scene_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_scenes_state *state;
struct bt_mesh_last_msg_info last;
struct bt_mesh_state_transition transition;
};
struct bt_mesh_scene_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_scenes_state *state;
};
struct schedule_register {
bool in_use;
uint64_t year : 7,
month : 12,
day : 5,
hour : 5,
minute : 6,
second : 6,
day_of_week : 7,
action : 4,
trans_time : 8;
uint16_t scene_number;
};
struct bt_mesh_scheduler_state {
const uint8_t schedule_count;
struct schedule_register *schedules; /* Up to 16 scheduled entries */
/**
* A recommended implementation of the Scheduler should calculate the
* value of the TAI Seconds of the next scheduled event and put it in
* a queue of scheduled events sorted by time.
*
* Every second, the first event in the queue is compared with the value
* of the Time state. The first event is executed if it is less than or
* equal to the Time state and then removed from the queue. After
* execution, the Repeat Flag shall be checked, and the next occurrence
* of the scheduled event is calculated and put in the queue.
*
* One second timeout value, and compare the first event in queue with the
* Time state. If it is satisfied, then execute the first event. Also the
* Repeat Flag need to be checked, if it is set then the event needs to
* be put into the end of queue.
*
* sys_slist_t event_queue;
*
* For each event_queue item, it can use the following struct:
* struct schedule_event {
* sys_snode_t node;
* uint8_t event_index;
* };
*
* Also we need a "struct k_delayed_work track_timer" which can be used to
* track the schedule timer and handle proper scheduled events.
*/
};
struct bt_mesh_scheduler_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_scheduler_state *state;
};
struct bt_mesh_scheduler_setup_srv {
struct bt_mesh_model *model;
struct bt_mesh_server_rsp_ctrl rsp_ctrl;
struct bt_mesh_scheduler_state *state;
};
typedef union {
struct {
uint8_t tai_seconds[5];
uint8_t subsecond;
uint8_t uncertainty;
uint16_t time_authority : 1;
uint16_t tai_utc_delta_curr : 15;
uint8_t time_zone_offset_curr;
} time_set;
struct {
uint8_t tai_seconds[5];
uint8_t subsecond;
uint8_t uncertainty;
uint16_t time_authority : 1;
uint16_t tai_utc_delta_curr : 15;
uint8_t time_zone_offset_curr;
} time_status;
struct {
uint8_t time_zone_offset_new;
uint8_t tai_zone_change[5];
} time_zone_set;
struct {
uint16_t tai_utc_delta_new : 15;
uint8_t tai_delta_change[5];
} tai_utc_delta_set;
struct {
uint8_t role;
} time_role_set;
struct {
uint16_t scene_number;
} scene_store;
struct {
uint16_t scene_number;
} scene_recall;
struct {
uint16_t scene_number;
} scene_delete;
struct {
uint64_t index : 4,
year : 7,
month : 12,
day : 5,
hour : 5,
minute : 6,
second : 6,
day_of_week : 7,
action : 4,
trans_time : 8;
uint16_t scene_number;
} scheduler_act_set;
} bt_mesh_time_scene_server_state_change_t;
typedef union {
struct {
uint8_t index;
} scheduler_act_get;
} bt_mesh_time_scene_server_recv_get_msg_t;
typedef union {
struct {
uint8_t tai_seconds[5];
uint8_t subsecond;
uint8_t uncertainty;
uint16_t time_authority : 1;
uint16_t tai_utc_delta : 15;
uint8_t time_zone_offset;
} time_set;
struct {
uint8_t time_zone_offset_new;
uint8_t tai_zone_change[5];
} time_zone_set;
struct {
uint16_t tai_utc_delta_new : 15;
uint16_t padding : 1;
uint8_t tai_delta_change[5];
} tai_utc_delta_set;
struct {
uint8_t time_role;
} time_role_set;
struct {
uint16_t scene_number;
} scene_store;
struct {
bool op_en;
uint16_t scene_number;
uint8_t tid;
uint8_t trans_time;
uint8_t delay;
} scene_recall;
struct {
uint16_t scene_number;
} scene_delete;
struct {
uint64_t index : 4,
year : 7,
month : 12,
day : 5,
hour : 5,
minute : 6,
second : 6,
day_of_week : 7,
action : 4,
trans_time : 8;
uint16_t scene_number;
} scheduler_act_set;
} bt_mesh_time_scene_server_recv_set_msg_t;
typedef union {
struct {
uint8_t tai_seconds[5];
uint8_t subsecond;
uint8_t uncertainty;
uint16_t time_authority : 1;
uint16_t tai_utc_delta : 15;
uint8_t time_zone_offset;
} time_status;
} bt_mesh_time_scene_server_recv_status_msg_t;
void bt_mesh_time_scene_server_lock(void);
void bt_mesh_time_scene_server_unlock(void);
void scene_publish(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, uint16_t opcode);
#ifdef __cplusplus
}
#endif
#endif /* _TIME_SCENE_SERVER_H_ */