Prvni ulozeni z chegewara githubu
This commit is contained in:
@@ -0,0 +1,433 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __ESP_BLUFI_API_H__
|
||||
#define __ESP_BLUFI_API_H__
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ESP_BLUFI_EVENT_INIT_FINISH = 0, /*<! When BLUFI init complete, this event happen */
|
||||
ESP_BLUFI_EVENT_DEINIT_FINISH, /*<! When BLUFI deinit complete, this event happen */
|
||||
ESP_BLUFI_EVENT_SET_WIFI_OPMODE, /*<! When Phone set ESP32 wifi operation mode(AP/STA/AP_STA), this event happen */
|
||||
ESP_BLUFI_EVENT_BLE_CONNECT, /*<! When Phone connect to ESP32 with BLE, this event happen */
|
||||
ESP_BLUFI_EVENT_BLE_DISCONNECT, /*<! When Phone disconnect with BLE, this event happen */
|
||||
ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP, /*<! When Phone request ESP32's STA connect to AP, this event happen */
|
||||
ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP, /*<! When Phone request ESP32's STA disconnect from AP, this event happen */
|
||||
ESP_BLUFI_EVENT_GET_WIFI_STATUS, /*<! When Phone get ESP32 wifi status, this event happen */
|
||||
ESP_BLUFI_EVENT_DEAUTHENTICATE_STA, /*<! When Phone deauthenticate sta from SOFTAP, this event happen */
|
||||
/* recv data */
|
||||
ESP_BLUFI_EVENT_RECV_STA_BSSID, /*<! When Phone send STA BSSID to ESP32 to connect, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_STA_SSID, /*<! When Phone send STA SSID to ESP32 to connect, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_STA_PASSWD, /*<! When Phone send STA PASSWORD to ESP32 to connect, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SOFTAP_SSID, /*<! When Phone send SOFTAP SSID to ESP32 to start SOFTAP, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD, /*<! When Phone send SOFTAP PASSWORD to ESP32 to start SOFTAP, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM, /*<! When Phone send SOFTAP max connection number to ESP32 to start SOFTAP, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE, /*<! When Phone send SOFTAP authentication mode to ESP32 to start SOFTAP, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL, /*<! When Phone send SOFTAP channel to ESP32 to start SOFTAP, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_USERNAME, /*<! When Phone send username to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_CA_CERT, /*<! When Phone send CA certificate to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_CLIENT_CERT, /*<! When Phone send Client certificate to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SERVER_CERT, /*<! When Phone send Server certificate to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY, /*<! When Phone send Client Private key to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY, /*<! When Phone send Server Private key to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_SLAVE_DISCONNECT_BLE, /*<! When Phone send Disconnect key to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_GET_WIFI_LIST, /*<! When Phone send get wifi list command to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_REPORT_ERROR, /*<! When Blufi report error, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_CUSTOM_DATA, /*<! When Phone send custom data to ESP32, this event happen */
|
||||
} esp_blufi_cb_event_t;
|
||||
|
||||
/// BLUFI config status
|
||||
typedef enum {
|
||||
ESP_BLUFI_STA_CONN_SUCCESS = 0x00,
|
||||
ESP_BLUFI_STA_CONN_FAIL = 0x01,
|
||||
} esp_blufi_sta_conn_state_t;
|
||||
|
||||
/// BLUFI init status
|
||||
typedef enum {
|
||||
ESP_BLUFI_INIT_OK = 0,
|
||||
ESP_BLUFI_INIT_FAILED,
|
||||
} esp_blufi_init_state_t;
|
||||
|
||||
/// BLUFI deinit status
|
||||
typedef enum {
|
||||
ESP_BLUFI_DEINIT_OK = 0,
|
||||
ESP_BLUFI_DEINIT_FAILED,
|
||||
} esp_blufi_deinit_state_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_BLUFI_SEQUENCE_ERROR = 0,
|
||||
ESP_BLUFI_CHECKSUM_ERROR,
|
||||
ESP_BLUFI_DECRYPT_ERROR,
|
||||
ESP_BLUFI_ENCRYPT_ERROR,
|
||||
ESP_BLUFI_INIT_SECURITY_ERROR,
|
||||
ESP_BLUFI_DH_MALLOC_ERROR,
|
||||
ESP_BLUFI_DH_PARAM_ERROR,
|
||||
ESP_BLUFI_READ_PARAM_ERROR,
|
||||
ESP_BLUFI_MAKE_PUBLIC_ERROR,
|
||||
ESP_BLUFI_DATA_FORMAT_ERROR,
|
||||
} esp_blufi_error_state_t;
|
||||
|
||||
/**
|
||||
* @brief BLUFI extra information structure
|
||||
*/
|
||||
typedef struct {
|
||||
//station
|
||||
uint8_t sta_bssid[6]; /*!< BSSID of station interface */
|
||||
bool sta_bssid_set; /*!< is BSSID of station interface set */
|
||||
uint8_t *sta_ssid; /*!< SSID of station interface */
|
||||
int sta_ssid_len; /*!< length of SSID of station interface */
|
||||
uint8_t *sta_passwd; /*!< password of station interface */
|
||||
int sta_passwd_len; /*!< length of password of station interface */
|
||||
uint8_t *softap_ssid; /*!< SSID of softap interface */
|
||||
int softap_ssid_len; /*!< length of SSID of softap interface */
|
||||
uint8_t *softap_passwd; /*!< password of station interface */
|
||||
int softap_passwd_len; /*!< length of password of station interface */
|
||||
uint8_t softap_authmode; /*!< authentication mode of softap interface */
|
||||
bool softap_authmode_set; /*!< is authentication mode of softap interface set */
|
||||
uint8_t softap_max_conn_num; /*!< max connection number of softap interface */
|
||||
bool softap_max_conn_num_set; /*!< is max connection number of softap interface set */
|
||||
uint8_t softap_channel; /*!< channel of softap interface */
|
||||
bool softap_channel_set; /*!< is channel of softap interface set */
|
||||
} esp_blufi_extra_info_t;
|
||||
|
||||
/** @brief Description of an WiFi AP */
|
||||
typedef struct {
|
||||
uint8_t ssid[33]; /**< SSID of AP */
|
||||
int8_t rssi; /**< signal strength of AP */
|
||||
} esp_blufi_ap_record_t;
|
||||
|
||||
/// Bluetooth address length
|
||||
#define ESP_BLUFI_BD_ADDR_LEN 6
|
||||
/// Bluetooth device address
|
||||
typedef uint8_t esp_blufi_bd_addr_t[ESP_BLUFI_BD_ADDR_LEN];
|
||||
|
||||
/**
|
||||
* @brief BLUFI callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_INIT_FINISH
|
||||
*/
|
||||
struct blufi_init_finish_evt_param {
|
||||
esp_blufi_init_state_t state; /*!< Initial status */
|
||||
} init_finish; /*!< Blufi callback param of ESP_BLUFI_EVENT_INIT_FINISH */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_DEINIT_FINISH
|
||||
*/
|
||||
struct blufi_deinit_finish_evt_param {
|
||||
esp_blufi_deinit_state_t state; /*!< De-initial status */
|
||||
} deinit_finish; /*!< Blufi callback param of ESP_BLUFI_EVENT_DEINIT_FINISH */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_SET_WIFI_MODE
|
||||
*/
|
||||
struct blufi_set_wifi_mode_evt_param {
|
||||
wifi_mode_t op_mode; /*!< Wifi operation mode */
|
||||
} wifi_mode; /*!< Blufi callback param of ESP_BLUFI_EVENT_INIT_FINISH */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_CONNECT
|
||||
*/
|
||||
struct blufi_connect_evt_param {
|
||||
esp_blufi_bd_addr_t remote_bda; /*!< Blufi Remote bluetooth device address */
|
||||
uint8_t server_if; /*!< server interface */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
} connect; /*!< Blufi callback param of ESP_BLUFI_EVENT_CONNECT */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_DISCONNECT
|
||||
*/
|
||||
struct blufi_disconnect_evt_param {
|
||||
esp_blufi_bd_addr_t remote_bda; /*!< Blufi Remote bluetooth device address */
|
||||
} disconnect; /*!< Blufi callback param of ESP_BLUFI_EVENT_DISCONNECT */
|
||||
|
||||
/* ESP_BLUFI_EVENT_REQ_WIFI_CONNECT */ /* No callback param */
|
||||
/* ESP_BLUFI_EVENT_REQ_WIFI_DISCONNECT */ /* No callback param */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_STA_BSSID
|
||||
*/
|
||||
struct blufi_recv_sta_bssid_evt_param {
|
||||
uint8_t bssid[6]; /*!< BSSID */
|
||||
} sta_bssid; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_STA_BSSID */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_STA_SSID
|
||||
*/
|
||||
struct blufi_recv_sta_ssid_evt_param {
|
||||
uint8_t *ssid; /*!< SSID */
|
||||
int ssid_len; /*!< SSID length */
|
||||
} sta_ssid; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_STA_SSID */
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_RECV_STA_PASSWD
|
||||
*/
|
||||
struct blufi_recv_sta_passwd_evt_param {
|
||||
uint8_t *passwd; /*!< Password */
|
||||
int passwd_len; /*!< Password Length */
|
||||
} sta_passwd; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_STA_PASSWD */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_SOFTAP_SSID
|
||||
*/
|
||||
struct blufi_recv_softap_ssid_evt_param {
|
||||
uint8_t *ssid; /*!< SSID */
|
||||
int ssid_len; /*!< SSID length */
|
||||
} softap_ssid; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_SSID */
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD
|
||||
*/
|
||||
struct blufi_recv_softap_passwd_evt_param {
|
||||
uint8_t *passwd; /*!< Password */
|
||||
int passwd_len; /*!< Password Length */
|
||||
} softap_passwd; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM
|
||||
*/
|
||||
struct blufi_recv_softap_max_conn_num_evt_param {
|
||||
int max_conn_num; /*!< SSID */
|
||||
} softap_max_conn_num; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM */
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE
|
||||
*/
|
||||
struct blufi_recv_softap_auth_mode_evt_param {
|
||||
wifi_auth_mode_t auth_mode; /*!< Authentication mode */
|
||||
} softap_auth_mode; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE */
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL
|
||||
*/
|
||||
struct blufi_recv_softap_channel_evt_param {
|
||||
uint8_t channel; /*!< Authentication mode */
|
||||
} softap_channel; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_USERNAME
|
||||
*/
|
||||
struct blufi_recv_username_evt_param {
|
||||
uint8_t *name; /*!< Username point */
|
||||
int name_len; /*!< Username length */
|
||||
} username; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_USERNAME*/
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_CA_CERT
|
||||
*/
|
||||
struct blufi_recv_ca_evt_param {
|
||||
uint8_t *cert; /*!< CA certificate point */
|
||||
int cert_len; /*!< CA certificate length */
|
||||
} ca; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CA_CERT */
|
||||
|
||||
/**
|
||||
* ESP_BLUFI_EVENT_RECV_CLIENT_CERT
|
||||
*/
|
||||
struct blufi_recv_client_cert_evt_param {
|
||||
uint8_t *cert; /*!< Client certificate point */
|
||||
int cert_len; /*!< Client certificate length */
|
||||
} client_cert; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CLIENT_CERT */
|
||||
|
||||
/**
|
||||
* ESP_BLUFI_EVENT_RECV_SERVER_CERT
|
||||
*/
|
||||
struct blufi_recv_server_cert_evt_param {
|
||||
uint8_t *cert; /*!< Client certificate point */
|
||||
int cert_len; /*!< Client certificate length */
|
||||
} server_cert; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SERVER_CERT */
|
||||
|
||||
/**
|
||||
* ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY
|
||||
*/
|
||||
struct blufi_recv_client_pkey_evt_param {
|
||||
uint8_t *pkey; /*!< Client Private Key point, if Client certificate not contain Key */
|
||||
int pkey_len; /*!< Client Private key length */
|
||||
} client_pkey; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY */
|
||||
/**
|
||||
* ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY
|
||||
*/
|
||||
struct blufi_recv_server_pkey_evt_param {
|
||||
uint8_t *pkey; /*!< Client Private Key point, if Client certificate not contain Key */
|
||||
int pkey_len; /*!< Client Private key length */
|
||||
} server_pkey; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY */
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_REPORT_ERROR
|
||||
*/
|
||||
struct blufi_get_error_evt_param {
|
||||
esp_blufi_error_state_t state; /*!< Blufi error state */
|
||||
} report_error; /*!< Blufi callback param of ESP_BLUFI_EVENT_REPORT_ERROR */
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_RECV_CUSTOM_DATA
|
||||
*/
|
||||
struct blufi_recv_custom_data_evt_param {
|
||||
uint8_t *data; /*!< Custom data */
|
||||
uint32_t data_len; /*!< Custom data Length */
|
||||
} custom_data; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CUSTOM_DATA */
|
||||
} esp_blufi_cb_param_t;
|
||||
|
||||
/**
|
||||
* @brief BLUFI event callback function type
|
||||
* @param event : Event type
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_blufi_event_cb_t)(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param);
|
||||
|
||||
/* security function declare */
|
||||
|
||||
/**
|
||||
* @brief BLUFI negotiate data handler
|
||||
* @param data : data from phone
|
||||
* @param len : length of data from phone
|
||||
* @param output_data : data want to send to phone
|
||||
* @param output_len : length of data want to send to phone
|
||||
* @param need_free : output reporting if memory needs to be freed or not *
|
||||
*/
|
||||
typedef void (*esp_blufi_negotiate_data_handler_t)(uint8_t *data, int len, uint8_t **output_data, int *output_len, bool *need_free);
|
||||
|
||||
/**
|
||||
* @brief BLUFI encrypt the data after negotiate a share key
|
||||
* @param iv8 : initial vector(8bit), normally, blufi core will input packet sequence number
|
||||
* @param crypt_data : plain text and encrypted data, the encrypt function must support autochthonous encrypt
|
||||
* @param crypt_len : length of plain text
|
||||
* @return Nonnegative number is encrypted length, if error, return negative number;
|
||||
*/
|
||||
typedef int (* esp_blufi_encrypt_func_t)(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
|
||||
|
||||
/**
|
||||
* @brief BLUFI decrypt the data after negotiate a share key
|
||||
* @param iv8 : initial vector(8bit), normally, blufi core will input packet sequence number
|
||||
* @param crypt_data : encrypted data and plain text, the encrypt function must support autochthonous decrypt
|
||||
* @param crypt_len : length of encrypted text
|
||||
* @return Nonnegative number is decrypted length, if error, return negative number;
|
||||
*/
|
||||
typedef int (* esp_blufi_decrypt_func_t)(uint8_t iv8, uint8_t *crypt_data, int crypt_len);
|
||||
|
||||
/**
|
||||
* @brief BLUFI checksum
|
||||
* @param iv8 : initial vector(8bit), normally, blufi core will input packet sequence number
|
||||
* @param data : data need to checksum
|
||||
* @param len : length of data
|
||||
*/
|
||||
typedef uint16_t (*esp_blufi_checksum_func_t)(uint8_t iv8, uint8_t *data, int len);
|
||||
|
||||
/**
|
||||
* @brief BLUFI callback functions type
|
||||
*/
|
||||
typedef struct {
|
||||
esp_blufi_event_cb_t event_cb; /*!< BLUFI event callback */
|
||||
esp_blufi_negotiate_data_handler_t negotiate_data_handler; /*!< BLUFI negotiate data function for negotiate share key */
|
||||
esp_blufi_encrypt_func_t encrypt_func; /*!< BLUFI encrypt data function with share key generated by negotiate_data_handler */
|
||||
esp_blufi_decrypt_func_t decrypt_func; /*!< BLUFI decrypt data function with share key generated by negotiate_data_handler */
|
||||
esp_blufi_checksum_func_t checksum_func; /*!< BLUFI check sum function (FCS) */
|
||||
} esp_blufi_callbacks_t;
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to receive blufi callback event
|
||||
*
|
||||
* @param[in] callbacks: callback functions
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_register_callbacks(esp_blufi_callbacks_t *callbacks);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to initialize blufi_profile
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_profile_init(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to de-initialize blufi_profile
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_profile_deinit(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to send wifi connection report
|
||||
* @param opmode : wifi opmode
|
||||
* @param sta_conn_state : station is already in connection or not
|
||||
* @param softap_conn_num : softap connection number
|
||||
* @param extra_info : extra information, such as sta_ssid, softap_ssid and etc.
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_wifi_conn_report(wifi_mode_t opmode, esp_blufi_sta_conn_state_t sta_conn_state, uint8_t softap_conn_num, esp_blufi_extra_info_t *extra_info);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to send wifi list
|
||||
* @param apCount : wifi list count
|
||||
* @param list : wifi list
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_wifi_list(uint16_t apCount, esp_blufi_ap_record_t *list);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Get BLUFI profile version
|
||||
*
|
||||
* @return Most 8bit significant is Great version, Least 8bit is Sub version
|
||||
*
|
||||
*/
|
||||
uint16_t esp_blufi_get_version(void);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to send blufi error information
|
||||
* @param state : error state
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state);
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to custom data
|
||||
* @param data : custom data value
|
||||
* @param data_len : the length of custom data
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_custom_data(uint8_t *data, uint32_t data_len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLUFI_API_ */
|
||||
@@ -0,0 +1,202 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __BLUFI_INT_H__
|
||||
#define __BLUFI_INT_H__
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "esp_blufi_api.h"
|
||||
#if (BLUFI_INCLUDED == TRUE)
|
||||
|
||||
#define BTC_BLUFI_GREAT_VER 0x01 //Version + Subversion
|
||||
#define BTC_BLUFI_SUB_VER 0x02 //Version + Subversion
|
||||
#define BTC_BLUFI_VERSION ((BTC_BLUFI_GREAT_VER<<8)|BTC_BLUFI_SUB_VER) //Version + Subversion
|
||||
|
||||
typedef UINT8 tGATT_IF;
|
||||
/* service engine control block */
|
||||
typedef struct {
|
||||
/* Protocol reference */
|
||||
tGATT_IF gatt_if;
|
||||
UINT8 srvc_inst;
|
||||
UINT16 handle_srvc;
|
||||
UINT16 handle_char_p2e;
|
||||
UINT16 handle_char_e2p;
|
||||
UINT16 handle_descr_e2p;
|
||||
UINT16 conn_id;
|
||||
BOOLEAN is_connected;
|
||||
BD_ADDR remote_bda;
|
||||
UINT32 trans_id;
|
||||
UINT8 congest;
|
||||
UINT16 frag_size;
|
||||
#define BLUFI_PREPAIR_BUF_MAX_SIZE 1024
|
||||
uint8_t *prepare_buf;
|
||||
int prepare_len;
|
||||
/* Control reference */
|
||||
esp_blufi_callbacks_t *cbs;
|
||||
BOOLEAN enabled;
|
||||
uint8_t send_seq;
|
||||
uint8_t recv_seq;
|
||||
uint8_t sec_mode;
|
||||
uint8_t *aggr_buf;
|
||||
uint16_t total_len;
|
||||
uint16_t offset;
|
||||
} tBLUFI_ENV;
|
||||
|
||||
/* BLUFI protocol */
|
||||
struct blufi_hdr{
|
||||
uint8_t type;
|
||||
uint8_t fc;
|
||||
uint8_t seq;
|
||||
uint8_t data_len;
|
||||
uint8_t data[0];
|
||||
};
|
||||
typedef struct blufi_hdr blufi_hd_t;
|
||||
|
||||
struct blufi_frag_hdr {
|
||||
uint8_t type;
|
||||
uint8_t fc;
|
||||
uint8_t seq;
|
||||
uint8_t data_len;
|
||||
uint16_t total_len;
|
||||
uint8_t content[0];
|
||||
};
|
||||
typedef struct blufi_frag_hdr blufi_frag_hdr_t;
|
||||
|
||||
#if GATT_DYNAMIC_MEMORY == FALSE
|
||||
extern tBLUFI_ENV blufi_env;
|
||||
#else
|
||||
extern tBLUFI_ENV *blufi_env_ptr;
|
||||
#define blufi_env (*blufi_env_ptr)
|
||||
#endif
|
||||
|
||||
#define BLUFI_DATA_SEC_MODE_CHECK_MASK 0x01
|
||||
#define BLUFI_DATA_SEC_MODE_ENC_MASK 0x02
|
||||
#define BLUFI_CTRL_SEC_MODE_CHECK_MASK 0x10
|
||||
#define BLUFI_CTRL_SEC_MODE_ENC_MASK 0x20
|
||||
#define BLUFI_MAX_DATA_LEN 255
|
||||
|
||||
// packet type
|
||||
#define BLUFI_TYPE_MASK 0x03
|
||||
#define BLUFI_TYPE_SHIFT 0
|
||||
#define BLUFI_SUBTYPE_MASK 0xFC
|
||||
#define BLUFI_SUBTYPE_SHIFT 2
|
||||
|
||||
#define BLUFI_GET_TYPE(type) ((type) & BLUFI_TYPE_MASK)
|
||||
#define BLUFI_GET_SUBTYPE(type) (((type) & BLUFI_SUBTYPE_MASK) >>BLUFI_SUBTYPE_SHIFT)
|
||||
#define BLUFI_BUILD_TYPE(type, subtype) (((type) & BLUFI_TYPE_MASK) | ((subtype)<<BLUFI_SUBTYPE_SHIFT))
|
||||
|
||||
#define BLUFI_TYPE_CTRL 0x0
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_ACK 0x00
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_SET_SEC_MODE 0x01
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE 0x02
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP 0x03
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP 0x04
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS 0x05
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA 0x06
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION 0x07
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_DISCONNECT_BLE 0x08
|
||||
#define BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_LIST 0x09
|
||||
|
||||
#define BLUFI_TYPE_DATA 0x1
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_NEG 0x00
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID 0x01
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_STA_SSID 0x02
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD 0x03
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID 0x04
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD 0x05
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM 0x06
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE 0x07
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL 0x08
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_USERNAME 0x09
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_CA 0x0a
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT 0x0b
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT 0x0c
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY 0x0d
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY 0x0e
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_WIFI_REP 0x0f
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_REPLY_VERSION 0x10
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_WIFI_LIST 0x11
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_ERROR_INFO 0x12
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA 0x13
|
||||
#define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL)
|
||||
#define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA)
|
||||
|
||||
#define BLUFI_TYPE_IS_CTRL_ACK(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_ACK)
|
||||
#define BLUFI_TYPE_IS_CTRL_START_NEG(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_START_NEG)
|
||||
#define BLUFI_TYPE_IS_CTRL_STOP_NEG(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_STOP_NEG)
|
||||
#define BLUFI_TYPE_IS_CTRL_SET_WIFI_OPMODE(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_SET_WIFI_OPMODE)
|
||||
#define BLUFI_TYPE_IS_CTRL_CONN_WIFI(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_CONN_TO_AP)
|
||||
#define BLUFI_TYPE_IS_CTRL_DISCONN_WIFI(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_DISCONN_FROM_AP)
|
||||
#define BLUFI_TYPE_IS_CTRL_GET_WIFI_STATUS(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_GET_WIFI_STATUS)
|
||||
#define BLUFI_TYPE_IS_CTRL_DEAUTHENTICATE_STA(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_DEAUTHENTICATE_STA)
|
||||
#define BLUFI_TYPE_IS_CTRL_GET_VERSION(type) (BLUFI_TYPE_IS_CTRL((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_CTRL_SUBTYPE_GET_VERSION)
|
||||
|
||||
#define BLUFI_TYPE_IS_DATA_NEG(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_NEG)
|
||||
#define BLUFI_TYPE_IS_DATA_STA_BSSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_BSSID)
|
||||
#define BLUFI_TYPE_IS_DATA_STA_SSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_SSID)
|
||||
#define BLUFI_TYPE_IS_DATA_STA_PASSWD(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_STA_PASSWD)
|
||||
#define BLUFI_TYPE_IS_DATA_SOFTAP_SSID(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_SSID)
|
||||
#define BLUFI_TYPE_IS_DATA_SOFTAP_PASSWD(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_PASSWD)
|
||||
#define BLUFI_TYPE_IS_DATA_SOFTAP_MAX_CONN_NUM(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_MAX_CONN_NUM)
|
||||
#define BLUFI_TYPE_IS_DATA_SOFTAP_AUTH_MODE(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_AUTH_MODE)
|
||||
#define BLUFI_TYPE_IS_DATA_SOFTAP_CHANNEL(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SOFTAP_CHANNEL)
|
||||
#define BLUFI_TYPE_IS_DATA_USERNAME(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_USERNAME)
|
||||
#define BLUFI_TYPE_IS_DATA_CA(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CA)
|
||||
#define BLUFI_TYPE_IS_DATA_CLEINT_CERT(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CLIENT_CERT)
|
||||
#define BLUFI_TYPE_IS_DATA_SERVER_CERT(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SERVER_CERT)
|
||||
#define BLUFI_TYPE_IS_DATA_CLIENT_PRIV_KEY(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_CLIENT_PRIV_KEY)
|
||||
#define BLUFI_TYPE_IS_DATA_SERVER_PRIV_KEY(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_SERVER_PRIV_KEY)
|
||||
#define BLUFI_TYPE_IS_DATA_ERROR_INFO(type) (BLUFI_TYPE_IS_DATA((type)) && BLUFI_GET_SUBTYPE((type)) == BLUFI_TYPE_DATA_SUBTYPE_ERROR_INFO)
|
||||
|
||||
// packet frame control
|
||||
#define BLUFI_FC_ENC_MASK 0x01
|
||||
#define BLUFI_FC_CHECK_MASK 0x02
|
||||
#define BLUFI_FC_DIR_MASK 0x04
|
||||
#define BLUFI_FC_REQ_ACK_MASK 0x08
|
||||
#define BLUFI_FC_FRAG_MASK 0x10
|
||||
|
||||
#define BLUFI_FC_ENC 0x01
|
||||
#define BLUFI_FC_CHECK 0x02
|
||||
#define BLUFI_FC_DIR_P2E 0x00
|
||||
#define BLUFI_FC_DIR_E2P 0x04
|
||||
#define BLUFI_FC_REQ_ACK 0x08
|
||||
#define BLUFI_FC_FRAG 0x10
|
||||
|
||||
#define BLUFI_FC_IS_ENC(fc) ((fc) & BLUFI_FC_ENC_MASK)
|
||||
#define BLUFI_FC_IS_CHECK(fc) ((fc) & BLUFI_FC_CHECK_MASK)
|
||||
#define BLUFI_FC_IS_DIR_P2E(fc) ((fc) & BLUFI_FC_DIR_P2E_MASK)
|
||||
#define BLUFI_FC_IS_DIR_E2P(fc) (!((fc) & BLUFI_DIR_P2E_MASK))
|
||||
#define BLUFI_FC_IS_REQ_ACK(fc) ((fc) & BLUFI_FC_REQ_ACK_MASK)
|
||||
#define BLUFI_FC_IS_FRAG(fc) ((fc) & BLUFI_FC_FRAG_MASK)
|
||||
|
||||
/* default GATT MTU size over LE link
|
||||
*/
|
||||
#define GATT_DEF_BLE_MTU_SIZE 23
|
||||
/* BLUFI HEADER + TOTAL(REMAIN) LENGTH + CRC + L2CAP RESERVED */
|
||||
#define BLUFI_MTU_RESERVED_SIZE (sizeof(struct blufi_hdr) + 2 + 2 + 3)
|
||||
#define BLUFI_FRAG_DATA_DEFAULT_LEN (GATT_DEF_BLE_MTU_SIZE - BLUFI_MTU_RESERVED_SIZE)
|
||||
|
||||
//function declare
|
||||
void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len);
|
||||
|
||||
void btc_blufi_send_encap(uint8_t type, uint8_t *data, int data_len);
|
||||
|
||||
void btc_blufi_set_callbacks(esp_blufi_callbacks_t *callbacks);
|
||||
|
||||
void btc_blufi_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_blufi_cb_deep_free(btc_msg_t *msg);
|
||||
|
||||
#endif /* __BLUFI_INT_H__ */
|
||||
#endif ///BLUFI_INCLUDED == TRUE
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef __ESP_BLUFI_H__
|
||||
#define __ESP_BLUFI_H__
|
||||
|
||||
#include "esp_blufi_api.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "nimble/ble.h"
|
||||
#include "modlog/modlog.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_gap_ble_api.h"
|
||||
#endif
|
||||
|
||||
#define BLUFI_APP_UUID 0xFFFF
|
||||
#define BLUFI_DEVICE_NAME "BLUFI_DEVICE"
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
struct ble_hs_cfg;
|
||||
struct ble_gatt_register_ctxt;
|
||||
struct gatt_value {
|
||||
struct os_mbuf *buf;
|
||||
uint16_t val_handle;
|
||||
uint8_t type;
|
||||
void *ptr;
|
||||
};
|
||||
#define SERVER_MAX_VALUES 3
|
||||
#define MAX_VAL_SIZE 512
|
||||
extern struct gatt_value gatt_values[SERVER_MAX_VALUES];
|
||||
/* GATT server callback */
|
||||
void esp_blufi_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
|
||||
|
||||
/* Initialise gatt server */
|
||||
int esp_blufi_gatt_svr_init(void);
|
||||
void esp_blufi_btc_init(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
/**
|
||||
* @brief Close a connection a remote device.
|
||||
*
|
||||
* @param[in] gatts_if: GATT server access interface
|
||||
* @param[in] conn_id: connection ID to be closed.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_close(uint8_t gatts_if, uint16_t conn_id);
|
||||
void esp_blufi_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
|
||||
#endif
|
||||
|
||||
/* Initialise blufi profile */
|
||||
uint8_t esp_blufi_init(void);
|
||||
|
||||
/* start advertising */
|
||||
void bleprph_advertise(void);
|
||||
|
||||
/* send notifications */
|
||||
void esp_blufi_send_notify(void *arg);
|
||||
|
||||
/* Deinitialise blufi */
|
||||
void esp_blufi_deinit(void);
|
||||
/* disconnect */
|
||||
void esp_blufi_disconnect(void);
|
||||
|
||||
/* Stop advertisement */
|
||||
void esp_blufi_adv_stop(void);
|
||||
|
||||
/* Start advertisement */
|
||||
void esp_blufi_adv_start(void);
|
||||
|
||||
void esp_blufi_send_encap(void *arg);
|
||||
|
||||
#endif/* _ESP_BLUFI_ */
|
||||
@@ -0,0 +1,111 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __BTC_BLUFI_PRF_H__
|
||||
#define __BTC_BLUFI_PRF_H__
|
||||
|
||||
#include "blufi_int.h"
|
||||
#include "btc/btc_task.h"
|
||||
#include "esp_blufi_api.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "stack/gatt_api.h"
|
||||
#define ESP_BLUFI_ERROR GATT_ERROR
|
||||
#define ESP_BLUFI_SUCCESS GATT_SUCCESS
|
||||
#else
|
||||
#define ESP_BLUFI_ERROR 0x85
|
||||
#define ESP_BLUFI_SUCCESS 0x00
|
||||
#endif
|
||||
|
||||
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||
|
||||
#define GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 /* Client Characteristic Configuration */
|
||||
//define the blufi serivce uuid
|
||||
#define BLUFI_SERVICE_UUID 0xFFFF
|
||||
//define the blufi Char uuid (PHONE to ESP32)
|
||||
#define BLUFI_CHAR_P2E_UUID 0xFF01
|
||||
//define the blufi Char uuid (ESP32 to PHONE)
|
||||
#define BLUFI_CHAR_E2P_UUID 0xFF02
|
||||
//define the blufi Descriptor uuid (ESP32 to PHONE)
|
||||
#define BLUFI_DESCR_E2P_UUID GATT_UUID_CHAR_CLIENT_CONFIG
|
||||
//define the blufi APP ID
|
||||
#define BLUFI_APP_UUID 0xFFFF
|
||||
|
||||
#define BLUFI_HDL_NUM 6
|
||||
|
||||
struct pkt_info{
|
||||
uint8_t *pkt;
|
||||
int pkt_len;
|
||||
};
|
||||
|
||||
static const tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}};
|
||||
static const tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}};
|
||||
static const tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}};
|
||||
static const tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}};
|
||||
static const tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
|
||||
|
||||
typedef enum {
|
||||
BTC_BLUFI_ACT_INIT = 0,
|
||||
BTC_BLUFI_ACT_DEINIT,
|
||||
BTC_BLUFI_ACT_SEND_CFG_REPORT,
|
||||
BTC_BLUFI_ACT_SEND_WIFI_LIST,
|
||||
BTC_BLUFI_ACT_SEND_ERR_INFO,
|
||||
BTC_BLUFI_ACT_SEND_CUSTOM_DATA,
|
||||
} btc_blufi_act_t;
|
||||
|
||||
typedef union {
|
||||
struct blufi_cfg_report {
|
||||
wifi_mode_t opmode;
|
||||
esp_blufi_sta_conn_state_t sta_conn_state;
|
||||
uint8_t softap_conn_num;
|
||||
esp_blufi_extra_info_t *extra_info;
|
||||
int extra_info_len;
|
||||
} wifi_conn_report;
|
||||
/*
|
||||
BTC_BLUFI_ACT_SEND_WIFI_LIST
|
||||
*/
|
||||
struct blufi_wifi_list {
|
||||
uint16_t apCount;
|
||||
esp_blufi_ap_record_t *list;
|
||||
} wifi_list;
|
||||
/*
|
||||
BTC_BLUFI_ACT_SEND_ERR_INFO
|
||||
*/
|
||||
struct blufi_error_infor {
|
||||
esp_blufi_error_state_t state;
|
||||
} blufi_err_infor;
|
||||
/*
|
||||
BTC_BLUFI_ACT_SEND_CUSTOM_DATA
|
||||
*/
|
||||
struct blufi_custom_data {
|
||||
uint8_t *data;
|
||||
uint32_t data_len;
|
||||
} custom_data;
|
||||
} btc_blufi_args_t;
|
||||
|
||||
void btc_blufi_cb_to_app(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param);
|
||||
void btc_blufi_cb_handler(btc_msg_t *msg);
|
||||
void btc_blufi_call_handler(btc_msg_t *msg);
|
||||
void btc_blufi_set_callbacks(esp_blufi_callbacks_t *callbacks);
|
||||
|
||||
void btc_blufi_recv_handler(uint8_t *data, int len);
|
||||
void btc_blufi_send_notify(uint8_t *pkt, int pkt_len);
|
||||
void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
void btc_blufi_call_deep_free(btc_msg_t *msg);
|
||||
|
||||
uint16_t btc_blufi_get_version(void);
|
||||
|
||||
#endif /* __BTC_BLUFI_PRF_H__ */
|
||||
84
tools/sdk/esp32/include/bt/common/osi/include/osi/alarm.h
Normal file
84
tools/sdk/esp32/include/bt/common/osi/include/osi/alarm.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _ALARM_H_
|
||||
#define _ALARM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_timer.h"
|
||||
|
||||
typedef struct alarm_t osi_alarm_t;
|
||||
typedef uint64_t period_ms_t;
|
||||
typedef esp_timer_cb_t osi_alarm_callback_t;
|
||||
|
||||
typedef enum {
|
||||
OSI_ALARM_ERR_PASS = 0,
|
||||
OSI_ALARM_ERR_FAIL = -1,
|
||||
OSI_ALARM_ERR_INVALID_ARG = -2,
|
||||
OSI_ALARM_ERR_INVALID_STATE = -3,
|
||||
} osi_alarm_err_t;
|
||||
|
||||
#define ALARM_CBS_NUM 50
|
||||
#define ALARM_ID_BASE 1000
|
||||
|
||||
int osi_alarm_create_mux(void);
|
||||
int osi_alarm_delete_mux(void);
|
||||
void osi_alarm_init(void);
|
||||
void osi_alarm_deinit(void);
|
||||
|
||||
// Creates a new alarm object. The returned object must be freed by calling
|
||||
// |alarm_free|. Returns NULL on failure.
|
||||
osi_alarm_t *osi_alarm_new(const char *alarm_name, osi_alarm_callback_t callback, void *data, period_ms_t timer_expire);
|
||||
|
||||
// Frees an alarm object created by |alarm_new|. |alarm| may be NULL. If the
|
||||
// alarm is pending, it will be cancelled. It is not safe to call |alarm_free|
|
||||
// from inside the callback of |alarm|.
|
||||
void osi_alarm_free(osi_alarm_t *alarm);
|
||||
|
||||
// Sets an alarm to fire |cb| after the given |deadline|. Note that |deadline| is the
|
||||
// number of milliseconds relative to the current time. |data| is a context variable
|
||||
// for the callback and may be NULL. |cb| will be called back in the context of an
|
||||
// unspecified thread (i.e. it will not be called back in the same thread as the caller).
|
||||
// |alarm| and |cb| may not be NULL.
|
||||
osi_alarm_err_t osi_alarm_set(osi_alarm_t *alarm, period_ms_t timeout);
|
||||
|
||||
// Sets an periodic alarm to fire |cb| each given |period|.
|
||||
osi_alarm_err_t osi_alarm_set_periodic(osi_alarm_t *alarm, period_ms_t period);
|
||||
|
||||
// This function cancels the |alarm| if it was previously set. When this call
|
||||
// returns, the caller has a guarantee that the callback is not in progress and
|
||||
// will not be called if it hasn't already been called. This function is idempotent.
|
||||
// |alarm| may not be NULL.
|
||||
osi_alarm_err_t osi_alarm_cancel(osi_alarm_t *alarm);
|
||||
|
||||
// Figure out how much time until next expiration.
|
||||
// Returns 0 if not armed. |alarm| may not be NULL.
|
||||
// only for oneshot alarm, not for periodic alarm
|
||||
// TODO: Remove this function once PM timers can be re-factored
|
||||
period_ms_t osi_alarm_get_remaining_ms(const osi_alarm_t *alarm);
|
||||
|
||||
// Alarm-related state cleanup
|
||||
//void alarm_cleanup(void);
|
||||
|
||||
uint32_t osi_time_get_os_boottime_ms(void);
|
||||
|
||||
// This function returns whether the given |alarm| is active or not.
|
||||
// Return true if active, false otherwise.
|
||||
bool osi_alarm_is_active(osi_alarm_t *alarm);
|
||||
|
||||
#endif /*_ALARM_H_*/
|
||||
145
tools/sdk/esp32/include/bt/common/osi/include/osi/allocator.h
Normal file
145
tools/sdk/esp32/include/bt/common/osi/include/osi/allocator.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _ALLOCATOR_H_
|
||||
#define _ALLOCATOR_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
char *osi_strdup(const char *str);
|
||||
|
||||
void *osi_malloc_func(size_t size);
|
||||
void *osi_calloc_func(size_t size);
|
||||
void osi_free_func(void *ptr);
|
||||
|
||||
#if HEAP_MEMORY_DEBUG
|
||||
|
||||
void osi_mem_dbg_init(void);
|
||||
void osi_mem_dbg_record(void *p, int size, const char *func, int line);
|
||||
void osi_mem_dbg_clean(void *p, const char *func, int line);
|
||||
void osi_mem_dbg_show(void);
|
||||
uint32_t osi_mem_dbg_get_max_size(void);
|
||||
uint32_t osi_mem_dbg_get_current_size(void);
|
||||
void osi_men_dbg_set_section_start(uint8_t index);
|
||||
void osi_men_dbg_set_section_end(uint8_t index);
|
||||
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
|
||||
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
|
||||
#define osi_malloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = heap_caps_malloc_prefer(size, 2, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#define osi_calloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = heap_caps_calloc_prefer(1, size, 2, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#else
|
||||
|
||||
#define osi_malloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = malloc((size)); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#define osi_calloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = calloc(1, (size)); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
|
||||
|
||||
|
||||
#if 0
|
||||
#define osi_malloc(size) \
|
||||
do { \
|
||||
void *p; \
|
||||
\
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \
|
||||
p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
|
||||
#else \
|
||||
p = malloc((size)); \
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
}while(0)
|
||||
|
||||
#define osi_calloc(size) \
|
||||
do { \
|
||||
void *p; \
|
||||
\
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST \
|
||||
p = heap_caps_calloc_prefer(1, size, 2, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
|
||||
#else \
|
||||
p = calloc(1, (size)); \
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */ \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#define osi_free(ptr) \
|
||||
do { \
|
||||
void *tmp_point = (void *)(ptr); \
|
||||
osi_mem_dbg_clean(tmp_point, __func__, __LINE__); \
|
||||
free(tmp_point); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
|
||||
#define osi_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#define osi_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#else
|
||||
#define osi_malloc(size) malloc((size))
|
||||
#define osi_calloc(size) calloc(1, (size))
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
|
||||
#define osi_free(p) free((p))
|
||||
|
||||
#endif /* HEAP_MEMORY_DEBUG */
|
||||
|
||||
#define FREE_AND_RESET(a) \
|
||||
do { \
|
||||
if (a) { \
|
||||
osi_free(a); \
|
||||
a = NULL; \
|
||||
} \
|
||||
}while (0)
|
||||
|
||||
|
||||
#endif /* _ALLOCATOR_H_ */
|
||||
59
tools/sdk/esp32/include/bt/common/osi/include/osi/buffer.h
Normal file
59
tools/sdk/esp32/include/bt/common/osi/include/osi/buffer.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _BUFFER_H_
|
||||
#define _BUFFER_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct buffer_t buffer_t;
|
||||
|
||||
// Returns a new buffer of |size| bytes. Returns NULL if a buffer could not be
|
||||
// allocated. |size| must be non-zero. The caller must release this buffer with
|
||||
// |buffer_free|.
|
||||
buffer_t *buffer_new(size_t size);
|
||||
|
||||
// Creates a new reference to the buffer |buf|. A reference is indistinguishable
|
||||
// from the original: writes to the original will be reflected in the reference
|
||||
// and vice versa. In other words, this function creates an alias to |buf|. The
|
||||
// caller must release the returned buffer with |buffer_free|. Note that releasing
|
||||
// the returned buffer does not release |buf|. |buf| must not be NULL.
|
||||
buffer_t *buffer_new_ref(const buffer_t *buf);
|
||||
|
||||
// Creates a new reference to the last |slice_size| bytes of |buf|. See
|
||||
// |buffer_new_ref| for a description of references. |slice_size| must be
|
||||
// greater than 0 and may be at most |buffer_length|
|
||||
// (0 < slice_size <= buffer_length). |buf| must not be NULL.
|
||||
buffer_t *buffer_new_slice(const buffer_t *buf, size_t slice_size);
|
||||
|
||||
// Frees a buffer object. |buf| may be NULL.
|
||||
void buffer_free(buffer_t *buf);
|
||||
|
||||
// Returns a pointer to a writeable memory region for |buf|. All references
|
||||
// and slices that share overlapping bytes will also be written to when
|
||||
// writing to the returned pointer. The caller may safely write up to
|
||||
// |buffer_length| consecutive bytes starting at the address returned by
|
||||
// this function. |buf| must not be NULL.
|
||||
void *buffer_ptr(const buffer_t *buf);
|
||||
|
||||
// Returns the length of the writeable memory region referred to by |buf|.
|
||||
// |buf| must not be NULL.
|
||||
size_t buffer_length(const buffer_t *buf);
|
||||
|
||||
#endif /*_BUFFER_H_*/
|
||||
148
tools/sdk/esp32/include/bt/common/osi/include/osi/config.h
Normal file
148
tools/sdk/esp32/include/bt/common/osi/include/osi/config.h
Normal file
@@ -0,0 +1,148 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
// This module implements a configuration parser. Clients can query the
|
||||
// contents of a configuration file through the interface provided here.
|
||||
// The current implementation is read-only; mutations are only kept in
|
||||
// memory. This parser supports the INI file format.
|
||||
|
||||
// Implementation notes:
|
||||
// - Key/value pairs that are not within a section are assumed to be under
|
||||
// the |CONFIG_DEFAULT_SECTION| section.
|
||||
// - Multiple sections with the same name will be merged as if they were in
|
||||
// a single section.
|
||||
// - Empty sections with no key/value pairs will be treated as if they do
|
||||
// not exist. In other words, |config_has_section| will return false for
|
||||
// empty sections.
|
||||
// - Duplicate keys in a section will overwrite previous values.
|
||||
// - All strings are case sensitive.
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// The default section name to use if a key/value pair is not defined within
|
||||
// a section.
|
||||
#define CONFIG_DEFAULT_SECTION "Global"
|
||||
|
||||
typedef struct config_t config_t;
|
||||
typedef struct config_section_node_t config_section_node_t;
|
||||
|
||||
// Creates a new config object with no entries (i.e. not backed by a file).
|
||||
// This function returns a config object or NULL on error. Clients must call
|
||||
// |config_free| on the returned handle when it is no longer required.
|
||||
config_t *config_new_empty(void);
|
||||
|
||||
// Loads the specified file and returns a handle to the config file. If there
|
||||
// was a problem loading the file or allocating memory, this function returns
|
||||
// NULL. Clients must call |config_free| on the returned handle when it is no
|
||||
// longer required. |filename| must not be NULL and must point to a readable
|
||||
// file on the filesystem.
|
||||
config_t *config_new(const char *filename);
|
||||
|
||||
// Frees resources associated with the config file. No further operations may
|
||||
// be performed on the |config| object after calling this function. |config|
|
||||
// may be NULL.
|
||||
void config_free(config_t *config);
|
||||
|
||||
// Returns true if the config file contains a section named |section|. If
|
||||
// the section has no key/value pairs in it, this function will return false.
|
||||
// |config| and |section| must not be NULL.
|
||||
bool config_has_section(const config_t *config, const char *section);
|
||||
|
||||
// Returns true if the config file has a key named |key| under |section|.
|
||||
// Returns false otherwise. |config|, |section|, and |key| must not be NULL.
|
||||
bool config_has_key(const config_t *config, const char *section, const char *key);
|
||||
|
||||
// Returns true if the config file has a key named |key| and the key_value.
|
||||
// Returns false otherwise. |config|, |key|, and |key_value| must not be NULL.
|
||||
bool config_has_key_in_section(config_t *config, const char *key, char *key_value);
|
||||
|
||||
// Returns the integral value for a given |key| in |section|. If |section|
|
||||
// or |key| do not exist, or the value cannot be fully converted to an integer,
|
||||
// this function returns |def_value|. |config|, |section|, and |key| must not
|
||||
// be NULL.
|
||||
int config_get_int(const config_t *config, const char *section, const char *key, int def_value);
|
||||
|
||||
// Returns the boolean value for a given |key| in |section|. If |section|
|
||||
// or |key| do not exist, or the value cannot be converted to a boolean, this
|
||||
// function returns |def_value|. |config|, |section|, and |key| must not be NULL.
|
||||
bool config_get_bool(const config_t *config, const char *section, const char *key, bool def_value);
|
||||
|
||||
// Returns the string value for a given |key| in |section|. If |section| or
|
||||
// |key| do not exist, this function returns |def_value|. The returned string
|
||||
// is owned by the config module and must not be freed. |config|, |section|,
|
||||
// and |key| must not be NULL. |def_value| may be NULL.
|
||||
const char *config_get_string(const config_t *config, const char *section, const char *key, const char *def_value);
|
||||
|
||||
// Sets an integral value for the |key| in |section|. If |key| or |section| do
|
||||
// not already exist, this function creates them. |config|, |section|, and |key|
|
||||
// must not be NULL.
|
||||
void config_set_int(config_t *config, const char *section, const char *key, int value);
|
||||
|
||||
// Sets a boolean value for the |key| in |section|. If |key| or |section| do
|
||||
// not already exist, this function creates them. |config|, |section|, and |key|
|
||||
// must not be NULL.
|
||||
void config_set_bool(config_t *config, const char *section, const char *key, bool value);
|
||||
|
||||
// Sets a string value for the |key| in |section|. If |key| or |section| do
|
||||
// not already exist, this function creates them. |config|, |section|, |key|, and
|
||||
// |value| must not be NULL.
|
||||
void config_set_string(config_t *config, const char *section, const char *key, const char *value, bool insert_back);
|
||||
|
||||
// Removes |section| from the |config| (and, as a result, all keys in the section).
|
||||
// Returns true if |section| was found and removed from |config|, false otherwise.
|
||||
// Neither |config| nor |section| may be NULL.
|
||||
bool config_remove_section(config_t *config, const char *section);
|
||||
|
||||
// Removes one specific |key| residing in |section| of the |config|. Returns true
|
||||
// if the section and key were found and the key was removed, false otherwise.
|
||||
// None of |config|, |section|, or |key| may be NULL.
|
||||
bool config_remove_key(config_t *config, const char *section, const char *key);
|
||||
|
||||
// Returns an iterator to the first section in the config file. If there are no
|
||||
// sections, the iterator will equal the return value of |config_section_end|.
|
||||
// The returned pointer must be treated as an opaque handle and must not be freed.
|
||||
// The iterator is invalidated on any config mutating operation. |config| may not
|
||||
// be NULL.
|
||||
const config_section_node_t *config_section_begin(const config_t *config);
|
||||
|
||||
// Returns an iterator to one past the last section in the config file. It does not
|
||||
// represent a valid section, but can be used to determine if all sections have been
|
||||
// iterated over. The returned pointer must be treated as an opaque handle and must
|
||||
// not be freed and must not be iterated on (must not call |config_section_next| on
|
||||
// it). |config| may not be NULL.
|
||||
const config_section_node_t *config_section_end(const config_t *config);
|
||||
|
||||
// Moves |iter| to the next section. If there are no more sections, |iter| will
|
||||
// equal the value of |config_section_end|. |iter| may not be NULL and must be
|
||||
// a pointer returned by either |config_section_begin| or |config_section_next|.
|
||||
const config_section_node_t *config_section_next(const config_section_node_t *iter);
|
||||
|
||||
// Returns the name of the section referred to by |iter|. The returned pointer is
|
||||
// owned by the config module and must not be freed by the caller. The pointer will
|
||||
// remain valid until |config_free| is called. |iter| may not be NULL and must not
|
||||
// equal the value returned by |config_section_end|.
|
||||
const char *config_section_name(const config_section_node_t *iter);
|
||||
|
||||
// Saves |config| to a file given by |filename|. Note that this could be a destructive
|
||||
// operation: if |filename| already exists, it will be overwritten. The config
|
||||
// module does not preserve comments or formatting so if a config file was opened
|
||||
// with |config_new| and subsequently overwritten with |config_save|, all comments
|
||||
// and special formatting in the original file will be lost. Neither |config| nor
|
||||
// |filename| may be NULL.
|
||||
bool config_save(const config_t *config, const char *filename);
|
||||
|
||||
#endif /* #ifndef __CONFIG_H__ */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _FIXED_PKT_QUEUE_H_
|
||||
#define _FIXED_PKT_QUEUE_H_
|
||||
|
||||
|
||||
#include "osi/pkt_queue.h"
|
||||
#include "osi/semaphore.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef FIXED_PKT_QUEUE_SIZE_MAX
|
||||
#define FIXED_PKT_QUEUE_SIZE_MAX 254
|
||||
#endif
|
||||
|
||||
#define FIXED_PKT_QUEUE_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
|
||||
|
||||
struct fixed_pkt_queue_t;
|
||||
|
||||
typedef struct fixed_pkt_queue_t fixed_pkt_queue_t;
|
||||
|
||||
typedef void (*fixed_pkt_queue_free_cb)(pkt_linked_item_t *data);
|
||||
typedef void (*fixed_pkt_queue_cb)(fixed_pkt_queue_t *queue);
|
||||
|
||||
// Creates a new fixed queue with the given |capacity|. If more elements than
|
||||
// |capacity| are added to the queue, the caller is blocked until space is
|
||||
// made available in the queue. Returns NULL on failure. The caller must free
|
||||
// the returned queue with |fixed_pkt_queue_free|.
|
||||
fixed_pkt_queue_t *fixed_pkt_queue_new(size_t capacity);
|
||||
|
||||
// Freeing a queue that is currently in use (i.e. has waiters
|
||||
// blocked on it) results in undefined behaviour.
|
||||
void fixed_pkt_queue_free(fixed_pkt_queue_t *queue, fixed_pkt_queue_free_cb free_cb);
|
||||
|
||||
// Returns a value indicating whether the given |queue| is empty. If |queue|
|
||||
// is NULL, the return value is true.
|
||||
bool fixed_pkt_queue_is_empty(fixed_pkt_queue_t *queue);
|
||||
|
||||
// Returns the length of the |queue|. If |queue| is NULL, the return value
|
||||
// is 0.
|
||||
size_t fixed_pkt_queue_length(fixed_pkt_queue_t *queue);
|
||||
|
||||
// Returns the maximum number of elements this queue may hold. |queue| may
|
||||
// not be NULL.
|
||||
size_t fixed_pkt_queue_capacity(fixed_pkt_queue_t *queue);
|
||||
|
||||
// Enqueues the given |data| into the |queue|. The caller will be blocked or immediately return or wait for timeout according to the parameter timeout.
|
||||
// If enqueue failed, it will return false, otherwise return true
|
||||
bool fixed_pkt_queue_enqueue(fixed_pkt_queue_t *queue, pkt_linked_item_t *linked_pkt, uint32_t timeout);
|
||||
|
||||
// Dequeues the next element from |queue|. If the queue is currently empty,
|
||||
// this function will block the caller until an item is enqueued or immediately return or wait for timeout according to the parameter timeout.
|
||||
// If dequeue failed, it will return NULL, otherwise return a point.
|
||||
pkt_linked_item_t *fixed_pkt_queue_dequeue(fixed_pkt_queue_t *queue, uint32_t timeout);
|
||||
|
||||
// Returns the first element from |queue|, if present, without dequeuing it.
|
||||
// This function will never block the caller. Returns NULL if there are no
|
||||
// elements in the queue or |queue| is NULL.
|
||||
pkt_linked_item_t *fixed_pkt_queue_try_peek_first(fixed_pkt_queue_t *queue);
|
||||
|
||||
// Registers |queue| with |reactor| for dequeue operations. When there is an element
|
||||
// in the queue, ready_cb will be called. The |context| parameter is passed, untouched,
|
||||
// to the callback routine. Neither |queue|, nor |reactor|, nor |read_cb| may be NULL.
|
||||
// |context| may be NULL.
|
||||
void fixed_pkt_queue_register_dequeue(fixed_pkt_queue_t *queue, fixed_pkt_queue_cb ready_cb);
|
||||
|
||||
// Unregisters the dequeue ready callback for |queue| from whichever reactor
|
||||
// it is registered with, if any. This function is idempotent.
|
||||
void fixed_pkt_queue_unregister_dequeue(fixed_pkt_queue_t *queue);
|
||||
|
||||
void fixed_pkt_queue_process(fixed_pkt_queue_t *queue);
|
||||
|
||||
#endif
|
||||
125
tools/sdk/esp32/include/bt/common/osi/include/osi/fixed_queue.h
Normal file
125
tools/sdk/esp32/include/bt/common/osi/include/osi/fixed_queue.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _FIXED_QUEUE_H_
|
||||
#define _FIXED_QUEUE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "osi/list.h"
|
||||
#include "osi/semaphore.h"
|
||||
|
||||
#ifndef QUEUE_SIZE_MAX
|
||||
#define QUEUE_SIZE_MAX 254
|
||||
#endif
|
||||
|
||||
#define FIXED_QUEUE_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
|
||||
|
||||
struct fixed_queue_t;
|
||||
|
||||
typedef struct fixed_queue_t fixed_queue_t;
|
||||
//typedef struct reactor_t reactor_t;
|
||||
|
||||
typedef void (*fixed_queue_free_cb)(void *data);
|
||||
typedef void (*fixed_queue_cb)(fixed_queue_t *queue);
|
||||
|
||||
// Creates a new fixed queue with the given |capacity|. If more elements than
|
||||
// |capacity| are added to the queue, the caller is blocked until space is
|
||||
// made available in the queue. Returns NULL on failure. The caller must free
|
||||
// the returned queue with |fixed_queue_free|.
|
||||
fixed_queue_t *fixed_queue_new(size_t capacity);
|
||||
|
||||
// Freeing a queue that is currently in use (i.e. has waiters
|
||||
// blocked on it) results in undefined behaviour.
|
||||
void fixed_queue_free(fixed_queue_t *queue, fixed_queue_free_cb free_cb);
|
||||
|
||||
// Returns a value indicating whether the given |queue| is empty. If |queue|
|
||||
// is NULL, the return value is true.
|
||||
bool fixed_queue_is_empty(fixed_queue_t *queue);
|
||||
|
||||
// Returns the length of the |queue|. If |queue| is NULL, the return value
|
||||
// is 0.
|
||||
size_t fixed_queue_length(fixed_queue_t *queue);
|
||||
|
||||
// Returns the maximum number of elements this queue may hold. |queue| may
|
||||
// not be NULL.
|
||||
size_t fixed_queue_capacity(fixed_queue_t *queue);
|
||||
|
||||
// Enqueues the given |data| into the |queue|. The caller will be blocked or immediately return or wait for timeout according to the parameter timeout.
|
||||
// If enqueue failed, it will return false, otherwise return true
|
||||
bool fixed_queue_enqueue(fixed_queue_t *queue, void *data, uint32_t timeout);
|
||||
|
||||
// Dequeues the next element from |queue|. If the queue is currently empty,
|
||||
// this function will block the caller until an item is enqueued or immediately return or wait for timeout according to the parameter timeout.
|
||||
// If dequeue failed, it will return NULL, otherwise return a point.
|
||||
void *fixed_queue_dequeue(fixed_queue_t *queue, uint32_t timeout);
|
||||
|
||||
// Returns the first element from |queue|, if present, without dequeuing it.
|
||||
// This function will never block the caller. Returns NULL if there are no
|
||||
// elements in the queue or |queue| is NULL.
|
||||
void *fixed_queue_try_peek_first(fixed_queue_t *queue);
|
||||
|
||||
// Returns the last element from |queue|, if present, without dequeuing it.
|
||||
// This function will never block the caller. Returns NULL if there are no
|
||||
// elements in the queue or |queue| is NULL.
|
||||
void *fixed_queue_try_peek_last(fixed_queue_t *queue);
|
||||
|
||||
// Tries to remove a |data| element from the middle of the |queue|. This
|
||||
// function will never block the caller. If the queue is empty or NULL, this
|
||||
// function returns NULL immediately. |data| may not be NULL. If the |data|
|
||||
// element is found in the queue, a pointer to the removed data is returned,
|
||||
// otherwise NULL.
|
||||
void *fixed_queue_try_remove_from_queue(fixed_queue_t *queue, void *data);
|
||||
|
||||
// Returns the iterateable list with all entries in the |queue|. This function
|
||||
// will never block the caller. |queue| may not be NULL.
|
||||
//
|
||||
// NOTE: The return result of this function is not thread safe: the list could
|
||||
// be modified by another thread, and the result would be unpredictable.
|
||||
// TODO: The usage of this function should be refactored, and the function
|
||||
// itself should be removed.
|
||||
list_t *fixed_queue_get_list(fixed_queue_t *queue);
|
||||
|
||||
// This function returns a valid file descriptor. Callers may perform one
|
||||
// operation on the fd: select(2). If |select| indicates that the file
|
||||
// descriptor is readable, the caller may call |fixed_queue_enqueue| without
|
||||
// blocking. The caller must not close the returned file descriptor. |queue|
|
||||
// may not be NULL.
|
||||
//int fixed_queue_get_enqueue_fd(const fixed_queue_t *queue);
|
||||
|
||||
// This function returns a valid file descriptor. Callers may perform one
|
||||
// operation on the fd: select(2). If |select| indicates that the file
|
||||
// descriptor is readable, the caller may call |fixed_queue_dequeue| without
|
||||
// blocking. The caller must not close the returned file descriptor. |queue|
|
||||
// may not be NULL.
|
||||
//int fixed_queue_get_dequeue_fd(const fixed_queue_t *queue);
|
||||
|
||||
// Registers |queue| with |reactor| for dequeue operations. When there is an element
|
||||
// in the queue, ready_cb will be called. The |context| parameter is passed, untouched,
|
||||
// to the callback routine. Neither |queue|, nor |reactor|, nor |read_cb| may be NULL.
|
||||
// |context| may be NULL.
|
||||
void fixed_queue_register_dequeue(fixed_queue_t *queue, fixed_queue_cb ready_cb);
|
||||
|
||||
// Unregisters the dequeue ready callback for |queue| from whichever reactor
|
||||
// it is registered with, if any. This function is idempotent.
|
||||
void fixed_queue_unregister_dequeue(fixed_queue_t *queue);
|
||||
|
||||
void fixed_queue_process(fixed_queue_t *queue);
|
||||
|
||||
list_t *fixed_queue_get_list(fixed_queue_t *queue);
|
||||
|
||||
#endif
|
||||
53
tools/sdk/esp32/include/bt/common/osi/include/osi/future.h
Normal file
53
tools/sdk/esp32/include/bt/common/osi/include/osi/future.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __FUTURE_H__
|
||||
#define __FUTURE_H__
|
||||
|
||||
#include "osi/semaphore.h"
|
||||
|
||||
struct future {
|
||||
bool ready_can_be_called;
|
||||
osi_sem_t semaphore; // NULL semaphore means immediate future
|
||||
void *result;
|
||||
};
|
||||
typedef struct future future_t;
|
||||
|
||||
#define FUTURE_SUCCESS ((void *)1)
|
||||
#define FUTURE_FAIL ((void *)0)
|
||||
|
||||
// Constructs a new future_t object. Returns NULL on failure.
|
||||
future_t *future_new(void);
|
||||
|
||||
// Constructs a new future_t object with an immediate |value|. No waiting will
|
||||
// occur in the call to |future_await| because the value is already present.
|
||||
// Returns NULL on failure.
|
||||
future_t *future_new_immediate(void *value);
|
||||
|
||||
// Signals that the |future| is ready, passing |value| back to the context
|
||||
// waiting for the result. Must only be called once for every future.
|
||||
// |future| may not be NULL.
|
||||
void future_ready(future_t *future, void *value);
|
||||
|
||||
// Waits for the |future| to be ready. Returns the value set in |future_ready|.
|
||||
// Frees the future before return. |future| may not be NULL.
|
||||
void *future_await(future_t *async_result);
|
||||
|
||||
//Free the future if this "future" is not used
|
||||
void future_free(future_t *future);
|
||||
#endif /* __FUTURE_H__ */
|
||||
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _HASH_FUNCTIONS_H_
|
||||
#define _HASH_FUNCTIONS_H_
|
||||
|
||||
#include "osi/hash_map.h"
|
||||
|
||||
typedef unsigned char hash_key_t[4];
|
||||
|
||||
hash_index_t hash_function_naive(const void *key);
|
||||
|
||||
hash_index_t hash_function_integer(const void *key);
|
||||
|
||||
// Hashes a pointer based only on its address value
|
||||
hash_index_t hash_function_pointer(const void *key);
|
||||
|
||||
hash_index_t hash_function_string(const void *key);
|
||||
|
||||
void hash_function_blob(const unsigned char *s, unsigned int len, hash_key_t h);
|
||||
|
||||
#endif /* _HASH_FUNCTIONS_H_ */
|
||||
110
tools/sdk/esp32/include/bt/common/osi/include/osi/hash_map.h
Normal file
110
tools/sdk/esp32/include/bt/common/osi/include/osi/hash_map.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _HASH_MAP_H_
|
||||
#define _HASH_MAP_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct hash_map_t;
|
||||
typedef struct hash_map_t hash_map_t;
|
||||
|
||||
typedef struct hash_map_entry_t {
|
||||
const void *key;
|
||||
void *data;
|
||||
const hash_map_t *hash_map;
|
||||
} hash_map_entry_t;
|
||||
|
||||
typedef size_t hash_index_t;
|
||||
|
||||
// Takes a key structure and returns a hash value.
|
||||
typedef hash_index_t (*hash_index_fn)(const void *key);
|
||||
typedef bool (*hash_map_iter_cb)(hash_map_entry_t *hash_entry, void *context);
|
||||
|
||||
typedef bool (*key_equality_fn)(const void *x, const void *y);
|
||||
|
||||
typedef void (*key_free_fn)(void *data);
|
||||
typedef void (*data_free_fn)(void *data);
|
||||
|
||||
// Returns a new, empty hash_map. Returns NULL if not enough memory could be allocated
|
||||
// for the hash_map structure. The returned hash_map must be freed with |hash_map_free|.
|
||||
// The |num_bucket| specifies the number of hashable buckets for the map and must not
|
||||
// be zero. The |hash_fn| specifies a hash function to be used and must not be NULL.
|
||||
// The |key_fn| and |data_fn| are called whenever a hash_map element is removed from
|
||||
// the hash_map. They can be used to release resources held by the hash_map element,
|
||||
// e.g. memory or file descriptor. |key_fn| and |data_fn| may be NULL if no cleanup
|
||||
// is necessary on element removal. |equality_fn| is used to check for key equality.
|
||||
// If |equality_fn| is NULL, default pointer equality is used.
|
||||
hash_map_t *hash_map_new(
|
||||
size_t size,
|
||||
hash_index_fn hash_fn,
|
||||
key_free_fn key_fn,
|
||||
data_free_fn data_fn,
|
||||
key_equality_fn equality_fn);
|
||||
|
||||
// Frees the hash_map. This function accepts NULL as an argument, in which case it
|
||||
// behaves like a no-op.
|
||||
void hash_map_free(hash_map_t *hash_map);
|
||||
|
||||
// Returns true if the hash_map is empty (has no elements), false otherwise.
|
||||
// Note that a NULL |hash_map| is not the same as an empty |hash_map|. This function
|
||||
// does not accept a NULL |hash_map|.
|
||||
//bool hash_map_is_empty(const hash_map_t *hash_map);
|
||||
|
||||
// Returns the number of elements in the hash map. This function does not accept a
|
||||
// NULL |hash_map|.
|
||||
//size_t hash_map_size(const hash_map_t *hash_map);
|
||||
|
||||
// Returns the number of buckets in the hash map. This function does not accept a
|
||||
// NULL |hash_map|.
|
||||
//size_t hash_map_num_buckets(const hash_map_t *hash_map);
|
||||
|
||||
// Returns true if the hash_map has a valid entry for the presented key.
|
||||
// This function does not accept a NULL |hash_map|.
|
||||
bool hash_map_has_key(const hash_map_t *hash_map, const void *key);
|
||||
|
||||
// Returns the element indexed by |key| in the hash_map without removing it. |hash_map|
|
||||
// may not be NULL. Returns NULL if no entry indexed by |key|.
|
||||
void *hash_map_get(const hash_map_t *hash_map, const void *key);
|
||||
|
||||
// Sets the value |data| indexed by |key| into the |hash_map|. Neither |data| nor
|
||||
// |hash_map| may be NULL. This function does not make copies of |data| nor |key|
|
||||
// so the pointers must remain valid at least until the element is removed from the
|
||||
// hash_map or the hash_map is freed. Returns true if |data| could be set, false
|
||||
// otherwise (e.g. out of memory).
|
||||
bool hash_map_set(hash_map_t *hash_map, const void *key, void *data);
|
||||
|
||||
// Removes data indexed by |key| from the hash_map. |hash_map| may not be NULL.
|
||||
// If |key_fn| or |data_fn| functions were specified in |hash_map_new|, they
|
||||
// will be called back with |key| or |data| respectively. This function returns true
|
||||
// if |key| was found in the hash_map and removed, false otherwise.
|
||||
bool hash_map_erase(hash_map_t *hash_map, const void *key);
|
||||
|
||||
// Removes all elements in the hash_map. Calling this function will return the hash_map
|
||||
// to the same state it was in after |hash_map_new|. |hash_map| may not be NULL.
|
||||
void hash_map_clear(hash_map_t *hash_map);
|
||||
|
||||
// Iterates through the entire |hash_map| and calls |callback| for each data
|
||||
// element and passes through the |context| argument. If the hash_map is
|
||||
// empty, |callback| will never be called. It is not safe to mutate the
|
||||
// hash_map inside the callback. Neither |hash_map| nor |callback| may be NULL.
|
||||
// If |callback| returns false, the iteration loop will immediately exit.
|
||||
void hash_map_foreach(hash_map_t *hash_map, hash_map_iter_cb callback, void *context);
|
||||
|
||||
#endif /* _HASH_MAP_H_ */
|
||||
121
tools/sdk/esp32/include/bt/common/osi/include/osi/list.h
Normal file
121
tools/sdk/esp32/include/bt/common/osi/include/osi/list.h
Normal file
@@ -0,0 +1,121 @@
|
||||
#ifndef _LIST_H_
|
||||
#define _LIST_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
struct list_node_t;
|
||||
typedef struct list_node_t list_node_t;
|
||||
|
||||
struct list_t;
|
||||
typedef struct list_t list_t;
|
||||
|
||||
typedef void (*list_free_cb)(void *data);
|
||||
typedef bool (*list_iter_cb)(void *data, void *context);
|
||||
|
||||
// Returns a new, empty list. Returns NULL if not enough memory could be allocated
|
||||
// for the list structure. The returned list must be freed with |list_free|. The
|
||||
// |callback| specifies a function to be called whenever a list element is removed
|
||||
// from the list. It can be used to release resources held by the list element, e.g.
|
||||
// memory or file descriptor. |callback| may be NULL if no cleanup is necessary on
|
||||
// element removal.
|
||||
list_t *list_new(list_free_cb callback);
|
||||
|
||||
|
||||
list_node_t *list_free_node(list_t *list, list_node_t *node);
|
||||
|
||||
// similar with list_free_node, this function doesn't free the node data
|
||||
list_node_t *list_delete_node(list_t *list, list_node_t *node);
|
||||
|
||||
// Frees the list. This function accepts NULL as an argument, in which case it
|
||||
// behaves like a no-op.
|
||||
void list_free(list_t *list);
|
||||
|
||||
// Returns true if |list| is empty (has no elements), false otherwise.
|
||||
// |list| may not be NULL.
|
||||
bool list_is_empty(const list_t *list);
|
||||
|
||||
// Returns true if the list contains |data|, false otherwise.
|
||||
// |list| may not be NULL.
|
||||
bool list_contains(const list_t *list, const void *data);
|
||||
|
||||
// Returns list_node which contains |data|, NULL otherwise.
|
||||
// |list| may not be NULL.
|
||||
list_node_t *list_get_node(const list_t *list, const void *data);
|
||||
|
||||
// Returns the length of the |list|. |list| may not be NULL.
|
||||
size_t list_length(const list_t *list);
|
||||
|
||||
// Returns the first element in the list without removing it. |list| may not
|
||||
// be NULL or empty.
|
||||
void *list_front(const list_t *list);
|
||||
|
||||
// Returns the last element in the list without removing it. |list| may not
|
||||
// be NULL or empty.
|
||||
void *list_back(const list_t *list);
|
||||
list_node_t *list_back_node(const list_t *list);
|
||||
|
||||
// Inserts |data| after |prev_node| in |list|. |data|, |list|, and |prev_node|
|
||||
// may not be NULL. This function does not make a copy of |data| so the pointer
|
||||
// must remain valid at least until the element is removed from the list or the
|
||||
// list is freed. Returns true if |data| could be inserted, false otherwise
|
||||
// (e.g. out of memory).
|
||||
bool list_insert_after(list_t *list, list_node_t *prev_node, void *data);
|
||||
|
||||
// Inserts |data| at the beginning of |list|. Neither |data| nor |list| may be NULL.
|
||||
// This function does not make a copy of |data| so the pointer must remain valid
|
||||
// at least until the element is removed from the list or the list is freed.
|
||||
// Returns true if |data| could be inserted, false otherwise (e.g. out of memory).
|
||||
bool list_prepend(list_t *list, void *data);
|
||||
|
||||
// Inserts |data| at the end of |list|. Neither |data| nor |list| may be NULL.
|
||||
// This function does not make a copy of |data| so the pointer must remain valid
|
||||
// at least until the element is removed from the list or the list is freed.
|
||||
// Returns true if |data| could be inserted, false otherwise (e.g. out of memory).
|
||||
bool list_append(list_t *list, void *data);
|
||||
|
||||
// Removes |data| from the list. Neither |list| nor |data| may be NULL. If |data|
|
||||
// is inserted multiple times in the list, this function will only remove the first
|
||||
// instance. If a free function was specified in |list_new|, it will be called back
|
||||
// with |data|. This function returns true if |data| was found in the list and removed,
|
||||
// false otherwise.
|
||||
//list_node_t list_remove_node(list_t *list, list_node_t *prev_node, list_node_t *node);
|
||||
//list_node_t list_insert_node(list_t *list, list_node_t *prev_node, list_node_t *node);
|
||||
|
||||
bool list_remove(list_t *list, void *data);
|
||||
|
||||
// similar with list_remove, but do not free the node data
|
||||
bool list_delete(list_t *list, void *data);
|
||||
|
||||
// Removes all elements in the list. Calling this function will return the list to the
|
||||
// same state it was in after |list_new|. |list| may not be NULL.
|
||||
void list_clear(list_t *list);
|
||||
|
||||
// Iterates through the entire |list| and calls |callback| for each data element.
|
||||
// If the list is empty, |callback| will never be called. It is safe to mutate the
|
||||
// list inside the callback. If an element is added before the node being visited,
|
||||
// there will be no callback for the newly-inserted node. Neither |list| nor
|
||||
// |callback| may be NULL.
|
||||
list_node_t *list_foreach(const list_t *list, list_iter_cb callback, void *context);
|
||||
|
||||
// Returns an iterator to the first element in |list|. |list| may not be NULL.
|
||||
// The returned iterator is valid as long as it does not equal the value returned
|
||||
// by |list_end|.
|
||||
list_node_t *list_begin(const list_t *list);
|
||||
|
||||
// Returns an iterator that points past the end of the list. In other words,
|
||||
// this function returns the value of an invalid iterator for the given list.
|
||||
// When an iterator has the same value as what's returned by this function, you
|
||||
// may no longer call |list_next| with the iterator. |list| may not be NULL.
|
||||
list_node_t *list_end(const list_t *list);
|
||||
|
||||
// Given a valid iterator |node|, this function returns the next value for the
|
||||
// iterator. If the returned value equals the value returned by |list_end|, the
|
||||
// iterator has reached the end of the list and may no longer be used for any
|
||||
// purpose.
|
||||
list_node_t *list_next(const list_node_t *node);
|
||||
|
||||
// Returns the value stored at the location pointed to by the iterator |node|.
|
||||
// |node| must not equal the value returned by |list_end|.
|
||||
void *list_node(const list_node_t *node);
|
||||
|
||||
#endif /* _LIST_H_ */
|
||||
52
tools/sdk/esp32/include/bt/common/osi/include/osi/mutex.h
Normal file
52
tools/sdk/esp32/include/bt/common/osi/include/osi/mutex.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2015 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __MUTEX_H__
|
||||
#define __MUTEX_H__
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "osi/semaphore.h"
|
||||
|
||||
#define OSI_MUTEX_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
|
||||
|
||||
#define osi_mutex_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
|
||||
#define osi_mutex_set_invalid( x ) ( ( *x ) = NULL )
|
||||
|
||||
typedef xSemaphoreHandle osi_mutex_t;
|
||||
|
||||
int osi_mutex_new(osi_mutex_t *mutex);
|
||||
|
||||
int osi_mutex_lock(osi_mutex_t *mutex, uint32_t timeout);
|
||||
|
||||
void osi_mutex_unlock(osi_mutex_t *mutex);
|
||||
|
||||
void osi_mutex_free(osi_mutex_t *mutex);
|
||||
|
||||
/* Just for a global mutex */
|
||||
int osi_mutex_global_init(void);
|
||||
|
||||
void osi_mutex_global_deinit(void);
|
||||
|
||||
void osi_mutex_global_lock(void);
|
||||
|
||||
void osi_mutex_global_unlock(void);
|
||||
|
||||
#endif /* __MUTEX_H__ */
|
||||
16
tools/sdk/esp32/include/bt/common/osi/include/osi/osi.h
Normal file
16
tools/sdk/esp32/include/bt/common/osi/include/osi/osi.h
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#ifndef _OSI_H_
|
||||
#define _OSI_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define UNUSED_ATTR __attribute__((unused))
|
||||
|
||||
#define CONCAT(a, b) a##b
|
||||
#define COMPILE_ASSERT(x)
|
||||
|
||||
int osi_init(void);
|
||||
void osi_deinit(void);
|
||||
|
||||
#endif /*_OSI_H_*/
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _PKT_LIST_H_
|
||||
#define _PKT_LIST_H_
|
||||
|
||||
#include "sys/queue.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct pkt_queue;
|
||||
|
||||
typedef struct pkt_linked_item {
|
||||
STAILQ_ENTRY(pkt_linked_item) next;
|
||||
uint8_t data[];
|
||||
} pkt_linked_item_t;
|
||||
|
||||
#define BT_PKT_LINKED_HDR_SIZE (sizeof (pkt_linked_item_t))
|
||||
|
||||
typedef void (*pkt_queue_free_cb)(pkt_linked_item_t *item);
|
||||
|
||||
/*
|
||||
* brief: create a pkt_queue instance. pkt_queue is a wrapper class of a FIFO implemented by single linked list.
|
||||
* The enqueue and dequeue operations of the FIFO are protected against race conditions of multiple tasks
|
||||
* return: NULL if not enough memory, otherwise a valid pointer
|
||||
*/
|
||||
struct pkt_queue *pkt_queue_create(void);
|
||||
|
||||
/*
|
||||
* brief: enqueue one item to the FIFO
|
||||
* param queue: pkt_queue instance created using pkt_queue_create
|
||||
* param item: the item to be enqueued to the FIFO
|
||||
* return: true if enqueued successfully, false when the arguments passed in are invalid
|
||||
*/
|
||||
bool pkt_queue_enqueue(struct pkt_queue *queue, pkt_linked_item_t *item);
|
||||
|
||||
/*
|
||||
* brief: dequeue one item for the FIFO
|
||||
* param queue: pkt_queue instance created using pkt_queue_create
|
||||
* return: pointer of type pkt_linked_item_t dequeued, NULL if the queue is empty or upon exception
|
||||
*/
|
||||
pkt_linked_item_t *pkt_queue_dequeue(struct pkt_queue *queue);
|
||||
|
||||
/*
|
||||
* brief: get the pointer of the first item from the FIFO but not get it dequeued
|
||||
* param queue: pkt_queue instance created using pkt_queue_create
|
||||
* return: pointer of the first item in the FIFO, NULL if the FIFO is empty
|
||||
*/
|
||||
pkt_linked_item_t *pkt_queue_try_peek_first(struct pkt_queue *queue);
|
||||
|
||||
/*
|
||||
* brief: retrieve the number of items existing in the FIFO
|
||||
* param queue: pkt_queue instance created using pkt_queue_create
|
||||
* return: total number of items in the FIFO
|
||||
*/
|
||||
size_t pkt_queue_length(const struct pkt_queue *queue);
|
||||
|
||||
/*
|
||||
* brief: retrieve the status whether the FIFO is empty
|
||||
* param queue: pkt_queue instance created using pkt_queue_create
|
||||
* return: false if the FIFO is not empty, otherwise true
|
||||
*/
|
||||
bool pkt_queue_is_empty(const struct pkt_queue *queue);
|
||||
|
||||
/*
|
||||
* brief: delete the item in the FIFO one by one
|
||||
* param free_cb: destructor function for each item in the FIFO, if set to NULL, will use osi_free_func by default
|
||||
*/
|
||||
void pkt_queue_flush(struct pkt_queue *queue, pkt_queue_free_cb free_cb);
|
||||
|
||||
/*
|
||||
* brief: delete the items in the FIFO and then destroy the pkt_queue instance.
|
||||
* param free_cb: destructor function for each item in the FIFO, if set to NULL, will use osi_free_func by default
|
||||
*/
|
||||
void pkt_queue_destroy(struct pkt_queue *queue, pkt_queue_free_cb free_cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2015 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __SEMAPHORE_H__
|
||||
#define __SEMAPHORE_H__
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#define OSI_SEM_MAX_TIMEOUT 0xffffffffUL
|
||||
|
||||
typedef xSemaphoreHandle osi_sem_t;
|
||||
|
||||
#define osi_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
|
||||
#define osi_sem_set_invalid( x ) ( ( *x ) = NULL )
|
||||
|
||||
int osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count);
|
||||
|
||||
void osi_sem_free(osi_sem_t *sem);
|
||||
|
||||
int osi_sem_take(osi_sem_t *sem, uint32_t timeout);
|
||||
|
||||
void osi_sem_give(osi_sem_t *sem);
|
||||
|
||||
|
||||
#endif /* __SEMAPHORE_H__ */
|
||||
130
tools/sdk/esp32/include/bt/common/osi/include/osi/thread.h
Normal file
130
tools/sdk/esp32/include/bt/common/osi/include/osi/thread.h
Normal file
@@ -0,0 +1,130 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __THREAD_H__
|
||||
#define __THREAD_H__
|
||||
|
||||
#include "freertos/FreeRTOSConfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "osi/semaphore.h"
|
||||
#include "esp_task.h"
|
||||
#include "bt_common.h"
|
||||
|
||||
#define portBASE_TYPE int
|
||||
|
||||
#define OSI_THREAD_MAX_TIMEOUT OSI_SEM_MAX_TIMEOUT
|
||||
|
||||
struct osi_thread;
|
||||
struct osi_event;
|
||||
|
||||
typedef struct osi_thread osi_thread_t;
|
||||
|
||||
typedef void (*osi_thread_func_t)(void *context);
|
||||
|
||||
typedef enum {
|
||||
OSI_THREAD_CORE_0 = 0,
|
||||
OSI_THREAD_CORE_1,
|
||||
OSI_THREAD_CORE_AFFINITY,
|
||||
} osi_thread_core_t;
|
||||
|
||||
/*
|
||||
* brief: Create a thread or task
|
||||
* param name: thread name
|
||||
* param stack_size: thread stack size
|
||||
* param priority: thread priority
|
||||
* param core: the CPU core which this thread run, OSI_THREAD_CORE_AFFINITY means unspecific CPU core
|
||||
* param work_queue_num: speicify queue number, the queue[0] has highest priority, and the priority is decrease by index
|
||||
* return : if create successfully, return thread handler; otherwise return NULL.
|
||||
*/
|
||||
osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num, const size_t work_queue_len[]);
|
||||
|
||||
/*
|
||||
* brief: Destroy a thread or task
|
||||
* param thread: point of thread handler
|
||||
*/
|
||||
void osi_thread_free(osi_thread_t *thread);
|
||||
|
||||
/*
|
||||
* brief: Post an msg to a thread and told the thread call the function
|
||||
* param thread: point of thread handler
|
||||
* param func: callback function that called by target thread
|
||||
* param context: argument of callback function
|
||||
* param queue_idx: the queue which the msg send to
|
||||
* param timeout: post timeout, OSI_THREAD_MAX_TIMEOUT means blocking forever, 0 means never blocking, others means block millisecond
|
||||
* return : if post successfully, return true, otherwise return false
|
||||
*/
|
||||
bool osi_thread_post(osi_thread_t *thread, osi_thread_func_t func, void *context, int queue_idx, uint32_t timeout);
|
||||
|
||||
/*
|
||||
* brief: Set the priority of thread
|
||||
* param thread: point of thread handler
|
||||
* param priority: priority
|
||||
* return : if set successfully, return true, otherwise return false
|
||||
*/
|
||||
bool osi_thread_set_priority(osi_thread_t *thread, int priority);
|
||||
|
||||
/* brief: Get thread name
|
||||
* param thread: point of thread handler
|
||||
* return: constant point of thread name
|
||||
*/
|
||||
const char *osi_thread_name(osi_thread_t *thread);
|
||||
|
||||
/* brief: Get the size of the specified queue
|
||||
* param thread: point of thread handler
|
||||
* param wq_idx: the queue index of the thread
|
||||
* return: queue size
|
||||
*/
|
||||
int osi_thread_queue_wait_size(osi_thread_t *thread, int wq_idx);
|
||||
|
||||
/*
|
||||
* brief: Create an osi_event struct and register the handler function and its argument
|
||||
* An osi_event is a kind of work that can be posted to the workqueue of osi_thread to process,
|
||||
* but the work can have at most one instance the thread workqueue before it is processed. This
|
||||
* allows the "single post, multiple data processing" jobs.
|
||||
* param func: the handler to process the job
|
||||
* param context: the argument to be passed to the handler function when the job is being processed
|
||||
* return: NULL if no memory, otherwise a valid struct pointer
|
||||
*/
|
||||
struct osi_event *osi_event_create(osi_thread_func_t func, void *context);
|
||||
|
||||
/*
|
||||
* brief: Bind an osi_event to a specific work queue for an osi_thread.
|
||||
* After binding is completed, a function call of API osi_thread_post_event will send a work
|
||||
* to the workqueue of the thread, with specified queue index.
|
||||
* param func: event: the pointer to osi_event that is created using osi_event_create
|
||||
* param thread: the pointer to osi_thread that is created using osi_thread_create
|
||||
* param queue_idx: the index of the workqueue of the specified osi_thread, with range starting from 0 to work_queue_num - 1
|
||||
* return: true if osi_event binds to the thread's workqueue successfully, otherwise false
|
||||
*/
|
||||
bool osi_event_bind(struct osi_event* event, osi_thread_t *thread, int queue_idx);
|
||||
|
||||
/*
|
||||
* brief: Destroy the osi_event struct created by osi_event_create and free the allocated memory
|
||||
* param event: the pointer to osi_event
|
||||
*/
|
||||
void osi_event_delete(struct osi_event* event);
|
||||
|
||||
/*
|
||||
* brief: try sending a work to the binded thread's workqueue, so that it can be handled by the worker thread
|
||||
* param event: pointer to osi_event, created by osi_event_create
|
||||
* param timeout: post timeout, OSI_THREAD_MAX_TIMEOUT means blocking forever, 0 means never blocking, others means block millisecond
|
||||
* return: true if the message is enqueued to the thread workqueue, otherwise failed
|
||||
* note: if the return value of function is false, it is the case that the workqueue of the thread is full, and users
|
||||
* are expected to post the event sometime later to get the work handled.
|
||||
*/
|
||||
bool osi_thread_post_event(struct osi_event *event, uint32_t timeout);
|
||||
|
||||
#endif /* __THREAD_H__ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
2275
tools/sdk/esp32/include/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h
Normal file
2275
tools/sdk/esp32/include/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 0x0–0x7F,
|
||||
* representing range of 1–127). 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 0x0–0xF,
|
||||
* representing range of 1–16).
|
||||
* 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 0x0–0x7F, representing
|
||||
* range of 1–127). 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 0x0–0xF,
|
||||
* representing range of 1 – 16).
|
||||
* Format B: The Length field is a 1-based uint7 value (valid range 0x0–0x7F,
|
||||
* 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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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_ */
|
||||
@@ -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__*/
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
80
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/access.h
Normal file
80
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/access.h
Normal 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_ */
|
||||
102
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/adv.h
Normal file
102
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/adv.h
Normal 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_ */
|
||||
35
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/beacon.h
Normal file
35
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/beacon.h
Normal 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_ */
|
||||
174
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/crypto.h
Normal file
174
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/crypto.h
Normal 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_ */
|
||||
@@ -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_ */
|
||||
183
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/foundation.h
Normal file
183
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/foundation.h
Normal 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_ */
|
||||
67
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/friend.h
Normal file
67
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/friend.h
Normal 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_ */
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
78
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/lpn.h
Normal file
78
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/lpn.h
Normal 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_ */
|
||||
33
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/mesh.h
Normal file
33
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/mesh.h
Normal 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_ */
|
||||
423
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/net.h
Normal file
423
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/net.h
Normal 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_ */
|
||||
43
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/prov.h
Normal file
43
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/prov.h
Normal 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_ */
|
||||
@@ -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_ */
|
||||
@@ -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_ */
|
||||
112
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/proxy_client.h
Normal file
112
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/proxy_client.h
Normal 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_ */
|
||||
@@ -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_ */
|
||||
39
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/scan.h
Normal file
39
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/scan.h
Normal 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_ */
|
||||
79
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/settings.h
Normal file
79
tools/sdk/esp32/include/bt/esp_ble_mesh/mesh_core/settings.h
Normal 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_ */
|
||||
@@ -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_ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user