Merge branch 'feat/ble_mesh_4_1_new_features_v4.0' into 'release/v4.0'

ESP BLE Mesh new features (v4.0)

See merge request espressif/esp-idf!6698
This commit is contained in:
Jiang Jiang Jian 2019-11-14 16:48:44 +08:00
commit 2b208eecde
185 changed files with 23935 additions and 4212 deletions

View file

@ -298,12 +298,14 @@ if(CONFIG_BT_ENABLED)
if(CONFIG_BLE_MESH)
list(APPEND include_dirs
"esp_ble_mesh/mesh_common/include"
"esp_ble_mesh/mesh_core"
"esp_ble_mesh/mesh_core/include"
"esp_ble_mesh/mesh_core/settings"
"esp_ble_mesh/mesh_core/storage"
"esp_ble_mesh/btc/include"
"esp_ble_mesh/mesh_models/common/include"
"esp_ble_mesh/mesh_models/client/include"
"esp_ble_mesh/mesh_models/server/include"
"esp_ble_mesh/api/core/include"
"esp_ble_mesh/api/models/include"
"esp_ble_mesh/api")
@ -327,7 +329,13 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/btc/btc_ble_mesh_prov.c"
"esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c"
"esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c"
"esp_ble_mesh/mesh_core/settings/settings_nvs.c"
"esp_ble_mesh/mesh_common/mesh_aes_encrypt.c"
"esp_ble_mesh/mesh_common/mesh_atomic.c"
"esp_ble_mesh/mesh_common/mesh_buf.c"
"esp_ble_mesh/mesh_common/mesh_common.c"
"esp_ble_mesh/mesh_common/mesh_kernel.c"
"esp_ble_mesh/mesh_common/mesh_util.c"
"esp_ble_mesh/mesh_core/storage/settings_nvs.c"
"esp_ble_mesh/mesh_core/access.c"
"esp_ble_mesh/mesh_core/adv.c"
"esp_ble_mesh/mesh_core/beacon.c"
@ -338,28 +346,30 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/mesh_core/health_cli.c"
"esp_ble_mesh/mesh_core/health_srv.c"
"esp_ble_mesh/mesh_core/lpn.c"
"esp_ble_mesh/mesh_core/mesh_aes_encrypt.c"
"esp_ble_mesh/mesh_core/mesh_atomic.c"
"esp_ble_mesh/mesh_core/mesh_buf.c"
"esp_ble_mesh/mesh_core/mesh_kernel.c"
"esp_ble_mesh/mesh_core/mesh_main.c"
"esp_ble_mesh/mesh_core/mesh_util.c"
"esp_ble_mesh/mesh_core/main.c"
"esp_ble_mesh/mesh_core/net.c"
"esp_ble_mesh/mesh_core/prov.c"
"esp_ble_mesh/mesh_core/provisioner_beacon.c"
"esp_ble_mesh/mesh_core/provisioner_main.c"
"esp_ble_mesh/mesh_core/provisioner_prov.c"
"esp_ble_mesh/mesh_core/provisioner_proxy.c"
"esp_ble_mesh/mesh_core/proxy.c"
"esp_ble_mesh/mesh_core/proxy_client.c"
"esp_ble_mesh/mesh_core/proxy_server.c"
"esp_ble_mesh/mesh_core/settings.c"
"esp_ble_mesh/mesh_core/test.c"
"esp_ble_mesh/mesh_core/transport.c"
"esp_ble_mesh/mesh_models/common/mesh_common.c"
"esp_ble_mesh/mesh_models/client/client_common.c"
"esp_ble_mesh/mesh_models/client/generic_client.c"
"esp_ble_mesh/mesh_models/client/lighting_client.c"
"esp_ble_mesh/mesh_models/client/sensor_client.c"
"esp_ble_mesh/mesh_models/client/time_scene_client.c")
"esp_ble_mesh/mesh_models/client/time_scene_client.c"
"esp_ble_mesh/mesh_models/server/device_property.c"
"esp_ble_mesh/mesh_models/server/generic_server.c"
"esp_ble_mesh/mesh_models/server/lighting_server.c"
"esp_ble_mesh/mesh_models/server/sensor_server.c"
"esp_ble_mesh/mesh_models/server/server_common.c"
"esp_ble_mesh/mesh_models/server/state_binding.c"
"esp_ble_mesh/mesh_models/server/state_transition.c"
"esp_ble_mesh/mesh_models/server/time_scene_server.c")
endif()
if(CONFIG_BT_NIMBLE_ENABLED)

View file

@ -126,6 +126,10 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_LIGHTING_CLIENT] = {btc_ble_mesh_lighting_client_call_handler, btc_ble_mesh_lighting_client_cb_handler },
[BTC_PID_SENSOR_CLIENT] = {btc_ble_mesh_sensor_client_call_handler, btc_ble_mesh_sensor_client_cb_handler },
[BTC_PID_TIME_SCENE_CLIENT] = {btc_ble_mesh_time_scene_client_call_handler, btc_ble_mesh_time_scene_client_cb_handler},
[BTC_PID_GENERIC_SERVER] = {NULL, btc_ble_mesh_generic_server_cb_handler },
[BTC_PID_LIGHTING_SERVER] = {NULL, btc_ble_mesh_lighting_server_cb_handler },
[BTC_PID_SENSOR_SERVER] = {NULL, btc_ble_mesh_sensor_server_cb_handler },
[BTC_PID_TIME_SCENE_SERVER] = {NULL, btc_ble_mesh_time_scene_server_cb_handler},
#endif /* #if CONFIG_BLE_MESH */
};

View file

@ -78,6 +78,10 @@ typedef enum {
BTC_PID_LIGHTING_CLIENT,
BTC_PID_SENSOR_CLIENT,
BTC_PID_TIME_SCENE_CLIENT,
BTC_PID_GENERIC_SERVER,
BTC_PID_LIGHTING_SERVER,
BTC_PID_SENSOR_SERVER,
BTC_PID_TIME_SCENE_SERVER,
#endif /* CONFIG_BLE_MESH */
BTC_PID_NUM,
} btc_pid_t; //btc profile id

View file

@ -137,22 +137,25 @@ endif
endif
ifdef CONFIG_BLE_MESH
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_core \
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_common/include \
esp_ble_mesh/mesh_core \
esp_ble_mesh/mesh_core/include \
esp_ble_mesh/mesh_core/settings \
esp_ble_mesh/mesh_core/storage \
esp_ble_mesh/btc/include \
esp_ble_mesh/mesh_models/common/include \
esp_ble_mesh/mesh_models/client/include \
esp_ble_mesh/mesh_models/server/include \
esp_ble_mesh/api/core/include \
esp_ble_mesh/api/models/include \
esp_ble_mesh/api
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core \
esp_ble_mesh/mesh_core/settings \
esp_ble_mesh/btc \
esp_ble_mesh/mesh_models/common \
esp_ble_mesh/mesh_models/client \
esp_ble_mesh/api/core \
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_common \
esp_ble_mesh/mesh_core \
esp_ble_mesh/mesh_core/storage \
esp_ble_mesh/btc \
esp_ble_mesh/mesh_models/client \
esp_ble_mesh/mesh_models/server \
esp_ble_mesh/api/core \
esp_ble_mesh/api/models
endif

View file

@ -60,7 +60,7 @@ if BLE_MESH
config BLE_MESH_MAX_STORED_NODES
int "Maximum number of nodes whose information can be stored"
default 20
range 1 1000
range BLE_MESH_MAX_PROV_NODES 1000
help
This option specifies the maximum number of nodes whose information can be
stored by a Provisioner in its upper layer.
@ -71,7 +71,7 @@ if BLE_MESH
config BLE_MESH_MAX_PROV_NODES
int "Maximum number of devices that can be provisioned by Provisioner"
default 20
range 1 100
range 1 1000
help
This option specifies how many devices can be provisioned by a Provisioner.
This value indicates the maximum number of unprovisioned devices which can be
@ -158,17 +158,28 @@ if BLE_MESH
Enable this option to support BLE Mesh Proxy protocol used by PB-GATT
and other proxy pdu transmission.
config BLE_MESH_GATT_PROXY
bool "BLE Mesh GATT Proxy Service"
config BLE_MESH_GATT_PROXY_SERVER
bool "BLE Mesh GATT Proxy Server"
select BLE_MESH_PROXY
depends on BLE_MESH_NODE
default y
help
This option enables support for Mesh GATT Proxy Service, i.e. the
ability to act as a proxy between a Mesh GATT Client and a Mesh network.
This option should be enabled if a node is going to be a Proxy Server.
config BLE_MESH_GATT_PROXY_CLIENT
bool "BLE Mesh GATT Proxy Client"
select BLE_MESH_PROXY
default n
help
This option enables support for Mesh GATT Proxy Client. The Proxy Client
can use the GATT bearer to send mesh messages to a node that supports the
advertising bearer.
config BLE_MESH_NODE_ID_TIMEOUT
int "Node Identity advertising timeout"
depends on BLE_MESH_GATT_PROXY
depends on BLE_MESH_GATT_PROXY_SERVER
range 1 60
default 60
help
@ -185,7 +196,7 @@ if BLE_MESH
config BLE_MESH_PROXY_FILTER_SIZE
int "Maximum number of filter entries per Proxy Client"
default 1
default 3 if BLE_MESH_GATT_PROXY
default 3 if BLE_MESH_GATT_PROXY_SERVER
range 1 32767
help
This option specifies how many Proxy Filter entries the local node supports.
@ -416,14 +427,39 @@ if BLE_MESH
config BLE_MESH_RELAY
bool "Relay support"
depends on BLE_MESH_NODE
default y
help
Support for acting as a Mesh Relay Node. Enabling this option will allow
a node to support the Relay feature, and the Relay feature can still
be enabled or disabled by proper configuration messages. Disabling this
option will let a node not support the Relay feature.
if BLE_MESH_RELAY
config BLE_MESH_RELAY_ADV_BUF
bool "Use separate advertising buffers for relay packets"
default n
help
When selected, self-send packets will be put in a high-priority
queue and relay packets will be put in a low-priority queue.
if BLE_MESH_RELAY_ADV_BUF
config BLE_MESH_RELAY_ADV_BUF_COUNT
int "Number of advertising buffers for relay packets"
default 60
range 6 256
help
Number of advertising buffers for relay packets available.
endif # BLE_MESH_RELAY_ADV_BUF
endif # BLE_MESH_RELAY
config BLE_MESH_LOW_POWER
bool "Support for Low Power features"
depends on BLE_MESH_NODE
help
Enable this option to operate as a Low Power Node. If low power consumption
is required by a node, this option should be enabled. And once the node
@ -434,7 +470,7 @@ if BLE_MESH
config BLE_MESH_LPN_ESTABLISHMENT
bool "Perform Friendship establishment using low power"
default y
default n
help
Perform the Friendship establishment using low power with the help of a
reduced scan duty cycle. The downside of this is that the node may miss
@ -446,7 +482,7 @@ if BLE_MESH
config BLE_MESH_LPN_AUTO
bool "Automatically start looking for Friend nodes once provisioned"
default y
default n
help
Once provisioned, automatically enable LPN functionality and start looking
for Friend nodes. If this option is disabled LPN mode needs to be manually
@ -465,8 +501,8 @@ if BLE_MESH
before starting to look for Friend nodes.
config BLE_MESH_LPN_RETRY_TIMEOUT
int "Retry timeout for Friend Requests"
default 8
int "Retry timeout for Friend requests"
default 6
range 1 3600
help
Time in seconds between Friend Requests, if a previous Friend Request did
@ -555,6 +591,7 @@ if BLE_MESH
config BLE_MESH_FRIEND
bool "Support for acting as a Friend Node"
depends on BLE_MESH_NODE
help
Enable this option to be able to act as a Friend Node.
@ -689,16 +726,6 @@ if BLE_MESH
endmenu #BLE Mesh NET BUF DEBUG LOG LEVEL
config BLE_MESH_IRQ_LOCK
bool "Used the IRQ lock instead of task lock"
help
To improve the real-time requirements of bt controller in BLE Mesh,
task lock is used to replace IRQ lock.
With this option enabled, interrupt lock instead of the mutex will
be used and the BLE Mesh stack will try to change interrupt level to
protect some critical situations. Users need to ensure that this option
is disabled so mutex will be used in the bottom layer.
config BLE_MESH_CLIENT_MSG_TIMEOUT
int "Timeout(ms) for client message response"
range 100 1200000

View file

@ -15,10 +15,51 @@
#include <stdint.h>
#include "btc/btc_task.h"
#include "btc/btc_manage.h"
#include "esp_err.h"
#include "btc_ble_mesh_prov.h"
#include "esp_ble_mesh_defs.h"
esp_err_t esp_ble_mesh_lpn_enable(void)
{
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_LPN_ENABLE;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_lpn_disable(bool force)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_LPN_DISABLE;
arg.lpn_disable.force = force;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_lpn_poll(void)
{
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_LPN_POLL;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -25,13 +25,13 @@
#define ESP_BLE_MESH_TX_SDU_MAX ((CONFIG_BLE_MESH_ADV_BUF_COUNT - 3) * 12)
static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
esp_ble_mesh_msg_ctx_t *ctx,
uint32_t opcode,
btc_ble_mesh_model_act_t act,
uint16_t length, uint8_t *data,
int32_t msg_timeout, bool need_rsp,
esp_ble_mesh_dev_role_t device_role)
static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
esp_ble_mesh_msg_ctx_t *ctx,
uint32_t opcode,
btc_ble_mesh_model_act_t act,
uint16_t length, uint8_t *data,
int32_t msg_timeout, bool need_rsp,
esp_ble_mesh_dev_role_t device_role)
{
btc_ble_mesh_model_args_t arg = {0};
uint8_t op_len = 0, mic_len = 0;
@ -41,7 +41,13 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
if (ctx && ctx->addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
LOG_ERROR("%s, Invalid destination address 0x0000", __func__);
return ESP_ERR_INVALID_ARG;
}
if (device_role > ROLE_FAST_PROV) {
LOG_ERROR("%s, Invalid device role 0x%02x", __func__, device_role);
return ESP_ERR_INVALID_ARG;
}
@ -106,7 +112,7 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
arg.model_send.msg_timeout = msg_timeout;
}
status = (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_prov_arg_deep_copy)
status = (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_model_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
osi_free(msg_data);
@ -165,8 +171,8 @@ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
if (!model || !ctx) {
return ESP_ERR_INVALID_ARG;
}
return ble_mesh_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
length, data, 0, false, ROLE_NODE);
return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
length, data, 0, false, ROLE_NODE);
}
esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model,
@ -177,8 +183,8 @@ esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model,
if (!model || !ctx) {
return ESP_ERR_INVALID_ARG;
}
return ble_mesh_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
length, data, msg_timeout, need_rsp, device_role);
return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
length, data, msg_timeout, need_rsp, device_role);
}
esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcode,
@ -188,8 +194,33 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod
if (!model || !model->pub || !model->pub->msg) {
return ESP_ERR_INVALID_ARG;
}
return ble_mesh_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH,
length, data, 0, false, device_role);
return ble_mesh_model_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH,
length, data, 0, false, device_role);
}
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)
{
btc_ble_mesh_model_args_t arg = {0};
btc_msg_t msg = {0};
if (!model || !value || type >= ESP_BLE_MESH_SERVER_MODEL_STATE_MAX) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
arg.model_update_state.model = model;
arg.model_update_state.type = type;
arg.model_update_state.value = value;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MODEL;
msg.act = BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_model_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_node_local_reset(void)

View file

@ -70,7 +70,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers)
}
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])
uint8_t private_key[32])
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
@ -157,7 +157,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name)
#if (CONFIG_BLE_MESH_PROVISIONER)
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])
uint8_t pub_key_y[32])
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};

View file

@ -61,3 +61,117 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void)
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (!addr || addr_type > ESP_BLE_MESH_ADDR_TYPE_RANDOM) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_CONNECT;
memcpy(arg.proxy_client_connect.addr, addr, BD_ADDR_LEN);
arg.proxy_client_connect.addr_type = addr_type;
arg.proxy_client_connect.net_idx = net_idx;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_DISCONNECT;
arg.proxy_client_disconnect.conn_handle = conn_handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (filter_type > PROXY_FILTER_BLACKLIST) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE;
arg.proxy_client_set_filter_type.conn_handle = conn_handle;
arg.proxy_client_set_filter_type.net_idx = net_idx;
arg.proxy_client_set_filter_type.filter_type = filter_type;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (!addr || addr_num == 0) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR;
arg.proxy_client_add_filter_addr.conn_handle = conn_handle;
arg.proxy_client_add_filter_addr.net_idx = net_idx;
arg.proxy_client_add_filter_addr.addr_num = addr_num;
arg.proxy_client_add_filter_addr.addr = addr;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (!addr || addr_num == 0) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR;
arg.proxy_client_remove_filter_addr.conn_handle = conn_handle;
arg.proxy_client_remove_filter_addr.net_idx = net_idx;
arg.proxy_client_remove_filter_addr.addr_num = addr_num;
arg.proxy_client_remove_filter_addr.addr = addr;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -17,4 +17,45 @@
#include "esp_ble_mesh_defs.h"
/**
* @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);
#endif /* _ESP_BLE_MESH_LOW_POWER_API_H_ */

View file

@ -134,6 +134,25 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod
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.
*

View file

@ -72,7 +72,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers);
* @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]);
uint8_t private_key[32]);
/**
* @brief Provide provisioning input OOB number.
@ -124,7 +124,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name);
* @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]);
uint8_t pub_key_y[32]);
/**
* @brief Provide provisioning input OOB string.

View file

@ -49,5 +49,70 @@ esp_err_t esp_ble_mesh_proxy_gatt_enable(void);
*/
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);
#endif /* _ESP_BLE_MESH_PROXY_API_H_ */

File diff suppressed because it is too large Load diff

View file

@ -70,3 +70,10 @@ esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_generic_client_args_t), btc_ble_mesh_generic_client_arg_deep_copy)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_register_generic_server_callback(esp_ble_mesh_generic_server_cb_t callback)
{
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_GENERIC_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
}

View file

@ -83,12 +83,16 @@ esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element)
btc_ble_mesh_health_server_args_t arg = {0};
btc_msg_t msg = {0};
if (element == NULL) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_HEALTH_SERVER;
msg.act = BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE;
arg.fault_update.element = element;
arg.health_fault_update.element = element;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_health_server_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);

View file

@ -71,3 +71,9 @@ esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_register_lighting_server_callback(esp_ble_mesh_lighting_server_cb_t callback)
{
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_LIGHTING_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
}

View file

@ -71,3 +71,11 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_register_sensor_server_callback(esp_ble_mesh_sensor_server_cb_t callback)
{
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_SENSOR_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
}

View file

@ -71,3 +71,10 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_register_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_t callback)
{
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_TIME_SCENE_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
}

View file

@ -79,8 +79,8 @@ typedef struct esp_ble_mesh_cfg_srv {
uint8_t min_hops; /*!< Minimum hops when receiving Heartbeat messages */
uint8_t max_hops; /*!< Maximum hops when receiving Heartbeat messages */
/** Optional subscription tracking function */
void (*func)(uint8_t hops, uint16_t feature);
/** Optional heartbeat subscription tracking function */
esp_ble_mesh_cb_t heartbeat_recv_cb;
} heartbeat_sub;
} esp_ble_mesh_cfg_srv_t;
@ -513,8 +513,8 @@ typedef struct {
/** 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 */
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 */
@ -610,28 +610,135 @@ typedef enum {
ESP_BLE_MESH_CFG_CLIENT_EVT_MAX,
} esp_ble_mesh_cfg_client_cb_event_t;
/** Parameter of Config AppKey Add */
/**
* @brief Configuration Server model related context.
*/
typedef struct {
uint16_t app_idx; /*!< AppKey Index of the Config AppKey Add */
} esp_ble_mesh_cfg_srv_app_key_add_cb_t;
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 received message union
* @brief Configuration Server model state change value union
*/
typedef union {
esp_ble_mesh_cfg_srv_app_key_add_cb_t app_key_add; /*!< The Config AppKey Add event value */
} esp_ble_mesh_cfg_server_common_cb_param_t;
/**
* 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;
/** Configuration Server Model callback parameters */
/**
* @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; /*!< The context of the received message */
esp_ble_mesh_cfg_server_common_cb_param_t status_cb; /*!< The received configuration message callback values */
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 */
/** This enum value is the event of Configuration Server model */
typedef enum {
ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT,
ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT,
ESP_BLE_MESH_CFG_SERVER_EVT_MAX,
} esp_ble_mesh_cfg_server_cb_event_t;

View file

@ -523,6 +523,775 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param
esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_generic_client_set_state_t *set_state);
/**
* @brief Generic Server Models related context.
*/
/** @def ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV
*
* @brief Define a new Generic OnOff Server Model.
*
* @note 1. The Generic OnOff Server Model is a root 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_gen_onoff_srv_t.
*
* @return New Generic OnOff Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_LEVEL_SRV
*
* @brief Define a new Generic Level Server Model.
*
* @note 1. The Generic Level Server Model is a root 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_gen_level_srv_t.
*
* @return New Generic Level Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_LEVEL_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_SRV
*
* @brief Define a new Generic Default Transition Time Server Model.
*
* @note 1. The Generic Default Transition Time Server Model is a root 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_gen_def_trans_time_srv_t.
*
* @return New Generic Default Transition Time Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SRV
*
* @brief Define a new Generic Power OnOff Server Model.
*
* @note 1. The Generic Power OnOff Server model extends the Generic OnOff Server
* model. When this model is present on an element, the corresponding
* Generic Power OnOff Setup Server model shall also be present.
* 2. This model may be used to represent a variety of devices that do not
* fit any of the model descriptions that have been defined but support
* the generic properties of On/Off.
* 3. 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_gen_power_onoff_srv_t.
*
* @return New Generic Power OnOff Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SETUP_SRV
*
* @brief Define a new Generic Power OnOff Setup Server Model.
*
* @note 1. The Generic Power OnOff Setup Server model extends the Generic Power
* OnOff Server model and the Generic Default Transition Time Server model.
* 2. This model shall support 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_gen_power_onoff_setup_srv_t.
*
* @return New Generic Power OnOff Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SRV
*
* @brief Define a new Generic Power Level Server Model.
*
* @note 1. The Generic Power Level Server model extends the Generic Power OnOff
* Server model and the Generic Level Server model. When this model is
* present on an Element, the corresponding Generic Power Level 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_gen_power_level_srv_t.
*
* @return New Generic Power Level Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SETUP_SRV
*
* @brief Define a new Generic Power Level Setup Server Model.
*
* @note 1. The Generic Power Level Setup Server model extends the Generic Power
* Level Server model and the Generic Power OnOff Setup Server model.
* 2. This model shall support 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_gen_power_level_setup_srv_t.
*
* @return New Generic Power Level Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_BATTERY_SRV
*
* @brief Define a new Generic Battery Server Model.
*
* @note 1. The Generic Battery Server Model is a root model.
* 2. This model shall support model publication and model subscription.
* 3. The model may be used to represent an element that is powered by a battery.
*
* @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_gen_battery_srv_t.
*
* @return New Generic Battery Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_BATTERY_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_LOCATION_SRV
*
* @brief Define a new Generic Location Server Model.
*
* @note 1. The Generic Location Server model is a root model. When this model
* is present on an Element, the corresponding Generic Location Setup
* Server model shall also be present.
* 2. This model shall support model publication and model subscription.
* 3. The model may be used to represent an element that knows its
* location (global or local).
*
* @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_gen_location_srv_t.
*
* @return New Generic Location Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_LOCATION_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_LOCATION_SETUP_SRV
*
* @brief Define a new Generic Location Setup Server Model.
*
* @note 1. The Generic Location Setup Server model extends the Generic Location
* Server model.
* 2. This model shall support 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_gen_location_setup_srv_t.
*
* @return New Generic Location Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_LOCATION_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_USER_PROP_SRV
*
* @brief Define a new Generic User Property Server Model.
*
* @note 1. The Generic User Property Server model is a root 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_gen_user_prop_srv_t.
*
* @return New Generic User Property Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_USER_PROP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_ADMIN_PROP_SRV
*
* @brief Define a new Generic Admin Property Server Model.
*
* @note 1. The Generic Admin Property Server model extends the Generic User
* Property 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_gen_admin_prop_srv_t.
*
* @return New Generic Admin Property Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_ADMIN_PROP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_MANUFACTURER_PROP_SRV
*
* @brief Define a new Generic Manufacturer Property Server Model.
*
* @note 1. The Generic Manufacturer Property Server model extends the Generic
* User Property 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_gen_manu_prop_srv_t.
*
* @return New Generic Manufacturer Property Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_MANUFACTURER_PROP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_GEN_CLIENT_PROP_SRV
*
* @brief Define a new Generic User Property Server Model.
*
* @note 1. The Generic Client Property Server model is a root 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_gen_client_prop_srv_t.
*
* @return New Generic Client Property Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_GEN_CLIENT_PROP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, \
NULL, srv_pub, srv_data)
/** Parameters of Generic OnOff state */
typedef struct {
uint8_t onoff; /*!< The present value of the Generic OnOff state */
uint8_t target_onoff; /*!< The target value of the Generic OnOff state */
} esp_ble_mesh_gen_onoff_state_t;
/** User data of Generic OnOff Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic OnOff Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_gen_onoff_state_t state; /*!< Parameters of the Generic OnOff 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_gen_onoff_srv_t;
/** Parameters of Generic Level state */
typedef struct {
int16_t level; /*!< The present value of the Generic Level state */
int16_t target_level; /*!< The target value of the Generic Level state */
/**
* When a new transaction starts, level should be set to last_last, and use
* "level + incoming delta" to calculate the target level. In another word,
* "last_level" is used to record "level" of the last transaction, and
* "last_delta" is used to record the previously received delta_level value.
*/
int16_t last_level; /*!< The last value of the Generic Level state */
int32_t last_delta; /*!< The last delta change of the Generic Level state */
bool move_start; /*!< Indicate if the transition of the Generic Level state has been started */
bool positive; /*!< Indicate if the transition is positive or negative */
} esp_ble_mesh_gen_level_state_t;
/** User data of Generic Level Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Level Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_gen_level_state_t state; /*!< Parameters of the Generic Level 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 */
int32_t tt_delta_level; /*!< Delta change value of level state transition */
} esp_ble_mesh_gen_level_srv_t;
/** Parameter of Generic Default Transition Time state */
typedef struct {
uint8_t trans_time; /*!< The value of the Generic Default Transition Time state */
} esp_ble_mesh_gen_def_trans_time_state_t;
/** User data of Generic Default Transition Time Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Default Transition 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_gen_def_trans_time_state_t state; /*!< Parameters of the Generic Default Transition Time state */
} esp_ble_mesh_gen_def_trans_time_srv_t;
/** Parameter of Generic OnPowerUp state */
typedef struct {
uint8_t onpowerup; /*!< The value of the Generic OnPowerUp state */
} esp_ble_mesh_gen_onpowerup_state_t;
/** User data of Generic Power OnOff Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power OnOff Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_gen_onpowerup_state_t *state; /*!< Parameters of the Generic OnPowerUp state */
} esp_ble_mesh_gen_power_onoff_srv_t;
/** User data of Generic Power OnOff Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power OnOff 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_gen_onpowerup_state_t *state; /*!< Parameters of the Generic OnPowerUp state */
} esp_ble_mesh_gen_power_onoff_setup_srv_t;
/** Parameters of Generic Power Level state */
typedef struct {
uint16_t power_actual; /*!< The present value of the Generic Power Actual state */
uint16_t target_power_actual; /*!< The target value of the Generic Power Actual state */
uint16_t power_last; /*!< The value of the Generic Power Last state */
uint16_t power_default; /*!< The value of the Generic Power Default state */
uint8_t status_code; /*!< The status code of setting Generic Power Range state */
uint16_t power_range_min; /*!< The minimum value of the Generic Power Range state */
uint16_t power_range_max; /*!< The maximum value of the Generic Power Range state */
} esp_ble_mesh_gen_power_level_state_t;
/** User data of Generic Power Level Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power Level Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_gen_power_level_state_t *state; /*!< Parameters of the Generic Power Level 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 */
int32_t tt_delta_level; /*!< Delta change value of level state transition */
} esp_ble_mesh_gen_power_level_srv_t;
/** User data of Generic Power Level Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power Level 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_gen_power_level_state_t *state; /*!< Parameters of the Generic Power Level state */
} esp_ble_mesh_gen_power_level_setup_srv_t;
/** Parameters of Generic Battery state */
typedef struct {
uint32_t battery_level : 8, /*!< The value of the Generic Battery Level state */
time_to_discharge : 24; /*!< The value of the Generic Battery Time to Discharge state */
uint32_t time_to_charge : 24, /*!< The value of the Generic Battery Time to Charge state */
battery_flags : 8; /*!< The value of the Generic Battery Flags state */
} esp_ble_mesh_gen_battery_state_t;
/** User data of Generic Battery Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Battery Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_gen_battery_state_t state; /*!< Parameters of the Generic Battery state */
} esp_ble_mesh_gen_battery_srv_t;
/** Parameters of Generic Location state */
typedef struct {
int32_t global_latitude; /*!< The value of the Global Latitude field */
int32_t global_longitude; /*!< The value of the Global Longtitude field */
int16_t global_altitude; /*!< The value of the Global Altitude field */
int16_t local_north; /*!< The value of the Local North field */
int16_t local_east; /*!< The value of the Local East field */
int16_t local_altitude; /*!< The value of the Local Altitude field */
uint8_t floor_number; /*!< The value of the Floor Number field */
uint16_t uncertainty; /*!< The value of the Uncertainty field */
} esp_ble_mesh_gen_location_state_t;
/** User data of Generic Location Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Location Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
esp_ble_mesh_gen_location_state_t *state; /*!< Parameters of the Generic Location state */
} esp_ble_mesh_gen_location_srv_t;
/** User data of Generic Location Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Location 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_gen_location_state_t *state; /*!< Parameters of the Generic Location state */
} esp_ble_mesh_gen_location_setup_srv_t;
/** This enum value is the access vlue of Generic User Property */
typedef enum {
ESP_BLE_MESH_GEN_USER_ACCESS_PROHIBIT,
ESP_BLE_MESH_GEN_USER_ACCESS_READ,
ESP_BLE_MESH_GEN_USER_ACCESS_WRITE,
ESP_BLE_MESH_GEN_USER_ACCESS_READ_WRITE,
} esp_ble_mesh_gen_user_prop_access_t;
/** This enum value is the access value of Generic Admin Property */
typedef enum {
ESP_BLE_MESH_GEN_ADMIN_NOT_USER_PROP,
ESP_BLE_MESH_GEN_ADMIN_ACCESS_READ,
ESP_BLE_MESH_GEN_ADMIN_ACCESS_WRITE,
ESP_BLE_MESH_GEN_ADMIN_ACCESS_READ_WRITE,
} esp_ble_mesh_gen_admin_prop_access_t;
/** This enum value is the access value of Generic Manufacturer Property */
typedef enum {
ESP_BLE_MESH_GEN_MANU_NOT_USER_PROP,
ESP_BLE_MESH_GEN_MANU_ACCESS_READ,
} esp_ble_mesh_gen_manu_prop_access_t;
/** Parameters of Generic Property states */
typedef struct {
uint16_t id; /*!< The value of User/Admin/Manufacturer Property ID */
uint8_t user_access; /*!< The value of User Access field */
uint8_t admin_access; /*!< The value of Admin Access field */
uint8_t manu_access; /*!< The value of Manufacturer Access field */
struct net_buf_simple *val; /*!< The value of User/Admin/Manufacturer Property */
} esp_ble_mesh_generic_property_t;
/** User data of Generic User Property Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic User Property Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
uint8_t property_count; /*!< Generic User Property count */
esp_ble_mesh_generic_property_t *properties; /*!< Parameters of the Generic User Property state */
} esp_ble_mesh_gen_user_prop_srv_t;
/** User data of Generic Admin Property Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Admin Property Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
uint8_t property_count; /*!< Generic Admin Property count */
esp_ble_mesh_generic_property_t *properties; /*!< Parameters of the Generic Admin Property state */
} esp_ble_mesh_gen_admin_prop_srv_t;
/** User data of Generic Manufacturer Property Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Manufacturer Property Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
uint8_t property_count; /*!< Generic Manufacturer Property count */
esp_ble_mesh_generic_property_t *properties; /*!< Parameters of the Generic Manufacturer Property state */
} esp_ble_mesh_gen_manu_prop_srv_t;
/** User data of Generic Client Property Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Client Property Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
uint8_t id_count; /*!< Generic Client Property ID count */
uint16_t *property_ids; /*!< Parameters of the Generic Client Property state */
} esp_ble_mesh_gen_client_prop_srv_t;
/** Parameter of Generic OnOff Set state change event */
typedef struct {
uint8_t onoff; /*!< The value of Generic OnOff state */
} esp_ble_mesh_state_change_gen_onoff_set_t;
/** Parameter of Generic Level Set state change event */
typedef struct {
int16_t level; /*!< The value of Generic Level state */
} esp_ble_mesh_state_change_gen_level_set_t;
/** Parameter of Generic Delta Set state change event */
typedef struct {
int16_t level; /*!< The value of Generic Level state */
} esp_ble_mesh_state_change_gen_delta_set_t;
/** Parameter of Generic Move Set state change event */
typedef struct {
int16_t level; /*!< The value of Generic Level state */
} esp_ble_mesh_state_change_gen_move_set_t;
/** Parameter of Generic Default Transition Time Set state change event */
typedef struct {
uint8_t trans_time; /*!< The value of Generic Default Transition Time state */
} esp_ble_mesh_state_change_gen_def_trans_time_set_t;
/** Parameter of Generic OnPowerUp Set state change event */
typedef struct {
uint8_t onpowerup; /*!< The value of Generic OnPowerUp state */
} esp_ble_mesh_state_change_gen_onpowerup_set_t;
/** Parameter of Generic Power Level Set state change event */
typedef struct {
uint16_t power; /*!< The value of Generic Power Actual state */
} esp_ble_mesh_state_change_gen_power_level_set_t;
/** Parameter of Generic Power Default Set state change event */
typedef struct {
uint16_t power; /*!< The value of Generic Power Default state */
} esp_ble_mesh_state_change_gen_power_default_set_t;
/** Parameters of Generic Power Range Set state change event */
typedef struct {
uint16_t range_min; /*!< The minimum value of Generic Power Range state */
uint16_t range_max; /*!< The maximum value of Generic Power Range state */
} esp_ble_mesh_state_change_gen_power_range_set_t;
/** Parameters of Generic Location Global Set state change event */
typedef struct {
int32_t latitude; /*!< The Global Latitude value of Generic Location state */
int32_t longitude; /*!< The Global Longitude value of Generic Location state */
int16_t altitude; /*!< The Global Altitude value of Generic Location state */
} esp_ble_mesh_state_change_gen_loc_global_set_t;
/** Parameters of Generic Location Local Set state change event */
typedef struct {
int16_t north; /*!< The Local North value of Generic Location state */
int16_t east; /*!< The Local East value of Generic Location state */
int16_t altitude; /*!< The Local Altitude value of Generic Location state */
uint8_t floor_number; /*!< The Floor Number value of Generic Location state */
uint16_t uncertainty; /*!< The Uncertainty value of Generic Location state */
} esp_ble_mesh_state_change_gen_loc_local_set_t;
/** Parameters of Generic User Property Set state change event */
typedef struct {
uint16_t id; /*!< The property id of Generic User Property state */
struct net_buf_simple *value; /*!< The property value of Generic User Property state */
} esp_ble_mesh_state_change_gen_user_property_set_t;
/** Parameters of Generic Admin Property Set state change event */
typedef struct {
uint16_t id; /*!< The property id of Generic Admin Property state */
uint8_t access; /*!< The property access of Generic Admin Property state */
struct net_buf_simple *value; /*!< The property value of Generic Admin Property state */
} esp_ble_mesh_state_change_gen_admin_property_set_t;
/** Parameters of Generic Manufacturer Property Set state change event */
typedef struct {
uint16_t id; /*!< The property id of Generic Manufacturer Property state */
uint8_t access; /*!< The property value of Generic Manufacturer Property state */
} esp_ble_mesh_state_change_gen_manu_property_set_t;
/**
* @brief Generic 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_gen_onoff_set_t onoff_set; /*!< Generic OnOff Set */
esp_ble_mesh_state_change_gen_level_set_t level_set; /*!< Generic Level Set */
esp_ble_mesh_state_change_gen_delta_set_t delta_set; /*!< Generic Delta Set */
esp_ble_mesh_state_change_gen_move_set_t move_set; /*!< Generic Move Set */
esp_ble_mesh_state_change_gen_def_trans_time_set_t def_trans_time_set; /*!< Generic Default Transition Time Set */
esp_ble_mesh_state_change_gen_onpowerup_set_t onpowerup_set; /*!< Generic OnPowerUp Set */
esp_ble_mesh_state_change_gen_power_level_set_t power_level_set; /*!< Generic Power Level Set */
esp_ble_mesh_state_change_gen_power_default_set_t power_default_set; /*!< Generic Power Default Set */
esp_ble_mesh_state_change_gen_power_range_set_t power_range_set; /*!< Generic Power Range Set */
esp_ble_mesh_state_change_gen_loc_global_set_t loc_global_set; /*!< Generic Location Global Set */
esp_ble_mesh_state_change_gen_loc_local_set_t loc_local_set; /*!< Generic Location Local Set */
esp_ble_mesh_state_change_gen_user_property_set_t user_property_set; /*!< Generic User Property Set */
esp_ble_mesh_state_change_gen_admin_property_set_t admin_property_set; /*!< Generic Admin Property Set */
esp_ble_mesh_state_change_gen_manu_property_set_t manu_property_set; /*!< Generic Manufactuer Property Set */
} esp_ble_mesh_generic_server_state_change_t;
/** Context of the received Generic User Property Get message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a Generic User Property */
} esp_ble_mesh_server_recv_gen_user_property_get_t;
/** Context of the received Generic Admin Property Get message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a Generic Admin Property */
} esp_ble_mesh_server_recv_gen_admin_property_get_t;
/** Context of the received Generic Manufacturer Property message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a Generic Manufacturer Property */
} esp_ble_mesh_server_recv_gen_manufacturer_property_get_t;
/** Context of the received Generic Client Properties Get message */
typedef struct {
uint16_t property_id; /*!< A starting Client Property ID present within an element */
} esp_ble_mesh_server_recv_gen_client_properties_get_t;
/**
* @brief Generic Server Model received get message union
*/
typedef union {
esp_ble_mesh_server_recv_gen_user_property_get_t user_property; /*!< Generic User Property Get */
esp_ble_mesh_server_recv_gen_admin_property_get_t admin_property; /*!< Generic Admin Property Get */
esp_ble_mesh_server_recv_gen_manufacturer_property_get_t manu_property; /*!< Generic Manufacturer Property Get */
esp_ble_mesh_server_recv_gen_client_properties_get_t client_properties; /*!< Generic Client Properties Get */
} esp_ble_mesh_generic_server_recv_get_msg_t;
/** Context of the received Generic OnOff Set message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint8_t onoff; /*!< Target value of Generic OnOff state */
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_gen_onoff_set_t;
/** Context of the received Generic Level Set message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
int16_t level; /*!< Target value of Generic Level state */
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_gen_level_set_t;
/** Context of the received Generic Delta Set message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
int32_t delta_level; /*!< Delta change of Generic Level state */
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_gen_delta_set_t;
/** Context of the received Generic Move Set message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
int16_t delta_level; /*!< Delta Level step to calculate Move speed for Generic Level state */
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_gen_move_set_t;
/** Context of the received Generic Default Transition Time Set message */
typedef struct {
uint8_t trans_time; /*!< The value of the Generic Default Transition Time state */
} esp_ble_mesh_server_recv_gen_def_trans_time_set_t;
/** Context of the received Generic OnPowerUp Set message */
typedef struct {
uint8_t onpowerup; /*!< The value of the Generic OnPowerUp state */
} esp_ble_mesh_server_recv_gen_onpowerup_set_t;
/** Context of the received Generic Power Level Set message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t power; /*!< Target value of Generic Power Actual state */
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_gen_power_level_set_t;
/** Context of the received Generic Power Default Set message */
typedef struct {
uint16_t power; /*!< The value of the Generic Power Default state */
} esp_ble_mesh_server_recv_gen_power_default_set_t;
/** Context of the received Generic Power Range Set message */
typedef struct {
uint16_t range_min; /*!< Value of Range Min field of Generic Power Range state */
uint16_t range_max; /*!< Value of Range Max field of Generic Power Range state */
} esp_ble_mesh_server_recv_gen_power_range_set_t;
/** Context of the received Generic Location Global Set message */
typedef struct {
int32_t global_latitude; /*!< Global Coordinates (Latitude) */
int32_t global_longitude; /*!< Global Coordinates (Longitude) */
int16_t global_altitude; /*!< Global Altitude */
} esp_ble_mesh_server_recv_gen_loc_global_set_t;
/** Context of the received Generic Location Local Set message */
typedef struct {
int16_t local_north; /*!< Local Coordinates (North) */
int16_t local_east; /*!< Local Coordinates (East) */
int16_t local_altitude; /*!< Local Altitude */
uint8_t floor_number; /*!< Floor Number */
uint16_t uncertainty; /*!< Uncertainty */
} esp_ble_mesh_server_recv_gen_loc_local_set_t;
/** Context of the received Generic User Property Set message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a Generic User Property */
struct net_buf_simple *property_value; /*!< Raw value for the User Property */
} esp_ble_mesh_server_recv_gen_user_property_set_t;
/** Context of the received Generic Admin Property Set message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a Generic Admin Property */
uint8_t user_access; /*!< Enumeration indicating user accessn */
struct net_buf_simple *property_value; /*!< Raw value for the Admin Property */
} esp_ble_mesh_server_recv_gen_admin_property_set_t;
/** Context of the received Generic Manufacturer Property Set message */
typedef struct {
uint16_t property_id; /*!< Property ID identifying a Generic Manufacturer Property */
uint8_t user_access; /*!< Enumeration indicating user access */
} esp_ble_mesh_server_recv_gen_manufacturer_property_set_t;
/**
* @brief Generic Server Model received set message union
*/
typedef union {
esp_ble_mesh_server_recv_gen_onoff_set_t onoff; /*!< Generic OnOff Set/Generic OnOff Set Unack */
esp_ble_mesh_server_recv_gen_level_set_t level; /*!< Generic Level Set/Generic Level Set Unack */
esp_ble_mesh_server_recv_gen_delta_set_t delta; /*!< Generic Delta Set/Generic Delta Set Unack */
esp_ble_mesh_server_recv_gen_move_set_t move; /*!< Generic Move Set/Generic Move Set Unack */
esp_ble_mesh_server_recv_gen_def_trans_time_set_t def_trans_time; /*!< Generic Default Transition Time Set/Generic Default Transition Time Set Unack */
esp_ble_mesh_server_recv_gen_onpowerup_set_t onpowerup; /*!< Generic OnPowerUp Set/Generic OnPowerUp Set Unack */
esp_ble_mesh_server_recv_gen_power_level_set_t power_level; /*!< Generic Power Level Set/Generic Power Level Set Unack */
esp_ble_mesh_server_recv_gen_power_default_set_t power_default; /*!< Generic Power Default Set/Generic Power Default Set Unack */
esp_ble_mesh_server_recv_gen_power_range_set_t power_range; /*!< Generic Power Range Set/Generic Power Range Set Unack */
esp_ble_mesh_server_recv_gen_loc_global_set_t location_global; /*!< Generic Location Global Set/Generic Location Global Set Unack */
esp_ble_mesh_server_recv_gen_loc_local_set_t location_local; /*!< Generic Location Local Set/Generic Location Local Set Unack */
esp_ble_mesh_server_recv_gen_user_property_set_t user_property; /*!< Generic User Property Set/Generic User Property Set Unack */
esp_ble_mesh_server_recv_gen_admin_property_set_t admin_property; /*!< Generic Admin Property Set/Generic Admin Property Set Unack */
esp_ble_mesh_server_recv_gen_manufacturer_property_set_t manu_property; /*!< Generic Manufacturer Property Set/Generic Manufacturer Property Set Unack */
} esp_ble_mesh_generic_server_recv_set_msg_t;
/**
* @brief Generic Server Model callback value union
*/
typedef union {
esp_ble_mesh_generic_server_state_change_t state_change; /*!< ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT */
esp_ble_mesh_generic_server_recv_get_msg_t get; /*!< ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT */
esp_ble_mesh_generic_server_recv_set_msg_t set; /*!< ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT */
} esp_ble_mesh_generic_server_cb_value_t;
/** Generic Server Model callback parameters */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to Generic Server Models */
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received messages */
esp_ble_mesh_generic_server_cb_value_t value; /*!< Value of the received Generic Messages */
} esp_ble_mesh_generic_server_cb_param_t;
/** This enum value is the event of Generic 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 Generic 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 Generic Set/Set Unack messages
* are received.
*/
ESP_BLE_MESH_GENERIC_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 Generic Get messages are received.
*/
ESP_BLE_MESH_GENERIC_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 Generic Set/Set Unack messages are received.
*/
ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT,
ESP_BLE_MESH_GENERIC_SERVER_EVT_MAX,
} esp_ble_mesh_generic_server_cb_event_t;
/**
* @brief Bluetooth Mesh Generic Server Model function.
*/
/**
* @brief Generic Server Model callback function type
* @param event: Event type
* @param param: Pointer to callback parameter
*/
typedef void (* esp_ble_mesh_generic_server_cb_t)(esp_ble_mesh_generic_server_cb_event_t event,
esp_ble_mesh_generic_server_cb_param_t *param);
/**
* @brief Register BLE Mesh Generic 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_generic_server_callback(esp_ble_mesh_generic_server_cb_t callback);
#endif /* _ESP_BLE_MESH_GENERIC_MODEL_API_H_ */

View file

@ -47,39 +47,123 @@
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_HEALTH_CLI, \
NULL, NULL, cli_data)
/** Health Server Model callbacks */
/** @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 {
/** Fetch current faults */
int (*fault_get_cur)(esp_ble_mesh_model_t *model, uint8_t *test_id,
uint16_t *company_id, uint8_t *faults, uint8_t *fault_count);
/** Clear health registered faults. Initialized by the stack. */
esp_ble_mesh_cb_t fault_clear;
/** Fetch registered faults */
int (*fault_get_reg)(esp_ble_mesh_model_t *model, uint16_t company_id,
uint8_t *test_id, uint8_t *faults, uint8_t *fault_count);
/** Run a specific health test. Initialized by the stack. */
esp_ble_mesh_cb_t fault_test;
/** Clear registered faults */
int (*fault_clear)(esp_ble_mesh_model_t *model, uint16_t company_id);
/** Health attention on callback. Initialized by the stack. */
esp_ble_mesh_cb_t attention_on;
/** Run a specific test */
int (*fault_test)(esp_ble_mesh_model_t *model, uint8_t test_id, uint16_t company_id);
/** Attention on */
void (*attn_on)(esp_ble_mesh_model_t *model);
/** Attention off */
void (*attn_off)(esp_ble_mesh_model_t *model);
/** Health attention off callback. Initialized by the stack. */
esp_ble_mesh_cb_t attention_off;
} esp_ble_mesh_health_srv_cb_t;
/** Health Server Model Context */
#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;
/** Optional callback struct */
const esp_ble_mesh_health_srv_cb_t *cb;
/** Health callback struct */
esp_ble_mesh_health_srv_cb_t health_cb;
/** Attention Timer state */
struct k_delayed_work attn_timer;
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 */
@ -186,14 +270,54 @@ typedef enum {
ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX,
} esp_ble_mesh_health_client_cb_event_t;
/** Health Server Model callback parameter */
/** Parameter of publishing Health Current Status completion event */
typedef struct {
int error_code; /*!< Appropriate error code */
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_COMPLETE_EVT,
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;
@ -270,7 +394,7 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_
esp_ble_mesh_health_client_set_state_t *set_state);
/**
* @brief This function is called by the Health Server Model to start to publish its Current Health Fault.
* @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.
*

View file

@ -255,6 +255,372 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_
esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_t *params,
esp_ble_mesh_sensor_client_set_state_t *set_state);
/**
* @brief Sensor Server Models related context.
*/
/** @def ESP_BLE_MESH_MODEL_SENSOR_SRV
*
* @brief Define a new Sensor Server Model.
*
* @note 1. The Sensor Server model is a root model. When this model is present
* on an element, the corresponding Sensor Setup Server model shall
* also be present.
* 2. This model shall support model publication and model subscription.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_sensor_srv_t.
*
* @return New Sensor Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SENSOR_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_SRV, \
NULL, srv_pub, srv_data)
/** @def ESP_BLE_MESH_MODEL_SENSOR_SETUP_SRV
*
* @brief Define a new Sensor Setup Server Model.
*
* @note 1. The Sensor Setup Server model extends the Sensor Server model.
* 2. This model shall support model publication and model subscription.
*
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
* @param srv_data Pointer to the unique struct esp_ble_mesh_sensor_setup_srv_t.
*
* @return New Sensor Setup Server Model instance.
*/
#define ESP_BLE_MESH_MODEL_SENSOR_SETUP_SRV(srv_pub, srv_data) \
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, \
NULL, srv_pub, srv_data)
#define ESP_BLE_MESH_INVALID_SENSOR_PROPERTY_ID 0x0000 /*!< Invalid Sensor Property ID */
#define ESP_BLE_MESH_SENSOR_PROPERTY_ID_LEN 0x02 /*!< Length of Sensor Property ID */
#define ESP_BLE_MESH_SENSOR_DESCRIPTOR_LEN 0x08 /*!< Length of Sensor Descriptor state */
#define ESP_BLE_MESH_SENSOR_UNSPECIFIED_POS_TOLERANCE 0x000 /*!< Unspecified Sensor Positive Tolerance */
#define ESP_BLE_MESH_SENSOR_UNSPECIFIED_NEG_TOLERANCE 0x000 /*!< Unspecified Sensor Negative Tolerance */
#define ESP_BLE_MESH_SENSOR_NOT_APPL_MEASURE_PERIOD 0x00 /*!< Not applicable Sensor Measurement Period */
#define ESP_BLE_MESH_SENSOR_NOT_APPL_UPDATE_INTERVAL 0x00 /*!< Not applicable Sensor Update Interval */
#define ESP_BLE_MESH_INVALID_SENSOR_SETTING_PROPERTY_ID 0x0000 /*!< Invalid Sensor Setting Property ID */
#define ESP_BLE_MESH_SENSOR_SETTING_PROPERTY_ID_LEN 0x02 /*!< Length of Sensor Setting Property ID */
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_LEN 0x01 /*!< Length of Sensor Setting Access */
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_READ 0x01 /*!< Sensor Setting Access - Read */
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_READ_WRITE 0x03 /*!< Sensor Setting Access - Read & Write */
#define ESP_BLE_MESH_SENSOR_DIVISOR_TRIGGER_TYPE_LEN 0x01 /*!< Length of Sensor Divisor Trigger Type */
#define ESP_BLE_MESH_SENSOR_STATUS_MIN_INTERVAL_LEN 0x01 /*!< Length of Sensor Status Min Interval */
#define ESP_BLE_MESH_SENSOR_PERIOD_DIVISOR_MAX_VALUE 15 /*!< Maximum value of Sensor Period Divisor */
#define ESP_BLE_MESH_SENSOR_STATUS_MIN_INTERVAL_MAX 26 /*!< Maximum value of Sensor Status Min Interval */
/**
* Sensor Status Trigger Type - Format Type of the characteristic
* that the Sensor Property ID state references
*/
#define ESP_BLE_MESH_SENSOR_STATUS_TRIGGER_TYPE_CHAR 0
/** Sensor Status Trigger Type - Format Type "uint16" */
#define ESP_BLE_MESH_SENSOR_STATUS_TRIGGER_TYPE_UINT16 1
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A 0x00 /*!< Sensor Data Format A */
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B 0x01 /*!< Sensor Data Format B */
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID_LEN 0x02 /*!< MPID length of Sensor Data Format A */
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID_LEN 0x03 /*!< MPID length of Sensor Data Format B */
/**
* Zero length of Sensor Data.
*
* Note:
* The Length field is a 1-based uint7 value (valid range 0x00x7F,
* representing range of 1127). The value 0x7F represents a length
* of zero.
*/
#define ESP_BLE_MESH_SENSOR_DATA_ZERO_LEN 0x7F
/** This enum value is value of Sensor Sampling Function */
enum esp_ble_mesh_sensor_sample_func {
ESP_BLE_MESH_SAMPLE_FUNC_UNSPECIFIED,
ESP_BLE_MESH_SAMPLE_FUNC_INSTANTANEOUS,
ESP_BLE_MESH_SAMPLE_FUNC_ARITHMETIC_MEAN,
ESP_BLE_MESH_SAMPLE_FUNC_RMS,
ESP_BLE_MESH_SAMPLE_FUNC_MAXIMUM,
ESP_BLE_MESH_SAMPLE_FUNC_MINIMUM,
ESP_BLE_MESH_SAMPLE_FUNC_ACCUMULATED,
ESP_BLE_MESH_SAMPLE_FUNC_COUNT,
};
/** Parameters of Sensor Descriptor state */
typedef struct {
uint32_t positive_tolerance : 12, /*!< The value of Sensor Positive Tolerance field */
negative_tolerance : 12, /*!< The value of Sensor Negative Tolerance field */
sampling_function : 8; /*!< The value of Sensor Sampling Function field */
uint8_t measure_period; /*!< The value of Sensor Measurement Period field */
uint8_t update_interval; /*!< The value of Sensor Update Interval field */
} esp_ble_mesh_sensor_descriptor_t;
/** Parameters of Sensor Setting state */
typedef struct {
uint16_t property_id; /*!< The value of Sensor Setting Property ID field */
uint8_t access; /*!< The value of Sensor Setting Access field */
struct net_buf_simple *raw; /*!< The value of Sensor Setting Raw field */
} esp_ble_mesh_sensor_setting_t;
/** Parameters of Sensor Cadence state */
typedef struct {
uint8_t period_divisor : 7, /*!< The value of Fast Cadence Period Divisor field */
trigger_type : 1; /*!< The value of Status Trigger Type field */
/**
* Note:
* The parameter "size" in trigger_delta_down, trigger_delta_up, fast_cadence_low &
* fast_cadence_high indicates the exact length of these four parameters, and they
* are associated with the Sensor Property ID. Users need to initialize the "size"
* precisely.
*/
struct net_buf_simple *trigger_delta_down; /*!< The value of Status Trigger Delta Down field */
struct net_buf_simple *trigger_delta_up; /*!< The value of Status Trigger Delta Up field */
uint8_t min_interval; /*!< The value of Status Min Interval field */
struct net_buf_simple *fast_cadence_low; /*!< The value of Fast Cadence Low field */
struct net_buf_simple *fast_cadence_high; /*!< The value of Fast Cadence High field */
} esp_ble_mesh_sensor_cadence_t;
/** Parameters of Sensor Data state */
typedef struct {
/**
* Format A: The Length field is a 1-based uint4 value (valid range 0x00xF,
* representing range of 1 16).
* Format B: The Length field is a 1-based uint7 value (valid range 0x00x7F,
* representing range of 1 127). The value 0x7F represents a
* length of zero.
*/
uint8_t format : 1, /*!< The value of the Sensor Data format */
length : 7; /*!< The value of the Sensor Data length */
struct net_buf_simple *raw_value; /*!< The value of Sensor Data raw value */
} esp_ble_mesh_sensor_data_t;
/** Parameters of Sensor Series Column state */
typedef struct {
struct net_buf_simple *raw_value_x; /*!< The value of Sensor Raw Value X field */
struct net_buf_simple *column_width; /*!< The value of Sensor Column Width field */
struct net_buf_simple *raw_value_y; /*!< The value of Sensor Raw Value Y field */
} esp_ble_mesh_sensor_series_column_t;
/** Parameters of Sensor states */
typedef struct {
uint16_t sensor_property_id; /*!< The value of Sensor Property ID field */
/* Constant throughout the lifetime of an element */
esp_ble_mesh_sensor_descriptor_t descriptor; /*!< Parameters of the Sensor Descriptor state */
/**
* Multiple Sensor Setting states may be present for each sensor.
* The Sensor Setting Property ID values shall be unique for each
* Sensor Property ID that identifies a sensor within an element.
*/
const uint8_t setting_count; /*!< */
esp_ble_mesh_sensor_setting_t *settings; /*!< Parameters of the Sensor Setting state */
/**
* The Sensor Cadence state may be not supported by sensors based
* on device properties referencing "non-scalar characteristics"
* such as "histograms" or "composite characteristics".
*/
esp_ble_mesh_sensor_cadence_t *cadence; /*!< Parameters of the Sensor Cadence state */
esp_ble_mesh_sensor_data_t sensor_data; /*!< Parameters of the Sensor Data state */
esp_ble_mesh_sensor_series_column_t series_column; /*!< Parameters of the Sensor Series Column state */
} esp_ble_mesh_sensor_state_t;
/** User data of Sensor Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Sensor Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
const uint8_t state_count; /*!< Sensor state count */
esp_ble_mesh_sensor_state_t *states; /*!< Parameters of the Sensor states */
} esp_ble_mesh_sensor_srv_t;
/** User data of Sensor Setup Server Model */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the Sensor Setup Server Model. Initialized internally. */
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
const uint8_t state_count; /*!< Sensor state count */
esp_ble_mesh_sensor_state_t *states; /*!< Parameters of the Sensor states */
} esp_ble_mesh_sensor_setup_srv_t;
/** Parameters of Sensor Cadence Set state change event */
typedef struct {
uint16_t property_id; /*!< The value of Sensor Property ID state */
uint8_t period_divisor : 7, /*!< The value of Fast Cadence Period Divisor state */
trigger_type : 1; /*!< The value of Status Trigger Type state */
struct net_buf_simple *trigger_delta_down; /*!< The value of Status Trigger Delta Down state */
struct net_buf_simple *trigger_delta_up; /*!< The value of Status Trigger Delta Up state */
uint8_t min_interval; /*!< The value of Status Min Interval state */
struct net_buf_simple *fast_cadence_low; /*!< The value of Fast Cadence Low state */
struct net_buf_simple *fast_cadence_high; /*!< The value of Fast Cadence High state */
} esp_ble_mesh_state_change_sensor_cadence_set_t;
/** Parameters of Sensor Setting Set state change event */
typedef struct {
uint16_t property_id; /*!< The value of Sensor Property ID state */
uint16_t setting_property_id; /*!< The value of Sensor Setting Property ID state */
struct net_buf_simple *setting_value; /*!< The value of Sensor Property Value state */
} esp_ble_mesh_state_change_sensor_setting_set_t;
/**
* @brief Sensor Server Model state change value union
*/
typedef union {
/**
* The recv_op in ctx can be used to decide which state is changed.
*/
esp_ble_mesh_state_change_sensor_cadence_set_t sensor_cadence_set; /*!< Sensor Cadence Set */
esp_ble_mesh_state_change_sensor_setting_set_t sensor_setting_set; /*!< Sensor Setting Set */
} esp_ble_mesh_sensor_server_state_change_t;
/** Context of the received Sensor Descriptor Get message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID of a sensor (optional) */
} esp_ble_mesh_server_recv_sensor_descriptor_get_t;
/** Context of the received Sensor Cadence Get message */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_server_recv_sensor_cadence_get_t;
/** Context of the received Sensor Settings Get message */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
} esp_ble_mesh_server_recv_sensor_settings_get_t;
/** Context of the received Sensor Setting Get message */
typedef struct {
uint16_t property_id; /*!< Property ID of a sensor */
uint16_t setting_property_id; /*!< Setting ID identifying a setting within a sensor */
} esp_ble_mesh_server_recv_sensor_setting_get_t;
/** Context of the received Sensor Get message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property ID for the sensor (optional) */
} esp_ble_mesh_server_recv_sensor_get_t;
/** Context of the received Sensor Column Get message */
typedef struct {
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value_x; /*!< Raw value identifying a column */
} esp_ble_mesh_server_recv_sensor_column_get_t;
/** Context of the received Sensor Series Get message */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t property_id; /*!< Property identifying a sensor */
struct net_buf_simple *raw_value; /*!< Raw value containg 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);
#endif /* _ESP_BLE_MESH_SENSOR_MODEL_API_H_ */

View file

@ -314,5 +314,599 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa
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_DELAT_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_DELAT_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);
#endif /* _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_ */

View file

@ -288,12 +288,17 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_CONFIG_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_config_client_copy_req_data);
sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_config_client_copy_req_data);
}
void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
@ -361,7 +366,7 @@ void btc_ble_mesh_config_client_publish_callback(u32_t opcode,
}
bt_mesh_config_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
@ -398,7 +403,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
return (cb->error_code =
bt_mesh_cfg_mod_pub_get(&ctx, get->model_pub_get.element_addr,
get->model_pub_get.model_id, get->model_pub_get.company_id));
get->model_pub_get.model_id, get->model_pub_get.company_id));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET:
return (cb->error_code = bt_mesh_cfg_hb_pub_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
@ -408,11 +413,11 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
return (cb->error_code =
bt_mesh_cfg_mod_sub_get(&ctx, get->sig_model_sub_get.element_addr,
get->sig_model_sub_get.model_id));
get->sig_model_sub_get.model_id));
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
return (cb->error_code =
bt_mesh_cfg_mod_sub_get_vnd(&ctx, get->vnd_model_sub_get.element_addr,
get->vnd_model_sub_get.model_id, get->vnd_model_sub_get.company_id));
get->vnd_model_sub_get.model_id, get->vnd_model_sub_get.company_id));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
return (cb->error_code = bt_mesh_cfg_net_key_get(&ctx));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
@ -422,11 +427,11 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
return (cb->error_code =
bt_mesh_cfg_mod_app_get(&ctx, get->sig_model_app_get.element_addr,
get->sig_model_app_get.model_id));
get->sig_model_app_get.model_id));
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
return (cb->error_code =
bt_mesh_cfg_mod_app_get_vnd(&ctx, get->vnd_model_app_get.element_addr,
get->vnd_model_app_get.model_id, get->vnd_model_app_get.company_id));
get->vnd_model_app_get.model_id, get->vnd_model_app_get.company_id));
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
return (cb->error_code = bt_mesh_cfg_kr_phase_get(&ctx, get->kr_phase_get.net_idx));
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
@ -475,16 +480,16 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD:
return (cb->error_code =
bt_mesh_cfg_net_key_add(&ctx, set->net_key_add.net_idx,
&set->net_key_add.net_key[0]));
&set->net_key_add.net_key[0]));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD:
return (cb->error_code =
bt_mesh_cfg_app_key_add(&ctx, set->app_key_add.net_idx,
set->app_key_add.app_idx, &set->app_key_add.app_key[0]));
set->app_key_add.app_idx, &set->app_key_add.app_key[0]));
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND:
return (cb->error_code =
bt_mesh_cfg_mod_app_bind(&ctx, set->model_app_bind.element_addr,
set->model_app_bind.model_app_idx, set->model_app_bind.model_id,
set->model_app_bind.company_id));
set->model_app_bind.model_app_idx, set->model_app_bind.model_id,
set->model_app_bind.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET: {
struct bt_mesh_cfg_mod_pub model_pub = {
.addr = set->model_pub_set.publish_addr,
@ -496,46 +501,46 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
};
return (cb->error_code =
bt_mesh_cfg_mod_pub_set(&ctx, set->model_pub_set.element_addr,
set->model_pub_set.model_id, set->model_pub_set.company_id, &model_pub));
set->model_pub_set.model_id, set->model_pub_set.company_id, &model_pub));
}
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD:
return (cb->error_code =
bt_mesh_cfg_mod_sub_add(&ctx, set->model_sub_add.element_addr,
set->model_sub_add.sub_addr, set->model_sub_add.model_id,
set->model_sub_add.company_id));
set->model_sub_add.sub_addr, set->model_sub_add.model_id,
set->model_sub_add.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE:
return (cb->error_code =
bt_mesh_cfg_mod_sub_del(&ctx, set->model_sub_delete.element_addr,
set->model_sub_delete.sub_addr, set->model_sub_delete.model_id,
set->model_sub_delete.company_id));
set->model_sub_delete.sub_addr, set->model_sub_delete.model_id,
set->model_sub_delete.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE:
return (cb->error_code =
bt_mesh_cfg_mod_sub_overwrite(&ctx, set->model_sub_overwrite.element_addr,
set->model_sub_overwrite.sub_addr, set->model_sub_overwrite.model_id,
set->model_sub_overwrite.company_id));
set->model_sub_overwrite.sub_addr, set->model_sub_overwrite.model_id,
set->model_sub_overwrite.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD:
return (cb->error_code =
bt_mesh_cfg_mod_sub_va_add(&ctx, set->model_sub_va_add.element_addr,
&set->model_sub_va_add.label_uuid[0], set->model_sub_va_add.model_id,
set->model_sub_va_add.company_id));
&set->model_sub_va_add.label_uuid[0], set->model_sub_va_add.model_id,
set->model_sub_va_add.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE:
return (cb->error_code =
bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set->model_sub_va_overwrite.element_addr,
&set->model_sub_va_overwrite.label_uuid[0], set->model_sub_va_overwrite.model_id,
set->model_sub_va_overwrite.company_id));
&set->model_sub_va_overwrite.label_uuid[0], set->model_sub_va_overwrite.model_id,
set->model_sub_va_overwrite.company_id));
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE:
return (cb->error_code =
bt_mesh_cfg_mod_sub_va_del(&ctx, set->model_sub_va_delete.element_addr,
&set->model_sub_va_delete.label_uuid[0], set->model_sub_va_delete.model_id,
set->model_sub_va_delete.company_id));
&set->model_sub_va_delete.label_uuid[0], set->model_sub_va_delete.model_id,
set->model_sub_va_delete.company_id));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET:
return (cb->error_code =
bt_mesh_cfg_hb_sub_set(&ctx,
(struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set));
(struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set));
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET:
return (cb->error_code =
bt_mesh_cfg_hb_pub_set(&ctx,
(const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set));
(const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set));
case ESP_BLE_MESH_MODEL_OP_NODE_RESET:
return (cb->error_code = bt_mesh_cfg_node_reset(&ctx));
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: {
@ -548,41 +553,41 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
};
return (cb->error_code =
bt_mesh_cfg_mod_pub_va_set(&ctx, set->model_pub_va_set.element_addr,
set->model_pub_va_set.model_id, set->model_pub_va_set.company_id,
set->model_pub_va_set.label_uuid, &model_pub));
set->model_pub_va_set.model_id, set->model_pub_va_set.company_id,
set->model_pub_va_set.label_uuid, &model_pub));
}
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL:
return (cb->error_code =
bt_mesh_cfg_mod_sub_del_all(&ctx, set->model_sub_delete_all.element_addr,
set->model_sub_delete_all.model_id, set->model_sub_delete_all.company_id));
set->model_sub_delete_all.model_id, set->model_sub_delete_all.company_id));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE:
return (cb->error_code =
bt_mesh_cfg_net_key_update(&ctx, set->net_key_update.net_idx,
set->net_key_update.net_key));
set->net_key_update.net_key));
case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE:
return (cb->error_code =
bt_mesh_cfg_net_key_delete(&ctx, set->net_key_delete.net_idx));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE:
return (cb->error_code =
bt_mesh_cfg_app_key_update(&ctx, set->app_key_update.net_idx,
set->app_key_update.app_idx, set->app_key_update.app_key));
set->app_key_update.app_idx, set->app_key_update.app_key));
case ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE:
return (cb->error_code =
bt_mesh_cfg_app_key_delete(&ctx, set->app_key_delete.net_idx,
set->app_key_delete.app_idx));
set->app_key_delete.app_idx));
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET:
return (cb->error_code =
bt_mesh_cfg_node_identity_set(&ctx, set->node_identity_set.net_idx,
set->node_identity_set.identity));
set->node_identity_set.identity));
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND:
return (cb->error_code =
bt_mesh_cfg_mod_app_unbind(&ctx, set->model_app_unbind.element_addr,
set->model_app_unbind.model_app_idx, set->model_app_unbind.model_id,
set->model_app_unbind.company_id));
set->model_app_unbind.model_app_idx, set->model_app_unbind.model_id,
set->model_app_unbind.company_id));
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET:
return (cb->error_code =
bt_mesh_cfg_kr_phase_set(&ctx, set->kr_phase_set.net_idx,
set->kr_phase_set.transition));
set->kr_phase_set.transition));
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET:
return (cb->error_code =
bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit));
@ -687,6 +692,11 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_CONFIG_SERVER;
msg.act = act;
@ -709,8 +719,8 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
}
switch (evt_type) {
case BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG:
act = ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT;
case BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE:
act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT;
break;
default:
LOG_ERROR("%s, Unknown config server event type %d", __func__, evt_type);
@ -726,8 +736,8 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
cb_params.ctx.recv_dst = ctx->recv_dst;
if (val && len) {
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
memcpy(&cb_params.status_cb, val, length);
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
}
btc_ble_mesh_config_server_callback(&cb_params, act);

View file

@ -361,12 +361,17 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GENERIC_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_generic_client_copy_req_data);
sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_generic_client_copy_req_data);
}
void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
@ -434,7 +439,7 @@ void btc_ble_mesh_generic_client_publish_callback(u32_t opcode,
}
bt_mesh_generic_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
@ -473,7 +478,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
cb.params = arg->generic_client_get_state.params;
cb.error_code = bt_mesh_generic_client_get_state(&common,
(void *)arg->generic_client_get_state.get_state, (void *)&cb.status_cb);
(void *)arg->generic_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
@ -499,7 +504,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
cb.params = arg->generic_client_set_state.params;
cb.error_code = bt_mesh_generic_client_set_state(&common,
(void *)arg->generic_client_set_state.set_state, (void *)&cb.status_cb);
(void *)arg->generic_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
@ -534,3 +539,232 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
btc_ble_mesh_generic_client_free_req_data(msg);
return;
}
/* Generic Server Models related functions */
static inline void btc_ble_mesh_generic_server_cb_to_app(
esp_ble_mesh_generic_server_cb_event_t event,
esp_ble_mesh_generic_server_cb_param_t *param)
{
esp_ble_mesh_generic_server_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_generic_server_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_SERVER);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_generic_server_cb_param_t *p_dest_data = (esp_ble_mesh_generic_server_cb_param_t *)p_dest;
esp_ble_mesh_generic_server_cb_param_t *p_src_data = (esp_ble_mesh_generic_server_cb_param_t *)p_src;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
switch (p_src_data->ctx.recv_op) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
if (p_src_data->value.state_change.user_property_set.value) {
length = p_src_data->value.state_change.user_property_set.value->len;
p_dest_data->value.state_change.user_property_set.value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.user_property_set.value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.user_property_set.value,
p_src_data->value.state_change.user_property_set.value->data,
p_src_data->value.state_change.user_property_set.value->len);
}
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
if (p_src_data->value.state_change.admin_property_set.value) {
length = p_src_data->value.state_change.admin_property_set.value->len;
p_dest_data->value.state_change.admin_property_set.value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.admin_property_set.value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.admin_property_set.value,
p_src_data->value.state_change.admin_property_set.value->data,
p_src_data->value.state_change.admin_property_set.value->len);
}
break;
default:
break;
}
break;
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT:
switch (p_src_data->ctx.recv_op) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
if (p_src_data->value.set.user_property.property_value) {
length = p_src_data->value.set.user_property.property_value->len;
p_dest_data->value.set.user_property.property_value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.set.user_property.property_value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.set.user_property.property_value,
p_src_data->value.set.user_property.property_value->data,
p_src_data->value.set.user_property.property_value->len);
}
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
if (p_src_data->value.set.admin_property.property_value) {
length = p_src_data->value.set.admin_property.property_value->len;
p_dest_data->value.set.admin_property.property_value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.set.admin_property.property_value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.set.admin_property.property_value,
p_src_data->value.set.admin_property.property_value->data,
p_src_data->value.set.admin_property.property_value->len);
}
break;
default:
break;
}
break;
default:
break;
}
}
static void btc_ble_mesh_generic_server_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_generic_server_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (esp_ble_mesh_generic_server_cb_param_t *)(msg->arg);
switch (msg->act) {
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
switch (arg->ctx.recv_op) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
bt_mesh_free_buf(arg->value.state_change.user_property_set.value);
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
bt_mesh_free_buf(arg->value.state_change.admin_property_set.value);
break;
default:
break;
}
break;
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT:
switch (arg->ctx.recv_op) {
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
bt_mesh_free_buf(arg->value.set.user_property.property_value);
break;
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
bt_mesh_free_buf(arg->value.set.admin_property.property_value);
break;
default:
break;
}
break;
default:
break;
}
}
static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GENERIC_SERVER;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_generic_server_cb_param_t), btc_ble_mesh_generic_server_copy_req_data);
}
void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
{
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
size_t length;
uint8_t act;
if (model == NULL || ctx == NULL) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (evt_type) {
case BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE:
act = ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT;
break;
case BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_GET_MSG:
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT;
break;
case BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_SET_MSG:
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT;
break;
default:
LOG_ERROR("%s, Unknown Generic Server event type", __func__);
return;
}
cb_params.model = (esp_ble_mesh_model_t *)model;
cb_params.ctx.net_idx = ctx->net_idx;
cb_params.ctx.app_idx = ctx->app_idx;
cb_params.ctx.addr = ctx->addr;
cb_params.ctx.recv_ttl = ctx->recv_ttl;
cb_params.ctx.recv_op = ctx->recv_op;
cb_params.ctx.recv_dst = ctx->recv_dst;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
}
btc_ble_mesh_generic_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_generic_server_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_generic_server_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_GENERIC_SERVER_EVT_MAX) {
btc_ble_mesh_generic_server_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_generic_server_free_req_data(msg);
return;
}

View file

@ -229,12 +229,17 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_HEALTH_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_health_client_cb_param_t), btc_ble_mesh_health_client_copy_req_data);
sizeof(esp_ble_mesh_health_client_cb_param_t), btc_ble_mesh_health_client_copy_req_data);
}
void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
@ -302,7 +307,7 @@ void btc_ble_mesh_health_publish_callback(u32_t opcode,
}
bt_mesh_health_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
@ -415,7 +420,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
break;
}
btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
arg->health_client_get_state.get_state, &cb);
arg->health_client_get_state.get_state, &cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
@ -431,7 +436,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
break;
}
btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
arg->health_client_set_state.set_state, &cb);
arg->health_client_set_state.set_state, &cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
@ -517,7 +522,7 @@ static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_des
}
switch (msg->act) {
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT:
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT:
break;
default:
break;
@ -532,7 +537,7 @@ static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
}
switch (msg->act) {
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT:
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT:
break;
default:
break;
@ -545,17 +550,22 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_HEALTH_SERVER;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data);
sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data);
}
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_health_server_cb_param_t health_server_cb = {0};
esp_ble_mesh_health_server_cb_param_t param = {0};
btc_ble_mesh_health_server_args_t *arg = NULL;
if (!msg || !msg->arg) {
@ -567,10 +577,10 @@ void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
switch (msg->act) {
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
health_server_cb.error_code =
bt_mesh_fault_update((struct bt_mesh_elem *)arg->fault_update.element);
btc_ble_mesh_health_server_callback(
&health_server_cb, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT);
param.fault_update_comp.element = arg->health_fault_update.element;
param.fault_update_comp.error_code =
bt_mesh_fault_update((struct bt_mesh_elem *)arg->health_fault_update.element);
btc_ble_mesh_health_server_callback(&param, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT);
break;
default:
break;
@ -600,3 +610,43 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
btc_ble_mesh_health_server_free_req_data(msg);
return;
}
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, u16_t company_id)
{
esp_ble_mesh_health_server_cb_param_t param = {0};
param.fault_clear.model = (esp_ble_mesh_model_t *)model;
param.fault_clear.company_id = company_id;
btc_ble_mesh_health_server_callback(&param, ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT);
}
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t test_id, u16_t company_id)
{
esp_ble_mesh_health_server_cb_param_t param = {0};
param.fault_test.model = (esp_ble_mesh_model_t *)model;
param.fault_test.test_id = test_id;
param.fault_test.company_id = company_id;
btc_ble_mesh_health_server_callback(&param, ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT);
}
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, u8_t time)
{
esp_ble_mesh_health_server_cb_param_t param = {0};
param.attention_on.model = (esp_ble_mesh_model_t *)model;
param.attention_on.time = time;
btc_ble_mesh_health_server_callback(&param, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT);
}
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model)
{
esp_ble_mesh_health_server_cb_param_t param = {0};
param.attention_off.model = (esp_ble_mesh_model_t *)model;
btc_ble_mesh_health_server_callback(&param, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT);
}

View file

@ -205,12 +205,17 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_LIGHTING_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_light_client_cb_param_t), btc_ble_mesh_lighting_client_copy_req_data);
sizeof(esp_ble_mesh_light_client_cb_param_t), btc_ble_mesh_lighting_client_copy_req_data);
}
void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
@ -278,7 +283,7 @@ void btc_ble_mesh_lighting_client_publish_callback(u32_t opcode,
}
bt_mesh_lighting_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
@ -317,7 +322,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
cb.params = arg->light_client_get_state.params;
cb.error_code = bt_mesh_light_client_get_state(&common,
(void *)arg->light_client_get_state.get_state, (void *)&cb.status_cb);
(void *)arg->light_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
@ -343,7 +348,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
cb.params = arg->light_client_set_state.params;
cb.error_code = bt_mesh_light_client_set_state(&common,
(void *)arg->light_client_set_state.set_state, (void *)&cb.status_cb);
(void *)arg->light_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
@ -379,3 +384,202 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
return;
}
/* Lighting Server Models related functions */
static inline void btc_ble_mesh_lighting_server_cb_to_app(
esp_ble_mesh_lighting_server_cb_event_t event,
esp_ble_mesh_lighting_server_cb_param_t *param)
{
esp_ble_mesh_lighting_server_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_lighting_server_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_SERVER);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_lighting_server_cb_param_t *p_dest_data = (esp_ble_mesh_lighting_server_cb_param_t *)p_dest;
esp_ble_mesh_lighting_server_cb_param_t *p_src_data = (esp_ble_mesh_lighting_server_cb_param_t *)p_src;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT:
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
if (p_src_data->value.state_change.lc_property_set.property_value) {
length = p_src_data->value.state_change.lc_property_set.property_value->len;
p_dest_data->value.state_change.lc_property_set.property_value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.lc_property_set.property_value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.lc_property_set.property_value,
p_src_data->value.state_change.lc_property_set.property_value->data,
p_src_data->value.state_change.lc_property_set.property_value->len);
}
}
break;
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT:
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
if (p_src_data->value.set.lc_property.property_value) {
length = p_src_data->value.set.lc_property.property_value->len;
p_dest_data->value.set.lc_property.property_value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.set.lc_property.property_value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.set.lc_property.property_value,
p_src_data->value.set.lc_property.property_value->data,
p_src_data->value.set.lc_property.property_value->len);
}
}
break;
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT:
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS) {
if (p_src_data->value.status.sensor_status.data) {
length = p_src_data->value.status.sensor_status.data->len;
p_dest_data->value.status.sensor_status.data = bt_mesh_alloc_buf(length);
if (p_dest_data->value.status.sensor_status.data == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.status.sensor_status.data,
p_src_data->value.status.sensor_status.data->data,
p_src_data->value.status.sensor_status.data->len);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_lighting_server_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_lighting_server_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (esp_ble_mesh_lighting_server_cb_param_t *)(msg->arg);
switch (msg->act) {
case ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT:
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
bt_mesh_free_buf(arg->value.state_change.lc_property_set.property_value);
}
break;
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT:
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
bt_mesh_free_buf(arg->value.set.lc_property.property_value);
}
break;
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT:
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS) {
bt_mesh_free_buf(arg->value.status.sensor_status.data);
}
break;
default:
break;
}
}
static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_LIGHTING_SERVER;
msg.act = act;
btc_transfer_context(
&msg, cb_params, sizeof(esp_ble_mesh_lighting_server_cb_param_t), btc_ble_mesh_lighting_server_copy_req_data);
}
void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
{
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
size_t length;
uint8_t act;
if (model == NULL || ctx == NULL) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (evt_type) {
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE:
act = ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT;
break;
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG:
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_GET_MSG_EVT;
break;
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG:
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT;
break;
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG:
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT;
break;
default:
LOG_ERROR("%s, Unknown Lighting Server event type", __func__);
return;
}
cb_params.model = (esp_ble_mesh_model_t *)model;
cb_params.ctx.net_idx = ctx->net_idx;
cb_params.ctx.app_idx = ctx->app_idx;
cb_params.ctx.addr = ctx->addr;
cb_params.ctx.recv_ttl = ctx->recv_ttl;
cb_params.ctx.recv_op = ctx->recv_op;
cb_params.ctx.recv_dst = ctx->recv_dst;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
}
btc_ble_mesh_lighting_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_lighting_server_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_lighting_server_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_LIGHTING_SERVER_EVT_MAX) {
btc_ble_mesh_lighting_server_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_lighting_server_free_req_data(msg);
return;
}

File diff suppressed because it is too large Load diff

View file

@ -450,12 +450,17 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_SENSOR_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_sensor_client_copy_req_data);
sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_sensor_client_copy_req_data);
}
void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
@ -523,7 +528,7 @@ void btc_ble_mesh_sensor_client_publish_callback(u32_t opcode,
}
bt_mesh_sensor_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
@ -562,7 +567,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
cb.params = arg->sensor_client_get_state.params;
cb.error_code = bt_mesh_sensor_client_get_state(&common,
(void *)arg->sensor_client_get_state.get_state, (void *)&cb.status_cb);
(void *)arg->sensor_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
@ -588,7 +593,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
cb.params = arg->sensor_client_set_state.params;
cb.error_code = bt_mesh_sensor_client_set_state(&common,
(void *)arg->sensor_client_set_state.set_state, (void *)&cb.status_cb);
(void *)arg->sensor_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
@ -624,3 +629,281 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
return;
}
/* Sensor Server Models related functions */
static inline void btc_ble_mesh_sensor_server_cb_to_app(
esp_ble_mesh_sensor_server_cb_event_t event,
esp_ble_mesh_sensor_server_cb_param_t *param)
{
esp_ble_mesh_sensor_server_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_sensor_server_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_SERVER);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
{
esp_ble_mesh_sensor_server_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_server_cb_param_t *)p_dest;
esp_ble_mesh_sensor_server_cb_param_t *p_src_data = (esp_ble_mesh_sensor_server_cb_param_t *)p_src;
u16_t length;
if (!msg || !p_src_data || !p_dest_data) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT:
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
if (p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down) {
length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len;
p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down,
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->data,
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len);
}
if (p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up) {
length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len;
p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up,
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->data,
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len);
}
if (p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low) {
length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len;
p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low,
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->data,
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len);
}
if (p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high) {
length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len;
p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high,
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->data,
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len);
}
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
if (p_src_data->value.state_change.sensor_setting_set.setting_value) {
length = p_src_data->value.state_change.sensor_setting_set.setting_value->len;
p_dest_data->value.state_change.sensor_setting_set.setting_value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.state_change.sensor_setting_set.setting_value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_setting_set.setting_value,
p_src_data->value.state_change.sensor_setting_set.setting_value->data,
p_src_data->value.state_change.sensor_setting_set.setting_value->len);
}
}
break;
case ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT:
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) {
if (p_src_data->value.get.sensor_column.raw_value_x) {
length = p_src_data->value.get.sensor_column.raw_value_x->len;
p_dest_data->value.get.sensor_column.raw_value_x = bt_mesh_alloc_buf(length);
if (p_dest_data->value.get.sensor_column.raw_value_x == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.get.sensor_column.raw_value_x,
p_src_data->value.get.sensor_column.raw_value_x->data,
p_src_data->value.get.sensor_column.raw_value_x->len);
}
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET) {
if (p_src_data->value.get.sensor_series.raw_value) {
length = p_src_data->value.get.sensor_series.raw_value->len;
p_dest_data->value.get.sensor_series.raw_value = bt_mesh_alloc_buf(length);
if (p_dest_data->value.get.sensor_series.raw_value == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.get.sensor_series.raw_value,
p_src_data->value.get.sensor_series.raw_value->data,
p_src_data->value.get.sensor_series.raw_value->len);
}
}
break;
case ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT:
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
if (p_src_data->value.set.sensor_cadence.cadence) {
length = p_src_data->value.set.sensor_cadence.cadence->len;
p_dest_data->value.set.sensor_cadence.cadence = bt_mesh_alloc_buf(length);
if (p_dest_data->value.set.sensor_cadence.cadence == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.set.sensor_cadence.cadence,
p_src_data->value.set.sensor_cadence.cadence->data,
p_src_data->value.set.sensor_cadence.cadence->len);
}
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
if (p_src_data->value.set.sensor_setting.setting_raw) {
length = p_src_data->value.set.sensor_setting.setting_raw->len;
p_dest_data->value.set.sensor_setting.setting_raw = bt_mesh_alloc_buf(length);
if (p_dest_data->value.set.sensor_setting.setting_raw == NULL) {
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
return;
}
net_buf_simple_add_mem(p_dest_data->value.set.sensor_setting.setting_raw,
p_src_data->value.set.sensor_setting.setting_raw->data,
p_src_data->value.set.sensor_setting.setting_raw->len);
}
}
break;
default:
break;
}
}
static void btc_ble_mesh_sensor_server_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_sensor_server_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
arg = (esp_ble_mesh_sensor_server_cb_param_t *)(msg->arg);
switch (msg->act) {
case ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT:
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.trigger_delta_down);
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.trigger_delta_up);
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.fast_cadence_low);
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.fast_cadence_high);
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
bt_mesh_free_buf(arg->value.state_change.sensor_setting_set.setting_value);
}
break;
case ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT:
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) {
bt_mesh_free_buf(arg->value.get.sensor_column.raw_value_x);
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET) {
bt_mesh_free_buf(arg->value.get.sensor_series.raw_value);
}
break;
case ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT:
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
bt_mesh_free_buf(arg->value.set.sensor_cadence.cadence);
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
bt_mesh_free_buf(arg->value.set.sensor_setting.setting_raw);
}
break;
default:
break;
}
}
static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_SENSOR_SERVER;
msg.act = act;
btc_transfer_context(
&msg, cb_params, sizeof(esp_ble_mesh_sensor_server_cb_param_t), btc_ble_mesh_sensor_server_copy_req_data);
}
void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
{
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
size_t length;
uint8_t act;
if (model == NULL || ctx == NULL) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (evt_type) {
case BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE:
act = ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT;
break;
case BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_GET_MSG:
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT;
break;
case BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_SET_MSG:
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT;
break;
default:
LOG_ERROR("%s, Unknown Sensor Server event type", __func__);
return;
}
cb_params.model = (esp_ble_mesh_model_t *)model;
cb_params.ctx.net_idx = ctx->net_idx;
cb_params.ctx.app_idx = ctx->app_idx;
cb_params.ctx.addr = ctx->addr;
cb_params.ctx.recv_ttl = ctx->recv_ttl;
cb_params.ctx.recv_op = ctx->recv_op;
cb_params.ctx.recv_dst = ctx->recv_dst;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
}
btc_ble_mesh_sensor_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_sensor_server_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_sensor_server_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_SENSOR_SERVER_EVT_MAX) {
btc_ble_mesh_sensor_server_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
btc_ble_mesh_sensor_server_free_req_data(msg);
return;
}

View file

@ -207,12 +207,17 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
msg.act = act;
btc_transfer_context(&msg, cb_params,
sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_time_scene_client_copy_req_data);
sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_time_scene_client_copy_req_data);
}
void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
@ -280,7 +285,7 @@ void btc_ble_mesh_time_scene_client_publish_callback(u32_t opcode,
}
bt_mesh_time_scene_client_cb_evt_to_btc(opcode,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
return;
}
@ -319,7 +324,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
cb.params = arg->time_scene_client_get_state.params;
cb.error_code = bt_mesh_time_scene_client_get_state(&common,
(void *)arg->time_scene_client_get_state.get_state, (void *)&cb.status_cb);
(void *)arg->time_scene_client_get_state.get_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
@ -345,7 +350,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
cb.params = arg->time_scene_client_set_state.params;
cb.error_code = bt_mesh_time_scene_client_set_state(&common,
(void *)arg->time_scene_client_set_state.set_state, (void *)&cb.status_cb);
(void *)arg->time_scene_client_set_state.set_state, (void *)&cb.status_cb);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
@ -381,3 +386,104 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
return;
}
/* Time and Scenes Server Models related functions */
static inline void btc_ble_mesh_time_scene_server_cb_to_app(
esp_ble_mesh_time_scene_server_cb_event_t event,
esp_ble_mesh_time_scene_server_cb_param_t *param)
{
esp_ble_mesh_time_scene_server_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_time_scene_server_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
LOG_DEBUG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_TIME_SCENE_SERVER;
msg.act = act;
btc_transfer_context(
&msg, cb_params, sizeof(esp_ble_mesh_time_scene_server_cb_param_t), NULL);
}
void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len)
{
esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0};
size_t length;
uint8_t act;
if (model == NULL || ctx == NULL) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
switch (evt_type) {
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE:
act = ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT;
break;
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_GET_MSG:
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT;
break;
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_SET_MSG:
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT;
break;
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_STATUS_MSG:
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT;
break;
default:
LOG_ERROR("%s, Unknown Time Scene Server event type", __func__);
return;
}
cb_params.model = (esp_ble_mesh_model_t *)model;
cb_params.ctx.net_idx = ctx->net_idx;
cb_params.ctx.app_idx = ctx->app_idx;
cb_params.ctx.addr = ctx->addr;
cb_params.ctx.recv_ttl = ctx->recv_ttl;
cb_params.ctx.recv_op = ctx->recv_op;
cb_params.ctx.recv_dst = ctx->recv_dst;
if (val && len) {
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
memcpy(&cb_params.value, val, length);
}
btc_ble_mesh_time_scene_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_time_scene_server_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
LOG_ERROR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_time_scene_server_cb_param_t *)(msg->arg);
if (msg->act < ESP_BLE_MESH_TIME_SCENE_SERVER_EVT_MAX) {
btc_ble_mesh_time_scene_server_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
}
return;
}

View file

@ -63,7 +63,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg);
typedef enum {
BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG,
BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX,
} btc_ble_mesh_config_server_evt_t;

View file

@ -60,4 +60,18 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_msg_ctx *ctx,
const u8_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(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg);
#endif /* _BTC_BLE_MESH_GENERIC_MODEL_H_ */

View file

@ -68,7 +68,7 @@ typedef enum {
typedef union {
struct ble_mesh_health_server_fault_update_args {
esp_ble_mesh_elem_t *element;
} fault_update;
} health_fault_update;
} btc_ble_mesh_health_server_args_t;
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg);
@ -77,4 +77,12 @@ 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, u16_t company_id);
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t test_id, u16_t company_id);
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, u8_t time);
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model);
#endif /* _BTC_BLE_MESH_HEALTH_MODEL_H_ */

View file

@ -60,5 +60,20 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_msg_ctx *ctx,
const u8_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(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg);
#endif /* _BTC_BLE_MESH_LIGHTING_MODEL_H_ */

View file

@ -55,12 +55,21 @@ typedef enum {
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY,
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_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 {
@ -156,6 +165,40 @@ typedef union {
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;
} btc_ble_mesh_prov_args_t;
typedef union {
@ -173,10 +216,17 @@ typedef union {
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);
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod);

View file

@ -60,5 +60,19 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_msg_ctx *ctx,
const u8_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(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg);
#endif /* _BTC_BLE_MESH_SENSOR_MODEL_H_ */

View file

@ -60,5 +60,20 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
struct bt_mesh_msg_ctx *ctx,
const u8_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(u8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const u8_t *val, size_t len);
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg);
#endif /* _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ */

View file

@ -544,8 +544,8 @@ struct net_buf {
};
struct net_buf_data_cb {
u8_t * (*alloc)(struct net_buf *buf, size_t *size, s32_t timeout);
u8_t * (*ref)(struct net_buf *buf, u8_t *data);
u8_t *(*alloc)(struct net_buf *buf, size_t *size, s32_t timeout);
u8_t *(*ref)(struct net_buf *buf, u8_t *data);
void (*unref)(struct net_buf *buf, u8_t *data);
};
@ -709,7 +709,7 @@ int net_buf_id(struct net_buf *buf);
*/
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
struct net_buf *net_buf_alloc_fixed_debug(struct net_buf_pool *pool, s32_t timeout,
const char *func, int line);
const char *func, int line);
#define net_buf_alloc_fixed(_pool, _timeout) \
net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
#else

View file

@ -46,7 +46,7 @@ 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.

View file

@ -182,6 +182,8 @@ struct k_delayed_work {
*/
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay);
int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period);
/**
* @brief Get time remaining before a delayed work gets scheduled.
*

View file

@ -310,7 +310,7 @@ void net_buf_unref(struct net_buf *buf)
}
#endif
NET_BUF_DBG("buf %p ref %u pool %p frags %p", buf, buf->ref,
buf->pool, buf->frags);
buf->pool, buf->frags);
/* Changed by Espressif. Add !buf->ref to avoid minus 0 */
if (!buf->ref || --buf->ref > 0) {
@ -325,7 +325,7 @@ void net_buf_unref(struct net_buf *buf)
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
pool->avail_count++;
NET_BUF_DBG("%s, pool %p, avail_count %d, uninit_count %d", __func__,
pool, pool->avail_count, pool->uninit_count);
pool, pool->avail_count, pool->uninit_count);
NET_BUF_ASSERT(pool->avail_count <= pool->buf_count);
#endif
@ -366,10 +366,10 @@ static u8_t *data_alloc(struct net_buf *buf, size_t *size, s32_t timeout)
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
struct net_buf *net_buf_alloc_len_debug(struct net_buf_pool *pool, size_t size,
s32_t timeout, const char *func, int line)
s32_t timeout, const char *func, int line)
#else
struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
s32_t timeout)
s32_t timeout)
#endif
{
struct net_buf *buf = NULL;
@ -379,7 +379,7 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
NET_BUF_ASSERT(pool);
NET_BUF_DBG("%s, pool %p, uninit_count %d, buf_count %d", __func__,
pool, pool->uninit_count, pool->buf_count);
pool, pool->uninit_count, pool->buf_count);
/* We need to lock interrupts temporarily to prevent race conditions
* when accessing pool->uninit_count.
@ -436,8 +436,8 @@ success:
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
struct net_buf *net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
s32_t timeout, const char *func,
int line)
s32_t timeout, const char *func,
int line)
{
const struct net_buf_pool_fixed *fixed = pool->alloc->alloc_data;

View file

@ -39,25 +39,16 @@ typedef struct alarm_t {
unsigned int bt_mesh_irq_lock(void)
{
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
unsigned int key = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL);
return key;
#else
/* Change by Espressif. In BLE Mesh, in order to improve the real-time
* requirements of bt controller, we use task lock to replace IRQ lock.
/* Changed by Espressif. In BLE Mesh, in order to improve the real-time
* requirements of bt controller, we use task lock instead of IRQ lock.
*/
osi_mutex_lock(&bm_irq_lock, OSI_MUTEX_MAX_TIMEOUT);
return 0;
#endif
}
void bt_mesh_irq_unlock(unsigned int key)
{
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
XTOS_RESTORE_INTLEVEL(key);
#else
osi_mutex_unlock(&bm_irq_lock);
#endif
}
s64_t k_uptime_get(void)
@ -124,8 +115,7 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
return;
}
int k_delayed_work_submit(struct k_delayed_work *work,
s32_t delay)
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
{
assert(work != NULL && bm_alarm_hash_map != NULL);
@ -141,6 +131,23 @@ int k_delayed_work_submit(struct k_delayed_work *work,
return 0;
}
int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period)
{
assert(work != NULL && bm_alarm_hash_map != NULL);
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__);
return -EINVAL;
}
/* Cancel the alarm first before starting it. */
osi_alarm_cancel(alarm);
osi_alarm_set_periodic(alarm, period);
return 0;
}
int k_delayed_work_cancel(struct k_delayed_work *work)
{
assert(work != NULL && bm_alarm_hash_map != NULL);

View file

@ -27,13 +27,18 @@
#include "transport.h"
#include "access.h"
#include "foundation.h"
#include "mesh_common.h"
#include "provisioner_main.h"
#include "generic_client.h"
#include "sensor_client.h"
#include "time_scene_client.h"
#include "lighting_client.h"
#include "provisioner_main.h"
#include "generic_server.h"
#include "sensor_server.h"
#include "time_scene_server.h"
#include "lighting_server.h"
#define BLE_MESH_SDU_MAX_LEN 384
@ -103,6 +108,41 @@ static const struct {
#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI)
{ BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_init },
#endif
{ BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, bt_mesh_gen_onoff_srv_init },
{ BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, bt_mesh_gen_level_srv_init },
{ BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, bt_mesh_gen_def_trans_time_srv_init },
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, bt_mesh_gen_power_onoff_srv_init },
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, bt_mesh_gen_power_onoff_setup_srv_init },
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, bt_mesh_gen_power_level_srv_init },
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, bt_mesh_gen_power_level_setup_srv_init },
{ BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, bt_mesh_gen_battery_srv_init },
{ BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, bt_mesh_gen_location_srv_init },
{ BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, bt_mesh_gen_location_setup_srv_init },
{ BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, bt_mesh_gen_user_prop_srv_init },
{ BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, bt_mesh_gen_admin_prop_srv_init },
{ BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, bt_mesh_gen_manu_prop_srv_init },
{ BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, bt_mesh_gen_client_prop_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, bt_mesh_light_lightness_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV, bt_mesh_light_lightness_setup_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_CTL_SRV, bt_mesh_light_ctl_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV, bt_mesh_light_ctl_setup_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV, bt_mesh_light_ctl_temp_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SRV, bt_mesh_light_hsl_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV, bt_mesh_light_hsl_hue_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV, bt_mesh_light_hsl_sat_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV, bt_mesh_light_hsl_setup_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_XYL_SRV, bt_mesh_light_xyl_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV, bt_mesh_light_xyl_setup_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_LC_SRV, bt_mesh_light_lc_srv_init },
{ BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV, bt_mesh_light_lc_setup_srv_init },
{ BLE_MESH_MODEL_ID_TIME_SRV, bt_mesh_time_srv_init },
{ BLE_MESH_MODEL_ID_TIME_SETUP_SRV, bt_mesh_time_setup_srv_init },
{ BLE_MESH_MODEL_ID_SCENE_SRV, bt_mesh_scene_srv_init },
{ BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, bt_mesh_scene_setup_srv_init },
{ BLE_MESH_MODEL_ID_SCHEDULER_SRV, bt_mesh_scheduler_srv_init },
{ BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, bt_mesh_scheduler_setup_srv_init },
{ BLE_MESH_MODEL_ID_SENSOR_SRV, bt_mesh_sensor_srv_init },
{ BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, bt_mesh_sensor_setup_srv_init },
};
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
@ -683,7 +723,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
if (buf->len < op->min_len) {
BT_ERR("%s, Too short message for OpCode 0x%08x",
__func__, opcode);
__func__, opcode);
continue;
}

View file

@ -30,10 +30,10 @@
#include "foundation.h"
#include "beacon.h"
#include "prov.h"
#include "proxy.h"
#include "proxy_server.h"
#include "provisioner_prov.h"
#include "provisioner_proxy.h"
#include "proxy_client.h"
#include "provisioner_beacon.h"
/* Convert from ms to 0.625ms units */
@ -55,7 +55,6 @@
#define ADV_STACK_SIZE 768
#endif
static xQueueHandle xBleMeshQueue;
static const bt_mesh_addr_t *dev_addr;
static const u8_t adv_type[] = {
@ -70,6 +69,27 @@ NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE
static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME];
static QueueHandle_t xBleMeshQueue;
#define BLE_MESH_QUEUE_SIZE 150
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
static struct bt_mesh_adv relay_adv_pool[CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT];
static QueueHandle_t xBleMeshRelayQueue;
#define BLE_MESH_RELAY_QUEUE_SIZE 150
static QueueSetHandle_t xBleMeshQueueSet;
#define BLE_MESH_QUEUE_SET_SIZE (BLE_MESH_QUEUE_SIZE + BLE_MESH_RELAY_QUEUE_SIZE)
#define BLE_MESH_RELAY_TIME_INTERVAL K_SECONDS(6)
#define BLE_MESH_MAX_TIME_INTERVAL 0xFFFFFFFF
static bool ignore_relay_packet(u32_t timestamp);
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
static struct bt_mesh_adv *adv_alloc(int id)
{
return &adv_pool[id];
@ -106,7 +126,7 @@ static inline int adv_send(struct net_buf *buf)
adv_int = MAX(adv_int_min,
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
duration = (BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1) *
(adv_int + 10);
(adv_int + 10);
BT_DBG("type %u len %u: %s", BLE_MESH_ADV(buf)->type,
buf->len, bt_hex(buf->data, buf->len));
@ -147,48 +167,111 @@ static inline int adv_send(struct net_buf *buf)
static void adv_thread(void *p)
{
struct net_buf **buf = NULL;
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
QueueSetMemberHandle_t handle;
#endif
bt_mesh_msg_t msg = {0};
int status;
BT_DBG("started");
struct net_buf **buf;
buf = (struct net_buf **)(&msg.arg);
BT_DBG("%s, starts", __func__);
while (1) {
*buf = NULL;
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if CONFIG_BLE_MESH_NODE
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
while (!(*buf)) {
s32_t timeout;
BT_DBG("Proxy advertising start");
BT_DBG("Mesh Proxy Advertising start");
timeout = bt_mesh_proxy_adv_start();
BT_DBG("Proxy Advertising up to %d ms", timeout);
BT_DBG("Mesh Proxy Advertising up to %d ms", timeout);
xQueueReceive(xBleMeshQueue, &msg, timeout);
BT_DBG("Proxy advertising stop");
BT_DBG("Mesh Proxy Advertising stop");
bt_mesh_proxy_adv_stop();
}
} else {
xQueueReceive(xBleMeshQueue, &msg, (portTickType)portMAX_DELAY);
xQueueReceive(xBleMeshQueue, &msg, portMAX_DELAY);
}
#else
xQueueReceive(xBleMeshQueue, &msg, (portTickType)portMAX_DELAY);
xQueueReceive(xBleMeshQueue, &msg, portMAX_DELAY);
#endif
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#if CONFIG_BLE_MESH_NODE
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT);
if (handle) {
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
}
} else {
while (!(*buf)) {
s32_t timeout;
BT_DBG("Mesh Proxy Advertising start");
timeout = bt_mesh_proxy_adv_start();
BT_DBG("Mesh Proxy Advertising up to %d ms", timeout);
handle = xQueueSelectFromSet(xBleMeshQueueSet, timeout);
BT_DBG("Mesh Proxy Advertising stop");
bt_mesh_proxy_adv_stop();
if (handle) {
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
}
}
}
}
} else {
handle = xQueueSelectFromSet(xBleMeshQueueSet, portMAX_DELAY);
if (handle) {
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
}
}
}
#else
handle = xQueueSelectFromSet(xBleMeshQueueSet, portMAX_DELAY);
if (handle) {
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
}
}
#endif
#endif /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
if (!(*buf)) {
if (*buf == NULL) {
continue;
}
/* busy == 0 means this was canceled */
if (BLE_MESH_ADV(*buf)->busy) {
BLE_MESH_ADV(*buf)->busy = 0U;
status = adv_send(*buf);
if (status) {
if (xQueueSendToFront(xBleMeshQueue, &msg, K_NO_WAIT) != pdTRUE) {
BT_ERR("%s, xQueueSendToFront failed", __func__);
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
if (adv_send(*buf)) {
BT_WARN("%s, Failed to send adv packet", __func__);
}
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
if (msg.relay && ignore_relay_packet(msg.timestamp)) {
/* If the interval between "current time - msg.timestamp" is bigger than
* BLE_MESH_RELAY_TIME_INTERVAL, this relay packet will not be sent.
*/
BT_DBG("%s, Ignore relay packet", __func__);
net_buf_unref(*buf);
} else {
if (adv_send(*buf)) {
BT_WARN("%s, Failed to send adv packet", __func__);
}
}
#endif
} else {
net_buf_unref(*buf);
}
@ -198,13 +281,6 @@ static void adv_thread(void *p)
}
}
void bt_mesh_adv_update(void)
{
BT_DBG("%s", __func__);
bt_mesh_msg_t msg = {0};
bt_mesh_task_post(&msg, 0);
}
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,
@ -224,7 +300,7 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
}
BT_DBG("%s, pool = %p, buf_count = %d, uinit_count = %d", __func__,
buf->pool, pool->buf_count, pool->uninit_count);
buf->pool, pool->buf_count, pool->uninit_count);
adv = get_id(net_buf_id(buf));
BLE_MESH_ADV(buf) = adv;
@ -244,17 +320,35 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
xmit, timeout);
}
void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
static void bt_mesh_unref_buf(bt_mesh_msg_t *msg)
{
struct net_buf *buf;
if (msg->arg) {
buf = (struct net_buf *)msg->arg;
BLE_MESH_ADV(buf)->busy = 0U;
net_buf_unref(buf);
}
return;
}
static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
{
BT_DBG("%s", __func__);
if (xQueueSend(xBleMeshQueue, msg, timeout) != pdTRUE) {
BT_ERR("%s, Failed to post msg to queue", __func__);
BT_ERR("%s, Failed to send item to queue", __func__);
bt_mesh_unref_buf(msg);
}
}
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data)
{
bt_mesh_msg_t msg = {
.relay = false,
};
BT_DBG("type 0x%02x len %u: %s", BLE_MESH_ADV(buf)->type, buf->len,
bt_hex(buf->data, buf->len));
@ -262,21 +356,228 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
BLE_MESH_ADV(buf)->cb_data = cb_data;
BLE_MESH_ADV(buf)->busy = 1U;
bt_mesh_msg_t msg = {0};
msg.arg = (void *)net_buf_ref(buf);
bt_mesh_task_post(&msg, portMAX_DELAY);
}
void bt_mesh_adv_update(void)
{
bt_mesh_msg_t msg = {
.relay = false,
.arg = NULL,
};
BT_DBG("%s", __func__);
bt_mesh_task_post(&msg, K_NO_WAIT);
}
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
static bool ignore_relay_packet(u32_t timestamp)
{
u32_t now = k_uptime_get_32();
u32_t interval;
if (now > timestamp) {
interval = now - timestamp;
} else if (now == timestamp) {
interval = BLE_MESH_MAX_TIME_INTERVAL;
} else {
interval = BLE_MESH_MAX_TIME_INTERVAL - (timestamp - now) + 1;
}
return (interval >= BLE_MESH_RELAY_TIME_INTERVAL) ? true : false;
}
static struct bt_mesh_adv *relay_adv_alloc(int id)
{
return &relay_adv_pool[id];
}
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
s32_t timeout)
{
return bt_mesh_adv_create_from_pool(&relay_adv_buf_pool, relay_adv_alloc, type,
xmit, timeout);
}
static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
{
QueueSetMemberHandle_t handle;
bt_mesh_msg_t old_msg = {0};
BT_DBG("%s", __func__);
if (xQueueSend(xBleMeshRelayQueue, msg, timeout) == pdTRUE) {
return;
}
/**
* If failed to send packet to the relay queue(queue is full), we will
* remove the oldest packet in the queue and put the new one into it.
*/
handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT);
if (handle && uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
BT_DBG("%s, Full queue, remove the oldest relay packet", __func__);
/* Remove the oldest relay packet from queue */
if (xQueueReceive(xBleMeshRelayQueue, &old_msg, K_NO_WAIT) != pdTRUE) {
BT_ERR("%s, Failed to remove item from queue", __func__);
bt_mesh_unref_buf(msg);
return;
}
/* Unref buf used for the oldest relay packet */
bt_mesh_unref_buf(&old_msg);
/* Send the latest relay packet to queue */
if (xQueueSend(xBleMeshRelayQueue, msg, K_NO_WAIT) != pdTRUE) {
BT_ERR("%s, Failed to send item to relay queue", __func__);
bt_mesh_unref_buf(msg);
return;
}
} else {
BT_WARN("%s, Empty queue, but failed to send the relay packet", __func__);
bt_mesh_unref_buf(msg);
}
}
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data, u16_t src, u16_t dst)
{
bt_mesh_msg_t msg = {
.relay = true,
};
BT_DBG("type 0x%02x len %u: %s", BLE_MESH_ADV(buf)->type, buf->len,
bt_hex(buf->data, buf->len));
BLE_MESH_ADV(buf)->cb = cb;
BLE_MESH_ADV(buf)->cb_data = cb_data;
BLE_MESH_ADV(buf)->busy = 1U;
msg.arg = (void *)net_buf_ref(buf);
msg.src = src;
msg.dst = dst;
msg.timestamp = k_uptime_get_32();
/* Use K_NO_WAIT here, if xBleMeshRelayQueue is full return immediately */
ble_mesh_relay_task_post(&msg, K_NO_WAIT);
}
u16_t bt_mesh_get_stored_relay_count(void)
{
return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue);
}
#endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
const bt_mesh_addr_t *bt_mesh_pba_get_addr(void)
{
return dev_addr;
}
#if (CONFIG_BLE_MESH_PROVISIONER && COFNIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static bool bt_mesh_is_adv_flags_valid(struct net_buf_simple *buf)
{
u8_t flags;
if (buf->len != 1U) {
BT_DBG("%s, Unexpected flags length", __func__);
return false;
}
flags = net_buf_simple_pull_u8(buf);
BT_DBG("Received adv pkt with flags: 0x%02x", flags);
/* Flags context will not be checked curently */
return true;
}
static bool bt_mesh_is_adv_srv_uuid_valid(struct net_buf_simple *buf, u16_t *uuid)
{
if (buf->len != 2U) {
BT_DBG("Length not match mesh service uuid");
return false;
}
*uuid = net_buf_simple_pull_le16(buf);
BT_DBG("Received adv pkt with service UUID: %d", *uuid);
if (*uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
*uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROV_VAL &&
bt_mesh_is_provisioner_en() == false) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROXY_VAL &&
!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
return false;
}
return true;
}
#define BLE_MESH_PROV_SRV_DATA_LEN 0x12
#define BLE_MESH_PROXY_SRV_DATA_LEN1 0x09
#define BLE_MESH_PROXY_SRV_DATA_LEN2 0x11
static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid)
{
u16_t type;
if (!buf || !addr) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
type = net_buf_simple_pull_le16(buf);
if (type != uuid) {
BT_DBG("%s, Invalid Mesh Service Data UUID 0x%04x", __func__, type);
return;
}
switch (type) {
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
case BLE_MESH_UUID_MESH_PROV_VAL:
if (bt_mesh_is_provisioner_en()) {
if (buf->len != BLE_MESH_PROV_SRV_DATA_LEN) {
BT_WARN("%s, Invalid Mesh Prov Service Data length %d", __func__, buf->len);
return;
}
BT_DBG("Start to handle Mesh Prov Service Data");
provisioner_prov_adv_ind_recv(buf, addr);
}
break;
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_UUID_MESH_PROXY_VAL:
if (buf->len != BLE_MESH_PROXY_SRV_DATA_LEN1 &&
buf->len != BLE_MESH_PROXY_SRV_DATA_LEN2) {
BT_WARN("%s, Invalid Mesh Proxy Service Data length %d", __func__, buf->len);
return;
}
BT_DBG("Start to handle Mesh Proxy Service Data");
proxy_client_adv_ind_recv(buf, addr);
break;
#endif
default:
break;
}
}
#endif
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
u8_t adv_type, struct net_buf_simple *buf)
{
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
u16_t uuid = 0;
#if (CONFIG_BLE_MESH_PROVISIONER && COFNIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
u16_t uuid;
#endif
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
@ -311,9 +612,9 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
#if 0
/* TODO: Check with BLE Mesh BQB test cases */
if ((type == BLE_MESH_DATA_MESH_PROV || type == BLE_MESH_DATA_MESH_MESSAGE ||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
BT_DBG("%s, ignore BLE Mesh packet (type 0x%02x) with adv_type 0x%02x",
__func__, type, adv_type);
__func__, type, adv_type);
return;
}
#endif
@ -348,30 +649,24 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
}
#endif
break;
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
#if (CONFIG_BLE_MESH_PROVISIONER && COFNIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_DATA_FLAGS:
if (bt_mesh_is_provisioner_en()) {
if (!provisioner_flags_match(buf)) {
BT_DBG("Flags mismatch, ignore this adv pkt");
return;
}
if (!bt_mesh_is_adv_flags_valid(buf)) {
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
return;
}
break;
case BLE_MESH_DATA_UUID16_ALL:
if (bt_mesh_is_provisioner_en()) {
uuid = provisioner_srv_uuid_recv(buf);
if (!uuid) {
BT_DBG("Service UUID mismatch, ignore this adv pkt");
return;
}
if (!bt_mesh_is_adv_srv_uuid_valid(buf, &uuid)) {
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
return;
}
break;
case BLE_MESH_DATA_SVC_DATA16:
if (bt_mesh_is_provisioner_en()) {
provisioner_srv_data_recv(buf, addr, uuid);
}
bt_mesh_adv_srv_data_recv(buf, addr, uuid);
break;
#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */
#endif
default:
break;
}
@ -385,10 +680,18 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
void bt_mesh_adv_init(void)
{
xBleMeshQueue = xQueueCreate(150, sizeof(bt_mesh_msg_t));
xBleMeshQueue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
configASSERT(xBleMeshQueue);
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
xBleMeshRelayQueue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
configASSERT(xBleMeshRelayQueue);
xBleMeshQueueSet = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE);
configASSERT(xBleMeshQueueSet);
xQueueAddToSet(xBleMeshQueue, xBleMeshQueueSet);
xQueueAddToSet(xBleMeshRelayQueue, xBleMeshQueueSet);
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL,
configMAX_PRIORITIES - 7, NULL, ADV_TASK_CORE);
configMAX_PRIORITIES - 7, NULL, ADV_TASK_CORE);
configASSERT(ret == pdTRUE);
}

View file

@ -21,11 +21,11 @@
#define BLE_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
typedef struct bt_mesh_msg {
uint8_t sig; //event signal
uint8_t aid; //application id
uint8_t pid; //profile id
uint8_t act; //profile action, defined in seprerate header files
void *arg; //param for btc function or function param
bool relay; /* Flag indicates if the packet is a relayed one */
void *arg; /* Pointer to the struct net_buf */
u16_t src; /* Source address for relay packets */
u16_t dst; /* Destination address for relay packets */
u32_t timestamp; /* Timestamp recorded when the relay packet is posted to queue */
} bt_mesh_msg_t;
enum bt_mesh_adv_type {
@ -73,6 +73,14 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
const bt_mesh_addr_t *bt_mesh_pba_get_addr(void);
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
s32_t timeout);
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data, u16_t src, u16_t dst);
u16_t bt_mesh_get_stored_relay_count(void);
void bt_mesh_adv_update(void);
void bt_mesh_adv_init(void);
@ -81,6 +89,4 @@ int bt_mesh_scan_enable(void);
int bt_mesh_scan_disable(void);
void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout);
#endif /* _ADV_H_ */

View file

@ -25,6 +25,7 @@
#include "crypto.h"
#include "beacon.h"
#include "foundation.h"
#include "proxy_client.h"
#if CONFIG_BLE_MESH_NODE
@ -138,6 +139,18 @@ static int secure_beacon_send(void)
continue;
}
/**
* If a node enables the Proxy Client functionality, and it
* succeeds to send Secure Network Beacon with GATT bearer,
* here we will continue to send Secure Network Beacon of
* other subnets.
*/
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
if (bt_mesh_proxy_client_beacon_send(sub)) {
continue;
}
#endif
buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, PROV_XMIT,
K_NO_WAIT);
if (!buf) {

View file

@ -47,7 +47,7 @@ struct bt_mesh_dev bt_mesh_dev;
#define BLE_MESH_GATT_GET_CONN_ID(conn_id) (((u16_t)(conn_id)) >> 8)
#define BLE_MESH_GATT_CREATE_CONN_ID(gatt_if, conn_id) ((u16_t)((((u8_t)(conn_id)) << 8) | ((u8_t)(gatt_if))))
/* We don't need to manage the BLE_MESH_DEV_ADVERTISING flags in the version of bluedriod,
/* We don't need to manage the BLE_MESH_DEV_ADVERTISING flags in the version of bluedriod,
* it will manage it in the BTM layer.
*/
#define BLE_MESH_DEV 0
@ -81,13 +81,13 @@ static future_t *future_mesh;
static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle);
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
#define BLE_MESH_GATTC_APP_UUID_BYTE 0x97
static struct gattc_prov_info {
/* Service to be found depends on the type of adv pkt received */
struct bt_mesh_conn conn;
BD_ADDR addr;
u8_t addr_type;
bt_mesh_addr_t addr;
u16_t service_uuid;
u16_t mtu;
bool wr_desc_done; /* Indicate if write char descriptor event is received */
@ -99,7 +99,7 @@ static struct gattc_prov_info {
} bt_mesh_gattc_info[BLE_MESH_MAX_CONN];
static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
static tBTA_GATTC_IF bt_mesh_gattc_if;
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
#endif
esp_err_t bt_mesh_host_init(void)
{
@ -136,7 +136,7 @@ void bt_mesh_hci_init(void)
}
static void bt_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, u8_t *p_eir,
tBTA_DM_SEARCH_CBACK *p_scan_cback)
tBTA_DM_SEARCH_CBACK *p_scan_cback)
{
tBTM_INQ_INFO *p_inq_info;
tBTA_DM_SEARCH result;
@ -512,9 +512,9 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
if (attr != NULL && attr->write != NULL) {
if ((len = attr->write(&bt_mesh_gatts_conn[index], attr,
p_data->req_data.p_data->write_req.value,
p_data->req_data.p_data->write_req.len,
p_data->req_data.p_data->write_req.offset, 0)) > 0) {
p_data->req_data.p_data->write_req.value,
p_data->req_data.p_data->write_req.len,
p_data->req_data.p_data->write_req.offset, 0)) > 0) {
if (p_data->req_data.p_data->write_req.need_rsp) {
BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id,
p_data->req_data.status, NULL);
@ -627,7 +627,7 @@ static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle)
}
static void bt_mesh_gatts_foreach_attr(u16_t start_handle, u16_t end_handle,
bt_mesh_gatt_attr_func_t func, void *user_data)
bt_mesh_gatt_attr_func_t func, void *user_data)
{
struct bt_mesh_gatt_service *svc = NULL;
@ -694,8 +694,8 @@ struct gatts_incl {
} __packed;
ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
{
struct bt_mesh_gatt_attr *incl = attr->user_data;
struct bt_mesh_uuid *uuid = incl->user_data;
@ -731,7 +731,7 @@ ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn,
}
return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset,
BLE_MESH_UUID_128(uuid)->val, 16);
BLE_MESH_UUID_128(uuid)->val, 16);
}
struct gatts_chrc {
@ -1013,27 +1013,40 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc)
}
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb)
{
bt_mesh_gattc_conn_cb = cb;
}
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
u8_t bt_mesh_gattc_get_free_conn_count(void)
{
int i;
u8_t count = 0;
u8_t i;
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (conn == &bt_mesh_gattc_info[i].conn) {
break;
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == 0xFFFF &&
bt_mesh_gattc_info[i].service_uuid == 0x0000) {
++count;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
return 0;
return count;
}
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
{
u8_t i;
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (conn == &bt_mesh_gattc_info[i].conn) {
return bt_mesh_gattc_info[i].service_uuid;
}
}
return bt_mesh_gattc_info[i].service_uuid;
BT_ERR("%s, Conn is not found", __func__);
return 0;
}
/** For provisioner acting as a GATT client, it may follow the procedures
@ -1052,22 +1065,22 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
int i;
if (!addr || !memcmp(addr->val, zero, BLE_MESH_ADDR_LEN) ||
(addr->type > BLE_ADDR_RANDOM)) {
(addr->type > BLE_ADDR_RANDOM)) {
BT_ERR("%s, Invalid remote address", __func__);
return -EINVAL;
}
if (service_uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
BT_ERR("%s, Invalid service uuid 0x%04x", __func__, service_uuid);
return -EINVAL;
}
/* Check if already creating connection with the device */
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN)) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN)) {
BT_WARN("%s, Already create connection with %s",
__func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
__func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
return -EALREADY;
}
}
@ -1075,9 +1088,9 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
/* Find empty element in queue to store device info */
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if ((bt_mesh_gattc_info[i].conn.handle == 0xFFFF) &&
(bt_mesh_gattc_info[i].service_uuid == 0x0000)) {
memcpy(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN);
bt_mesh_gattc_info[i].addr_type = addr->type;
(bt_mesh_gattc_info[i].service_uuid == 0x0000)) {
memcpy(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN);
bt_mesh_gattc_info[i].addr.type = addr->type;
/* Service to be found after exhanging mtu size */
bt_mesh_gattc_info[i].service_uuid = service_uuid;
break;
@ -1104,15 +1117,12 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
* Slave_latency: 0x0
* Supervision_timeout: 32 sec
*/
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr, 0xC8, 0xC8, 0x00, 0xC80);
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr.val, 0xC8, 0xC8, 0x00, 0xC80);
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr,
bt_mesh_gattc_info[i].addr_type, true, BTA_GATT_TRANSPORT_LE);
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE);
/* Increment pbg_count */
provisioner_pbg_count_inc();
return 0;
return i;
}
void bt_mesh_gattc_exchange_mtu(u8_t index)
@ -1149,24 +1159,16 @@ int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_g
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (conn == &bt_mesh_gattc_info[i].conn) {
break;
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
BTA_GATTC_WriteCharValue(conn_id, bt_mesh_gattc_info[i].data_in_handle,
BTA_GATTC_TYPE_WRITE_NO_RSP, len,
(u8_t *)data, BTA_GATT_AUTH_REQ_NONE);
return 0;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
BT_ERR("%s, Conn is not found", __func__);
/** Here we return 0 for prov_send() return value check in provisioner.c
*/
return 0;
}
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
BTA_GATTC_WriteCharValue(conn_id, bt_mesh_gattc_info[i].data_in_handle,
BTA_GATTC_TYPE_WRITE_NO_RSP, len,
(u8_t *)data, BTA_GATT_AUTH_REQ_NONE);
return 0;
BT_ERR("%s, Conn is not found", __func__);
return -EEXIST;
}
void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
@ -1184,18 +1186,14 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (conn == &bt_mesh_gattc_info[i].conn) {
break;
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
BTA_GATTC_Close(conn_id);
return;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
BT_ERR("%s, Conn is not found", __func__);
return;
}
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
BTA_GATTC_Close(conn_id);
BT_ERR("%s, Conn is not found", __func__);
return;
}
/** Mesh Provisioning Service: 0x1827
@ -1235,25 +1233,16 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == handle) {
bt_mesh_gattc_info[i].mtu = p_data->cfg_mtu.mtu;
/* Search Mesh Provisioning Service or Mesh Proxy Service */
tBT_UUID service_uuid = {
.len = sizeof(bt_mesh_gattc_info[i].service_uuid),
.uu.uuid16 = bt_mesh_gattc_info[i].service_uuid,
};
BTA_GATTC_ServiceSearchRequest(p_data->cfg_mtu.conn_id, &service_uuid);
break;
}
}
/** Once mtu exchanged accomplished, start to find services, and here
* need a flag to indicate which service to find(Mesh Prov Service or
* Mesh Proxy Service)
*/
if (i != ARRAY_SIZE(bt_mesh_gattc_info)) {
tBT_UUID service_uuid;
u16_t conn_id;
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
service_uuid.len = sizeof(bt_mesh_gattc_info[i].service_uuid);
service_uuid.uu.uuid16 = bt_mesh_gattc_info[i].service_uuid;
/* Search Mesh Provisioning Service or Mesh Proxy Service */
BTA_GATTC_ServiceSearchRequest(conn_id, &service_uuid);
}
}
break;
}
@ -1264,17 +1253,14 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == handle) {
if (p_data->srvc_res.service_uuid.uuid.len == 2 &&
p_data->srvc_res.service_uuid.uuid.uu.uuid16 == bt_mesh_gattc_info[i].service_uuid) {
bt_mesh_gattc_info[i].start_handle = p_data->srvc_res.start_handle;
bt_mesh_gattc_info[i].end_handle = p_data->srvc_res.end_handle;
}
break;
}
}
if (i != ARRAY_SIZE(bt_mesh_gattc_info)) {
if (p_data->srvc_res.service_uuid.uuid.len == 2 &&
p_data->srvc_res.service_uuid.uuid.uu.uuid16 == bt_mesh_gattc_info[i].service_uuid) {
bt_mesh_gattc_info[i].start_handle = p_data->srvc_res.start_handle;
bt_mesh_gattc_info[i].end_handle = p_data->srvc_res.end_handle;
}
}
break;
}
case BTA_GATTC_SEARCH_CMPL_EVT: {
@ -1285,37 +1271,35 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == handle) {
conn = &bt_mesh_gattc_info[i].conn;
break;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
if (conn == NULL) {
BT_ERR("%s, Conn handle is not found", __func__);
return;
}
conn = &bt_mesh_gattc_info[i].conn;
if (bt_mesh_gattc_info[i].start_handle == 0x00 ||
bt_mesh_gattc_info[i].end_handle == 0x00 ||
bt_mesh_gattc_info[i].end_handle == 0x00 ||
(bt_mesh_gattc_info[i].start_handle > bt_mesh_gattc_info[i].end_handle)) {
bt_mesh_gattc_disconnect(conn);
return;
}
u16_t notify_en = BLE_MESH_GATT_CCC_NOTIFY;
btgatt_db_element_t *result = NULL;
tBT_UUID char_uuid = {0};
tBTA_GATT_STATUS status;
tBTA_GATT_UNFMT write;
int count = 0;
int num = 0;
u16_t conn_id;
tBT_UUID char_uuid;
btgatt_db_element_t *result = NULL;
tBTA_GATT_STATUS status;
u16_t notify_en = BLE_MESH_GATT_CCC_NOTIFY;
tBTA_GATT_UNFMT write;
/* Get the characteristic num within Mesh Provisioning/Proxy Service */
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
BTA_GATTC_GetDBSizeByType(conn_id, BTGATT_DB_CHARACTERISTIC, bt_mesh_gattc_info[i].start_handle,
bt_mesh_gattc_info[i].end_handle, BTA_GATTC_INVALID_HANDLE, &count);
BTA_GATTC_GetDBSizeByType(p_data->search_cmpl.conn_id, BTGATT_DB_CHARACTERISTIC,
bt_mesh_gattc_info[i].start_handle, bt_mesh_gattc_info[i].end_handle,
BTA_GATTC_INVALID_HANDLE, &count);
if (count != 2) {
bt_mesh_gattc_disconnect(conn);
return;
@ -1333,7 +1317,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
char_uuid.uu.uuid16 = BLE_MESH_UUID_MESH_PROXY_DATA_IN_VAL + j;
}
BTA_GATTC_GetCharByUUID(conn_id, bt_mesh_gattc_info[i].start_handle,
BTA_GATTC_GetCharByUUID(p_data->search_cmpl.conn_id, bt_mesh_gattc_info[i].start_handle,
bt_mesh_gattc_info[i].end_handle, char_uuid, &result, &num);
if (!result) {
@ -1362,12 +1346,13 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
}
bt_mesh_gattc_info[i].data_out_handle = result[0].attribute_handle;
}
osi_free(result);
result = NULL;
}
/* Register Notification fot Mesh Provisioning/Proxy Data Out Characteristic */
status = BTA_GATTC_RegisterForNotifications(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr,
status = BTA_GATTC_RegisterForNotifications(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
bt_mesh_gattc_info[i].data_out_handle);
if (status != BTA_GATT_OK) {
bt_mesh_gattc_disconnect(conn);
@ -1377,8 +1362,9 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
/** After notification is registered, get descriptor number of the
* Mesh Provisioning/Proxy Data Out Characteristic
*/
BTA_GATTC_GetDBSizeByType(conn_id, BTGATT_DB_DESCRIPTOR, bt_mesh_gattc_info[i].start_handle,
bt_mesh_gattc_info[i].end_handle, bt_mesh_gattc_info[i].data_out_handle, &num);
BTA_GATTC_GetDBSizeByType(p_data->search_cmpl.conn_id, BTGATT_DB_DESCRIPTOR,
bt_mesh_gattc_info[i].start_handle, bt_mesh_gattc_info[i].end_handle,
bt_mesh_gattc_info[i].data_out_handle, &num);
if (!num) {
bt_mesh_gattc_disconnect(conn);
return;
@ -1387,9 +1373,8 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
/* Get CCC of Mesh Provisioning/Proxy Data Out Characteristic */
char_uuid.len = 2;
char_uuid.uu.uuid16 = BLE_MESH_UUID_GATT_CCC_VAL;
BTA_GATTC_GetDescrByCharHandle(conn_id, bt_mesh_gattc_info[i].data_out_handle,
BTA_GATTC_GetDescrByCharHandle(p_data->search_cmpl.conn_id, bt_mesh_gattc_info[i].data_out_handle,
char_uuid, &result, &num);
if (!result) {
bt_mesh_gattc_disconnect(conn);
return;
@ -1408,7 +1393,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
*/
write.len = sizeof(notify_en);
write.p_value = (u8_t *)&notify_en;
BTA_GATTC_WriteCharDescr(conn_id, result[0].attribute_handle,
BTA_GATTC_WriteCharDescr(p_data->search_cmpl.conn_id, result[0].attribute_handle,
BTA_GATTC_TYPE_WRITE, &write, BTA_GATT_AUTH_REQ_NONE);
osi_free(result);
@ -1426,17 +1411,16 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == handle) {
conn = &bt_mesh_gattc_info[i].conn;
break;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
if (conn == NULL) {
BT_ERR("%s, Conn handle is not found", __func__);
return;
}
conn = &bt_mesh_gattc_info[i].conn;
if (bt_mesh_gattc_info[i].ccc_handle != p_data->write.handle) {
BT_WARN("%s, gattc ccc_handle is not matched", __func__);
bt_mesh_gattc_disconnect(conn);
@ -1445,7 +1429,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_write_descr != NULL) {
len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].conn, bt_mesh_gattc_info[i].addr);
len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn);
if (len < 0) {
BT_ERR("%s, prov_write_descr failed", __func__);
bt_mesh_gattc_disconnect(conn);
@ -1455,12 +1439,13 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
}
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_write_descr != NULL) {
len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].conn);
len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn);
if (len < 0) {
BT_ERR("%s, proxy_write_descr failed", __func__);
bt_mesh_gattc_disconnect(conn);
return;
}
bt_mesh_gattc_info[i].wr_desc_done = true;
}
}
}
@ -1473,18 +1458,22 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == handle) {
if (bt_mesh_gattc_info[i].wr_desc_done == false) {
BT_DBG("Receive notification before finishing to write ccc");
return;
}
conn = &bt_mesh_gattc_info[i].conn;
break;
}
}
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
if (conn == NULL) {
BT_ERR("%s, Conn handle is not found", __func__);
return;
}
conn = &bt_mesh_gattc_info[i].conn;
if (memcmp(bt_mesh_gattc_info[i].addr, p_data->notify.bda, BLE_MESH_ADDR_LEN) ||
if (memcmp(bt_mesh_gattc_info[i].addr.val, p_data->notify.bda, BLE_MESH_ADDR_LEN) ||
bt_mesh_gattc_info[i].data_out_handle != p_data->notify.handle ||
p_data->notify.is_notify == false) {
BT_ERR("%s, Notification error", __func__);
@ -1495,7 +1484,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_notify != NULL) {
len = bt_mesh_gattc_conn_cb->prov_notify(&bt_mesh_gattc_info[i].conn,
p_data->notify.value, p_data->notify.len);
p_data->notify.value, p_data->notify.len);
if (len < 0) {
BT_ERR("%s, prov_notify failed", __func__);
bt_mesh_gattc_disconnect(conn);
@ -1505,7 +1494,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL) {
len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn,
p_data->notify.value, p_data->notify.len);
p_data->notify.value, p_data->notify.len);
if (len < 0) {
BT_ERR("%s, proxy_notify failed", __func__);
bt_mesh_gattc_disconnect(conn);
@ -1560,9 +1549,9 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->connected != NULL) {
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->connect.remote_bda, BLE_MESH_ADDR_LEN)) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, p_data->connect.remote_bda, BLE_MESH_ADDR_LEN)) {
bt_mesh_gattc_info[i].conn.handle = BLE_MESH_GATT_GET_CONN_ID(p_data->connect.conn_id);
(bt_mesh_gattc_conn_cb->connected)(bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i);
(bt_mesh_gattc_conn_cb->connected)(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i);
break;
}
}
@ -1581,24 +1570,36 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->disconnected != NULL) {
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->disconnect.remote_bda, BLE_MESH_ADDR_LEN)) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, p_data->disconnect.remote_bda, BLE_MESH_ADDR_LEN)) {
if (bt_mesh_gattc_info[i].conn.handle == handle) {
(bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].conn, p_data->disconnect.reason);
(bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, p_data->disconnect.reason);
if (!bt_mesh_gattc_info[i].wr_desc_done) {
/* Add this in case connection is established, connected event comes, but
* connection is terminated before server->filter_type is set to PROV.
*/
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr);
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr.val);
}
#endif
}
} else {
/* Add this in case connection is failed to be established, and here we
* need to clear some provision link info, like connecting flag, device
* uuid, address info, etc.
*/
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr);
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr.val);
}
#endif
}
/* Decrease prov pbg_count */
provisioner_pbg_count_dec();
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
/* Decrease provisioner pbg_count */
provisioner_pbg_count_dec();
}
#endif
/* Reset corresponding gattc info */
memset(&bt_mesh_gattc_info[i], 0, sizeof(bt_mesh_gattc_info[i]));
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
@ -1618,7 +1619,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
break;
}
}
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn)
{
@ -1648,7 +1649,8 @@ void bt_mesh_gatt_init(void)
BTA_GATTS_AppRegister(&app_uuid, bt_mesh_bta_gatts_cb);
#endif
#if CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
bt_mesh_gattc_info[i].mtu = GATT_DEF_BLE_MTU_SIZE; /* Default MTU_SIZE 23 */
@ -1874,7 +1876,7 @@ int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info)
BD_ADDR value = {0};
if ((sub_code > BLE_MESH_EXCEP_LIST_CLEAN) ||
(type > BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV)) {
(type > BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV)) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}

View file

@ -120,7 +120,7 @@ static void timeout_handler(struct k_work *work)
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_config_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}

View file

@ -29,7 +29,7 @@
#include "crypto.h"
#include "access.h"
#include "beacon.h"
#include "proxy.h"
#include "proxy_server.h"
#include "foundation.h"
#include "friend.h"
#include "settings.h"
@ -96,7 +96,7 @@ static int comp_get_page_0(struct net_buf_simple *buf)
feat |= BLE_MESH_FEAT_RELAY;
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
feat |= BLE_MESH_FEAT_PROXY;
}
@ -472,10 +472,14 @@ static void app_key_add(struct bt_mesh_model *model,
return;
}
#if defined(CONFIG_BLE_MESH_FAST_PROV)
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG,
model, ctx, (u8_t *)&key_app_idx, sizeof(u16_t));
#endif
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_appkey_add.net_idx = key_net_idx;
change.cfg_appkey_add.app_idx = key_app_idx;
memcpy(change.cfg_appkey_add.app_key, buf->data, 16);
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
static void app_key_update(struct bt_mesh_model *model,
@ -501,6 +505,15 @@ static void app_key_update(struct bt_mesh_model *model,
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("%s, Unable to send Config AppKey Status", __func__);
}
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_appkey_update.net_idx = key_net_idx;
change.cfg_appkey_update.app_idx = key_app_idx;
memcpy(change.cfg_appkey_update.app_key, buf->data, 16);
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
struct unbind_data {
@ -577,6 +590,14 @@ send_status:
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("%s, Unable to send Config AppKey Status", __func__);
}
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_appkey_delete.net_idx = key_net_idx;
change.cfg_appkey_delete.app_idx = key_app_idx;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
/* Index list length: 3 bytes for every pair and 2 bytes for an odd idx */
@ -797,7 +818,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
return;
}
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) ||
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) ||
bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_NOT_SUPPORTED) {
goto send_status;
}
@ -1124,6 +1145,21 @@ static void mod_pub_set(struct bt_mesh_model *model,
send_status:
send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod,
status, mod_id);
if (status == STATUS_SUCCESS && mod->pub) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_mod_pub_set.elem_addr = elem_addr;
change.cfg_mod_pub_set.pub_addr = mod->pub->addr;
change.cfg_mod_pub_set.app_idx = mod->pub->key;
change.cfg_mod_pub_set.cred_flag = mod->pub->cred;
change.cfg_mod_pub_set.ttl = mod->pub->ttl;
change.cfg_mod_pub_set.period = mod->pub->period;
change.cfg_mod_pub_set.transmit = mod->pub->retransmit;
change.cfg_mod_pub_set.cid = vnd ? mod->vnd.company : 0xFFFF;
change.cfg_mod_pub_set.mod_id = vnd ? mod->vnd.id : mod->id;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
#if CONFIG_BLE_MESH_LABEL_COUNT > 0
@ -1447,6 +1483,16 @@ static void mod_sub_add(struct bt_mesh_model *model,
send_status:
send_mod_sub_status(model, ctx, status, elem_addr, sub_addr,
mod_id, vnd);
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_mod_sub_add.elem_addr = elem_addr;
change.cfg_mod_sub_add.sub_addr = sub_addr;
change.cfg_mod_sub_add.cid = vnd ? mod->vnd.company : 0xFFFF;
change.cfg_mod_sub_add.mod_id = vnd ? mod->vnd.id : mod->id;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
static void mod_sub_del(struct bt_mesh_model *model,
@ -1513,6 +1559,16 @@ static void mod_sub_del(struct bt_mesh_model *model,
send_status:
send_mod_sub_status(model, ctx, status, elem_addr, sub_addr,
mod_id, vnd);
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_mod_sub_delete.elem_addr = elem_addr;
change.cfg_mod_sub_delete.sub_addr = sub_addr;
change.cfg_mod_sub_delete.cid = vnd ? mod->vnd.company : 0xFFFF;
change.cfg_mod_sub_delete.mod_id = vnd ? mod->vnd.id : mod->id;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
static void mod_sub_overwrite(struct bt_mesh_model *model,
@ -2166,7 +2222,7 @@ static void net_key_add(struct bt_mesh_model *model,
/* Make sure we have valid beacon data to be sent */
bt_mesh_net_beacon_update(sub);
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED;
#if CONFIG_BLE_MESH_NODE
bt_mesh_proxy_beacon_send(sub);
@ -2177,6 +2233,12 @@ static void net_key_add(struct bt_mesh_model *model,
}
send_net_key_status(model, ctx, idx, STATUS_SUCCESS);
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_netkey_add.net_idx = sub->net_idx;
memcpy(change.cfg_netkey_add.net_key, sub->keys[0].net, 16);
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
static void net_key_update(struct bt_mesh_model *model,
@ -2246,6 +2308,12 @@ static void net_key_update(struct bt_mesh_model *model,
bt_mesh_net_beacon_update(sub);
send_net_key_status(model, ctx, idx, STATUS_SUCCESS);
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_netkey_update.net_idx = sub->net_idx;
memcpy(change.cfg_netkey_update.net_key, sub->keys[1].net, 16);
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
static void hb_pub_disable(struct bt_mesh_cfg_srv *cfg)
@ -2298,6 +2366,13 @@ static void net_key_del(struct bt_mesh_model *model,
send_status:
send_net_key_status(model, ctx, del_idx, status);
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_netkey_delete.net_idx = sub->net_idx;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
static void net_key_get(struct bt_mesh_model *model,
@ -2416,7 +2491,7 @@ static void node_identity_set(struct bt_mesh_model *model,
* 0x00, the Node Identity state for all subnets shall be set
* to 0x00 and shall not be changed."
*/
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) {
if (node_id) {
bt_mesh_proxy_identity_start(sub);
@ -2503,6 +2578,16 @@ send_status:
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("%s, Unable to send Config Model App Bind Status", __func__);
}
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_mod_app_bind.elem_addr = elem_addr;
change.cfg_mod_app_bind.app_idx = key_app_idx;
change.cfg_mod_app_bind.cid = vnd ? mod->vnd.company : 0xFFFF;
change.cfg_mod_app_bind.mod_id = vnd ? mod->vnd.id : mod->id;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
static void mod_app_unbind(struct bt_mesh_model *model,
@ -2549,6 +2634,16 @@ send_status:
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("%s, Unable to send Config Model App Unbind Status", __func__);
}
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_mod_app_unbind.elem_addr = elem_addr;
change.cfg_mod_app_unbind.app_idx = key_app_idx;
change.cfg_mod_app_unbind.cid = vnd ? mod->vnd.company : 0xFFFF;
change.cfg_mod_app_unbind.mod_id = vnd ? mod->vnd.id : mod->id;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
}
#define KEY_LIST_LEN (CONFIG_BLE_MESH_MODEL_KEY_COUNT * 2)
@ -2857,6 +2952,12 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
}
send_krp_status(model, ctx, idx, sub->kr_phase, STATUS_SUCCESS);
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_kr_phase_set.net_idx = idx;
change.cfg_kr_phase_set.kr_phase = phase;
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
model, ctx, (const u8_t *)&change, sizeof(change));
}
static u8_t hb_log(u16_t val)
@ -3129,7 +3230,7 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
* MESH/NODE/CFG/HBS/BV-02-C.
*/
if (sub_src == BLE_MESH_ADDR_UNASSIGNED ||
sub_dst == BLE_MESH_ADDR_UNASSIGNED) {
sub_dst == BLE_MESH_ADDR_UNASSIGNED) {
cfg->hb_sub.src = BLE_MESH_ADDR_UNASSIGNED;
cfg->hb_sub.dst = BLE_MESH_ADDR_UNASSIGNED;
cfg->hb_sub.min_hops = BLE_MESH_TTL_MAX;
@ -3295,7 +3396,7 @@ int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary)
cfg->frnd = BLE_MESH_FRIEND_NOT_SUPPORTED;
}
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
cfg->gatt_proxy = BLE_MESH_GATT_PROXY_NOT_SUPPORTED;
}

View file

@ -65,6 +65,18 @@ static struct friend_adv {
u64_t seq_auth;
} adv_pool[FRIEND_BUF_COUNT];
enum {
BLE_MESH_FRIENDSHIP_TERMINATE_ESTABLISH_FAIL,
BLE_MESH_FRIENDSHIP_TERMINATE_POLL_TIMEOUT,
BLE_MESH_FRIENDSHIP_TERMINATE_RECV_FRND_REQ,
BLE_MESH_FRIENDSHIP_TERMINATE_RECV_FRND_CLEAR,
BLE_MESH_FRIENDSHIP_TERMINATE_DISABLE,
};
static void (*friend_cb)(bool establish, u16_t lpn_addr, u8_t reason);
static struct bt_mesh_adv *adv_alloc(int id)
{
return &adv_pool[id].adv;
@ -137,7 +149,7 @@ static s32_t recv_delay(struct bt_mesh_friend *frnd)
#endif
}
static void friend_clear(struct bt_mesh_friend *frnd)
static void friend_clear(struct bt_mesh_friend *frnd, u8_t reason)
{
int i;
@ -145,6 +157,12 @@ static void friend_clear(struct bt_mesh_friend *frnd)
k_delayed_work_cancel(&frnd->timer);
if (frnd->established) {
if (friend_cb) {
friend_cb(false, frnd->lpn, reason);
}
}
friend_cred_del(frnd->net_idx, frnd->lpn);
if (frnd->last) {
@ -189,7 +207,7 @@ void bt_mesh_friend_clear_net_idx(u16_t net_idx)
}
if (net_idx == BLE_MESH_KEY_ANY || frnd->net_idx == net_idx) {
friend_clear(frnd);
friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_DISABLE);
}
}
}
@ -262,7 +280,7 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_CLEAR_CFM, &cfm,
sizeof(cfm), NULL, NULL, NULL);
friend_clear(frnd);
friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_RECV_FRND_CLEAR);
return 0;
}
@ -568,6 +586,9 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
if (!frnd->established) {
BT_DBG("Friendship established with 0x%04x", frnd->lpn);
frnd->established = 1U;
if (friend_cb) {
friend_cb(true, frnd->lpn, 0);
}
}
if (msg->fsn == frnd->fsn && frnd->last) {
@ -828,7 +849,7 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, false);
if (frnd) {
BT_WARN("%s, Existing LPN re-requesting Friendship", __func__);
friend_clear(frnd);
friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_RECV_FRND_REQ);
goto init_friend;
}
@ -857,6 +878,13 @@ init_friend:
BT_DBG("LPN 0x%04x rssi %d recv_delay %u poll_to %ums",
frnd->lpn, rx->rssi, frnd->recv_delay, frnd->poll_to);
/**
* Spec says:
* After a friendship has been established, if the PreviousAddress field
* of the Friend Request message contains a valid unicast address that is
* not the Friend nodes own unicast address, then the Friend node shall
* begin sending Friend Clear messages to that unicast address.
*/
if (BLE_MESH_ADDR_IS_UNICAST(frnd->clear.frnd) &&
!bt_mesh_elem_find(frnd->clear.frnd)) {
clear_procedure_start(frnd);
@ -874,8 +902,8 @@ init_friend:
}
static struct bt_mesh_friend_seg *get_seg(struct bt_mesh_friend *frnd,
u16_t src, u64_t *seq_auth,
u8_t seg_count)
u16_t src, u64_t *seq_auth,
u8_t seg_count)
{
struct bt_mesh_friend_seg *unassigned = NULL;
int i;
@ -923,7 +951,7 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
seg = get_seg(frnd, BLE_MESH_ADV(buf)->addr, &adv->seq_auth, seg_count);
if (!seg) {
BT_ERR("%s, No free friend segment RX contexts for 0x%04x",
__func__, BLE_MESH_ADV(buf)->addr);
__func__, BLE_MESH_ADV(buf)->addr);
net_buf_unref(buf);
return;
}
@ -1010,14 +1038,14 @@ static void friend_timeout(struct k_work *work)
if (frnd->established && !frnd->pending_req) {
BT_WARN("%s, Friendship lost with 0x%04x", __func__, frnd->lpn);
friend_clear(frnd);
friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_POLL_TIMEOUT);
return;
}
frnd->last = (void *)sys_slist_get(&frnd->queue);
if (!frnd->last) {
BT_WARN("%s, Friendship not established with 0x%04x", __func__, frnd->lpn);
friend_clear(frnd);
friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_ESTABLISH_FAIL);
return;
}
@ -1035,6 +1063,11 @@ send_last:
bt_mesh_adv_send(frnd->last, &buf_sent_cb, frnd);
}
void bt_mesh_friend_set_cb(void (*cb)(bool establish, u16_t lpn_addr, u8_t reason))
{
friend_cb = cb;
}
int bt_mesh_friend_init(void)
{
int i;
@ -1242,7 +1275,7 @@ static bool friend_queue_has_space(struct bt_mesh_friend *frnd, u16_t addr,
*/
buf = (void *)sys_slist_peek_head(&seg->queue);
if (buf && BLE_MESH_ADV(buf)->addr == addr &&
FRIEND_ADV(buf)->seq_auth == *seq_auth) {
FRIEND_ADV(buf)->seq_auth == *seq_auth) {
return true;
}
}
@ -1350,7 +1383,7 @@ void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx,
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
if (!friend_lpn_matches(frnd, rx->sub->net_idx,
rx->ctx.recv_dst)) {
rx->ctx.recv_dst)) {
continue;
}

View file

@ -76,7 +76,7 @@ static void timeout_handler(struct k_work *work)
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_health_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}

View file

@ -27,130 +27,112 @@
#include "foundation.h"
#include "mesh_common.h"
#define HEALTH_TEST_STANDARD 0x00
#include "btc_ble_mesh_health_model.h"
/* Maximum message length is 384 in BLE Mesh. Here for health fault status,
* due to 1 octet opcode and 4 octets TransMIC, 379 octets can be used to
* store health fault status.
*/
#define HEALTH_FAULT_MAX_LEN 379
#define HEALTH_TEST_STANDARD 0x00
#define HEALTH_NO_FAULT 0x00
/* Health Server context of the primary element */
struct bt_mesh_health_srv *health_srv;
static void health_get_registered(struct bt_mesh_model *mod,
u16_t company_id,
struct net_buf_simple *msg)
/**
* When an Element receives a Health Fault Get, or a Health Fault Test, or
* a Health Fault Test Unacknowledged, or a Health Fault Clear, or a Health
* Fault Clear Unacknowledged message that is not successfully processed
* (i.e. the Company ID field that does not identify any Health Fault state
* present in the node), it shall ignore the message.
* The Health Fault state is identified by Company ID and may be present in
* the node for more than one Company ID.
*/
static u8_t health_get_curr_fault_count(struct bt_mesh_model *model)
{
struct bt_mesh_health_srv *srv = mod->user_data;
u8_t *test_id;
struct bt_mesh_health_srv *srv = model->user_data;
u8_t count = 0;
size_t i;
BT_DBG("Company ID 0x%04x", company_id);
if (!srv) {
BT_ERR("%s, No Health Server context provided", __func__);
return;
for (i = 0U; i < ARRAY_SIZE(srv->test.curr_faults); i++) {
if (srv->test.curr_faults[i] != HEALTH_NO_FAULT) {
count++;
}
}
bt_mesh_model_msg_init(msg, OP_HEALTH_FAULT_STATUS);
return count;
}
test_id = net_buf_simple_add(msg, 1);
net_buf_simple_add_le16(msg, company_id);
static void health_get_fault_value(struct bt_mesh_model *model,
struct net_buf_simple *msg,
bool current)
{
struct bt_mesh_health_srv *srv = model->user_data;
size_t array_size;
size_t i;
if (srv->cb && srv->cb->fault_get_reg) {
u8_t fault_count = net_buf_simple_tailroom(msg) - 4;
int err;
array_size = current ? ARRAY_SIZE(srv->test.curr_faults) : ARRAY_SIZE(srv->test.reg_faults);
err = srv->cb->fault_get_reg(mod, company_id, test_id,
net_buf_simple_tail(msg),
&fault_count);
if (err) {
BT_ERR("%s, Failed to get faults (err %d)", __func__, err);
*test_id = HEALTH_TEST_STANDARD;
} else {
net_buf_simple_add(msg, fault_count);
for (i = 0U; i < array_size; i++) {
if (net_buf_simple_tailroom(msg) == 0) {
return;
}
u8_t fault = current ? srv->test.curr_faults[i] : srv->test.reg_faults[i];
if (fault != HEALTH_NO_FAULT) {
net_buf_simple_add_u8(msg, fault);
}
} else {
BT_WARN("No callback for getting faults");
*test_id = HEALTH_TEST_STANDARD;
}
}
static size_t health_get_current(struct bt_mesh_model *mod,
struct net_buf_simple *msg)
static bool health_is_test_id_exist(struct bt_mesh_model *model, u8_t test_id)
{
struct bt_mesh_health_srv *srv = mod->user_data;
const struct bt_mesh_comp *comp;
u8_t *test_id, *company_ptr;
u16_t company_id;
u8_t fault_count;
struct bt_mesh_health_srv *srv = model->user_data;
u8_t i;
for (i = 0U; i < srv->test.id_count; i++) {
if (srv->test.test_ids[i] == test_id) {
return true;
}
}
return false;
}
static int health_send_fault_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx)
{
struct bt_mesh_health_srv *srv = model->user_data;
struct net_buf_simple *msg = NULL;
int err;
if (!srv) {
BT_ERR("%s, No Health Server context provided", __func__);
return 0;
msg = bt_mesh_alloc_buf(4 + ARRAY_SIZE(srv->test.reg_faults) + 4);
if (!msg) {
BT_ERR("%s, Failed to allocate memory", __func__);
return -ENOMEM;
}
bt_mesh_model_msg_init(msg, OP_HEALTH_CURRENT_STATUS);
test_id = net_buf_simple_add(msg, 1);
company_ptr = net_buf_simple_add(msg, sizeof(company_id));
comp = bt_mesh_comp_get();
if (srv->cb && srv->cb->fault_get_cur) {
fault_count = net_buf_simple_tailroom(msg);
err = srv->cb->fault_get_cur(mod, test_id, &company_id,
net_buf_simple_tail(msg),
&fault_count);
if (err) {
BT_ERR("%s, Failed to get faults (err %d)", __func__, err);
sys_put_le16(comp->cid, company_ptr);
*test_id = HEALTH_TEST_STANDARD;
fault_count = 0U;
} else {
sys_put_le16(company_id, company_ptr);
net_buf_simple_add(msg, fault_count);
}
} else {
BT_WARN("No callback for getting faults");
sys_put_le16(comp->cid, company_ptr);
*test_id = HEALTH_TEST_STANDARD;
fault_count = 0U;
bt_mesh_model_msg_init(msg, OP_HEALTH_FAULT_STATUS);
net_buf_simple_add_u8(msg, srv->test.prev_test_id);
net_buf_simple_add_le16(msg, srv->test.company_id);
if (ctx->recv_op != OP_HEALTH_FAULT_CLEAR) {
/**
* For Health Fault Clear, the FaultArray field in Health Fault Status
* shall be empty.
*/
health_get_fault_value(model, msg, false);
}
return fault_count;
err = bt_mesh_model_send(model, ctx, msg, NULL, NULL);
if (err) {
BT_ERR("%s, Failed to send Health Fault Status response", __func__);
}
bt_mesh_free_buf(msg);
return err;
}
static void health_fault_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct net_buf_simple *sdu = NULL;
u16_t company_id;
company_id = net_buf_simple_pull_le16(buf);
BT_DBG("company_id 0x%04x", company_id);
sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN));
if (!sdu) {
BT_ERR("%s, Failed to allocate memory", __func__);
return;
}
health_get_registered(model, company_id, sdu);
if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) {
BT_ERR("%s, Unable to send Health Current Status", __func__);
}
bt_mesh_free_buf(sdu);
return;
}
static void health_fault_clear_unrel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_health_srv *srv = model->user_data;
u16_t company_id;
@ -161,12 +143,14 @@ static void health_fault_clear_unrel(struct bt_mesh_model *model,
}
company_id = net_buf_simple_pull_le16(buf);
if (company_id != srv->test.company_id) {
BT_ERR("%s, Unknown Company ID 0x%04x", __func__, company_id);
return;
}
BT_DBG("company_id 0x%04x", company_id);
if (srv->cb && srv->cb->fault_clear) {
srv->cb->fault_clear(model, company_id);
}
health_send_fault_status(model, ctx);
}
static void health_fault_clear(struct bt_mesh_model *model,
@ -174,7 +158,6 @@ static void health_fault_clear(struct bt_mesh_model *model,
struct net_buf_simple *buf)
{
struct bt_mesh_health_srv *srv = model->user_data;
struct net_buf_simple *sdu = NULL;
u16_t company_id;
if (!srv) {
@ -183,49 +166,21 @@ static void health_fault_clear(struct bt_mesh_model *model,
}
company_id = net_buf_simple_pull_le16(buf);
if (company_id != srv->test.company_id) {
BT_ERR("%s, Unknown Company ID 0x%04x", __func__, company_id);
return;
}
BT_DBG("company_id 0x%04x", company_id);
if (srv->cb && srv->cb->fault_clear) {
srv->cb->fault_clear(model, company_id);
memset(srv->test.reg_faults, HEALTH_NO_FAULT, ARRAY_SIZE(srv->test.reg_faults));
if (srv->cb.fault_clear) {
srv->cb.fault_clear(model, company_id);
}
sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN));
if (!sdu) {
BT_ERR("%s, Failed to allocate memory", __func__);
return;
}
health_get_registered(model, company_id, sdu);
if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) {
BT_ERR("%s, Unable to send Health Current Status", __func__);
}
bt_mesh_free_buf(sdu);
return;
}
static void health_fault_test_unrel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct bt_mesh_health_srv *srv = model->user_data;
u16_t company_id;
u8_t test_id;
if (!srv) {
BT_ERR("%s, No Health Server context provided", __func__);
return;
}
test_id = net_buf_simple_pull_u8(buf);
company_id = net_buf_simple_pull_le16(buf);
BT_DBG("test 0x%02x company 0x%04x", test_id, company_id);
if (srv->cb && srv->cb->fault_test) {
srv->cb->fault_test(model, test_id, company_id);
if (ctx->recv_op == OP_HEALTH_FAULT_CLEAR) {
health_send_fault_status(model, ctx);
}
}
@ -234,7 +189,6 @@ static void health_fault_test(struct bt_mesh_model *model,
struct net_buf_simple *buf)
{
struct bt_mesh_health_srv *srv = model->user_data;
struct net_buf_simple *sdu = NULL;
u16_t company_id;
u8_t test_id;
@ -246,34 +200,28 @@ static void health_fault_test(struct bt_mesh_model *model,
}
test_id = net_buf_simple_pull_u8(buf);
company_id = net_buf_simple_pull_le16(buf);
BT_DBG("test 0x%02x company 0x%04x", test_id, company_id);
if (srv->cb && srv->cb->fault_test) {
int err;
err = srv->cb->fault_test(model, test_id, company_id);
if (err) {
BT_WARN("Running fault test failed with err %d", err);
return;
}
}
sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN));
if (!sdu) {
BT_ERR("%s, Failed to allocate memory", __func__);
if (health_is_test_id_exist(model, test_id) == false) {
BT_ERR("%s, Unknown Test ID 0x%02x", __func__, test_id);
return;
}
health_get_registered(model, company_id, sdu);
if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) {
BT_ERR("%s, Unable to send Health Current Status", __func__);
company_id = net_buf_simple_pull_le16(buf);
if (company_id != srv->test.company_id) {
BT_ERR("%s, Unknown Company ID 0x%04x", __func__, company_id);
return;
}
bt_mesh_free_buf(sdu);
return;
BT_DBG("test 0x%02x company 0x%04x", test_id, company_id);
srv->test.prev_test_id = test_id;
if (srv->cb.fault_test) {
srv->cb.fault_test(model, test_id, company_id);
}
if (ctx->recv_op == OP_HEALTH_FAULT_TEST) {
health_send_fault_status(model, ctx);
}
}
static void send_attention_status(struct bt_mesh_model *model,
@ -293,7 +241,6 @@ static void send_attention_status(struct bt_mesh_model *model,
BT_DBG("%u second%s", time, (time == 1U) ? "" : "s");
bt_mesh_model_msg_init(&msg, OP_ATTENTION_STATUS);
net_buf_simple_add_u8(&msg, time);
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
@ -310,9 +257,9 @@ static void attention_get(struct bt_mesh_model *model,
send_attention_status(model, ctx);
}
static void attention_set_unrel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
static void health_set_attention(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
u8_t time;
@ -329,9 +276,11 @@ static void attention_set(struct bt_mesh_model *model,
{
BT_DBG("%s", __func__);
attention_set_unrel(model, ctx, buf);
health_set_attention(model, ctx, buf);
send_attention_status(model, ctx);
if (ctx->recv_op == OP_ATTENTION_SET) {
send_attention_status(model, ctx);
}
}
static void send_health_period_status(struct bt_mesh_model *model,
@ -341,7 +290,6 @@ static void send_health_period_status(struct bt_mesh_model *model,
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_STATUS);
net_buf_simple_add_u8(&msg, model->pub->period_div);
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
@ -358,9 +306,9 @@ static void health_period_get(struct bt_mesh_model *model,
send_health_period_status(model, ctx);
}
static void health_period_set_unrel(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
static void health_set_period(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
u8_t period;
@ -381,34 +329,64 @@ static void health_period_set(struct bt_mesh_model *model,
{
BT_DBG("%s", __func__);
health_period_set_unrel(model, ctx, buf);
health_set_period(model, ctx, buf);
send_health_period_status(model, ctx);
if (ctx->recv_op == OP_HEALTH_PERIOD_SET) {
send_health_period_status(model, ctx);
}
}
const struct bt_mesh_model_op bt_mesh_health_srv_op[] = {
{ OP_HEALTH_FAULT_GET, 2, health_fault_get },
{ OP_HEALTH_FAULT_GET, 2, health_fault_get },
{ OP_HEALTH_FAULT_CLEAR, 2, health_fault_clear },
{ OP_HEALTH_FAULT_CLEAR_UNREL, 2, health_fault_clear_unrel },
{ OP_HEALTH_FAULT_TEST, 3, health_fault_test },
{ OP_HEALTH_FAULT_TEST_UNREL, 3, health_fault_test_unrel },
{ OP_HEALTH_PERIOD_GET, 0, health_period_get },
{ OP_HEALTH_PERIOD_SET, 1, health_period_set },
{ OP_HEALTH_PERIOD_SET_UNREL, 1, health_period_set_unrel },
{ OP_ATTENTION_GET, 0, attention_get },
{ OP_ATTENTION_SET, 1, attention_set },
{ OP_ATTENTION_SET_UNREL, 1, attention_set_unrel },
{ OP_HEALTH_FAULT_CLEAR_UNREL, 2, health_fault_clear },
{ OP_HEALTH_FAULT_TEST, 3, health_fault_test },
{ OP_HEALTH_FAULT_TEST_UNREL, 3, health_fault_test },
{ OP_HEALTH_PERIOD_GET, 0, health_period_get },
{ OP_HEALTH_PERIOD_SET, 1, health_period_set },
{ OP_HEALTH_PERIOD_SET_UNREL, 1, health_period_set },
{ OP_ATTENTION_GET, 0, attention_get },
{ OP_ATTENTION_SET, 1, attention_set },
{ OP_ATTENTION_SET_UNREL, 1, attention_set },
BLE_MESH_MODEL_OP_END,
};
static int health_pub_update(struct bt_mesh_model *mod)
static size_t health_get_current(struct bt_mesh_model *model,
struct net_buf_simple *msg)
{
struct bt_mesh_model_pub *pub = mod->pub;
struct bt_mesh_health_srv *srv = model->user_data;
if (!srv) {
BT_ERR("%s, No Health Server context provided", __func__);
return 0;
}
if (msg->size < 4) {
BT_ERR("%s, Too small health publication msg size %d", __func__, msg->size);
return 0;
}
bt_mesh_model_msg_init(msg, OP_HEALTH_CURRENT_STATUS);
net_buf_simple_add_u8(msg, srv->test.prev_test_id);
net_buf_simple_add_le16(msg, srv->test.company_id);
health_get_fault_value(model, msg, true);
return health_get_curr_fault_count(model);
}
static int health_pub_update(struct bt_mesh_model *model)
{
struct bt_mesh_model_pub *pub = model->pub;
size_t count;
BT_DBG("%s", __func__);
count = health_get_current(mod, pub->msg);
if (!pub || !pub->msg) {
BT_ERR("%s, Invalid health publication context", __func__);
return -EINVAL;
}
count = health_get_current(model, pub->msg);
if (count) {
pub->fast_period = 1U;
} else {
@ -420,29 +398,29 @@ static int health_pub_update(struct bt_mesh_model *mod)
int bt_mesh_fault_update(struct bt_mesh_elem *elem)
{
struct bt_mesh_model *mod;
struct bt_mesh_model *model;
mod = bt_mesh_model_find(elem, BLE_MESH_MODEL_ID_HEALTH_SRV);
if (!mod) {
model = bt_mesh_model_find(elem, BLE_MESH_MODEL_ID_HEALTH_SRV);
if (!model) {
BT_ERR("%s, Health Server does not exist", __func__);
return -EINVAL;
}
if (!mod->pub) {
if (!model->pub) {
BT_ERR("%s, Health Server has no publication support", __func__);
return -EIO;
return -EINVAL;
}
/* Let periodic publishing, if enabled, take care of sending the
* Health Current Status.
*/
if (bt_mesh_model_pub_period_get(mod)) {
if (bt_mesh_model_pub_period_get(model)) {
return 0;
}
health_pub_update(mod);
health_pub_update(model);
return bt_mesh_model_publish(mod);
return bt_mesh_model_publish(model);
}
static void attention_off(struct k_work *work)
@ -457,17 +435,23 @@ static void attention_off(struct k_work *work)
return;
}
if (srv->cb && srv->cb->attn_off) {
srv->cb->attn_off(srv->model);
if (srv->cb.attn_off) {
srv->cb.attn_off(srv->model);
}
srv->attn_timer_start = false;
}
int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary)
{
struct bt_mesh_health_srv *srv = model->user_data;
/* Health Server Model shall be supported by a primary element and may be
* supported by any secondary elements.
*/
if (!srv) {
if (!primary) {
/* If Health Server is in the secondary element with NULL user_data. */
return 0;
}
@ -475,6 +459,11 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary)
return -EINVAL;
}
if (srv->test.id_count == 0 || !srv->test.test_ids) {
BT_ERR("%s, No Health Test ID provided", __func__);
return -EINVAL;
}
if (!model->pub) {
BT_ERR("%s, Health Server has no publication support", __func__);
return -EINVAL;
@ -485,6 +474,10 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary)
k_delayed_work_init(&srv->attn_timer, attention_off);
srv->model = model;
srv->attn_timer_start = false;
memset(srv->test.curr_faults, HEALTH_NO_FAULT, ARRAY_SIZE(srv->test.curr_faults));
memset(srv->test.reg_faults, HEALTH_NO_FAULT, ARRAY_SIZE(srv->test.reg_faults));
if (primary) {
health_srv = srv;
@ -514,16 +507,20 @@ void bt_mesh_attention(struct bt_mesh_model *model, u8_t time)
}
if (time) {
if (srv->cb && srv->cb->attn_on) {
srv->cb->attn_on(model);
if (srv->cb.attn_on) {
srv->cb.attn_on(model, time);
}
k_delayed_work_submit(&srv->attn_timer, time * 1000U);
srv->attn_timer_start = true;
} else {
k_delayed_work_cancel(&srv->attn_timer);
if (srv->cb && srv->cb->attn_off) {
srv->cb->attn_off(model);
if (srv->attn_timer_start == true) {
if (srv->cb.attn_off) {
srv->cb.attn_off(model);
}
srv->attn_timer_start = false;
}
}
}

View file

@ -65,6 +65,149 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_SRV, \
bt_mesh_cfg_srv_op, NULL, srv_data)
typedef union {
struct {
u8_t beacon;
} cfg_beacon_set;
struct {
u8_t ttl;
} cfg_default_ttl_set;
struct {
u8_t gatt_proxy;
} cfg_gatt_proxy_set;
struct {
u8_t relay;
u8_t retransmit;
} cfg_relay_set;
struct {
u16_t elem_addr;
u16_t pub_addr;
u16_t app_idx;
bool cred_flag;
u8_t ttl;
u8_t period;
u8_t transmit;
u16_t cid;
u16_t mod_id;
} cfg_mod_pub_set;
struct {
u16_t elem_addr;
u8_t pub_addr[16];
u16_t app_idx;
bool cred_flag;
u8_t ttl;
u8_t period;
u8_t transmit;
u16_t cid;
u16_t mod_id;
} cfg_mod_pub_va_set;
struct {
u16_t elem_addr;
u16_t sub_addr;
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_add;
struct {
u16_t elem_addr;
u8_t sub_addr[16];
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_va_add;
struct {
u16_t elem_addr;
u16_t sub_addr;
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_delete;
struct {
u16_t elem_addr;
u8_t sub_addr[16];
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_va_delete;
struct {
u16_t elem_addr;
u16_t sub_addr;
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_overwrite;
struct {
u16_t elem_addr;
u8_t sub_addr[16];
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_va_overwrite;
struct {
u16_t elem_addr;
u16_t cid;
u16_t mod_id;
} cfg_mod_sub_delete_all;
struct {
u16_t net_idx;
u8_t net_key[16];
} cfg_netkey_add;
struct {
u16_t net_idx;
u8_t net_key[16];
} cfg_netkey_update;
struct {
u16_t net_idx;
} cfg_netkey_delete;
struct {
u16_t net_idx;
u16_t app_idx;
u8_t app_key[16];
} cfg_appkey_add;
struct {
u16_t net_idx;
u16_t app_idx;
u8_t app_key[16];
} cfg_appkey_update;
struct {
u16_t net_idx;
u16_t app_idx;
} cfg_appkey_delete;
struct {
u16_t net_idx;
u8_t identity;
} cfg_node_identity_set;
struct {
u16_t elem_addr;
u16_t app_idx;
u16_t cid;
u16_t mod_id;
} cfg_mod_app_bind;
struct {
u16_t elem_addr;
u16_t app_idx;
u16_t cid;
u16_t mod_id;
} cfg_mod_app_unbind;
struct {
u8_t frnd;
} cfg_friend_set;
struct {
u16_t net_idx;
u8_t kr_phase;
} cfg_kr_phase_set;
struct {
u16_t dst;
u8_t count;
u8_t period;
u8_t ttl;
u16_t feat;
u16_t net_idx;
} cfg_hb_pub_set;
struct {
u16_t src;
u16_t dst;
u8_t period;
} cfg_hb_sub_set;
struct {
u8_t transmit;
} cfg_net_transmit_set;
} bt_mesh_cfg_server_state_change_t;
/**
* @}
*/

View file

@ -21,25 +21,15 @@
*/
struct bt_mesh_health_srv_cb {
/* Fetch current faults */
int (*fault_get_cur)(struct bt_mesh_model *model, u8_t *test_id,
u16_t *company_id, u8_t *faults,
u8_t *fault_count);
/* Fetch registered faults */
int (*fault_get_reg)(struct bt_mesh_model *model, u16_t company_id,
u8_t *test_id, u8_t *faults,
u8_t *fault_count);
/* Clear registered faults */
int (*fault_clear)(struct bt_mesh_model *model, u16_t company_id);
void (*fault_clear)(struct bt_mesh_model *model, u16_t company_id);
/* Run a specific test */
int (*fault_test)(struct bt_mesh_model *model, u8_t test_id,
u16_t company_id);
void (*fault_test)(struct bt_mesh_model *model, u8_t test_id,
u16_t company_id);
/* Attention on */
void (*attn_on)(struct bt_mesh_model *model);
void (*attn_on)(struct bt_mesh_model *model, u8_t time);
/* Attention off */
void (*attn_off)(struct bt_mesh_model *model);
@ -55,15 +45,30 @@ struct bt_mesh_health_srv_cb {
#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 {
u8_t id_count; /* Number of Health self-test ID */
const u8_t *test_ids; /* Array of Health self-test IDs */
u16_t company_id; /* Company ID used to identify the Health Fault state */
u8_t prev_test_id; /* Most currently performed test id */
u8_t curr_faults[32]; /* Array of current faults */
u8_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 */
const struct bt_mesh_health_srv_cb *cb;
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[];

View file

@ -17,7 +17,8 @@
/* BLE Mesh Max Connection Count */
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
#define BLE_MESH_MAX_CONN \
MIN(CONFIG_BT_ACL_CONNECTIONS, CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN)
#define ADV_TASK_CORE TASK_PINNED_TO_CORE
#endif
@ -445,7 +446,7 @@ typedef void (*bt_mesh_dh_key_cb_t)(const u8_t key[32], const u8_t idx);
* or BLE_MESH_GATT_ITER_STOP to stop.
*/
typedef u8_t (*bt_mesh_gatt_attr_func_t)(const struct bt_mesh_gatt_attr *attr,
void *user_data);
void *user_data);
/** @brief Connection callback structure.
*
@ -481,15 +482,15 @@ struct bt_mesh_conn_cb {
};
struct bt_mesh_prov_conn_cb {
void (*connected)(const u8_t addr[6], struct bt_mesh_conn *conn, int id);
void (*connected)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int id);
void (*disconnected)(struct bt_mesh_conn *conn, u8_t reason);
void (*disconnected)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, u8_t reason);
ssize_t (*prov_write_descr)(struct bt_mesh_conn *conn, u8_t *addr);
ssize_t (*prov_write_descr)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn);
ssize_t (*prov_notify)(struct bt_mesh_conn *conn, u8_t *data, u16_t len);
ssize_t (*proxy_write_descr)(struct bt_mesh_conn *conn);
ssize_t (*proxy_write_descr)(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn);
ssize_t (*proxy_notify)(struct bt_mesh_conn *conn, u8_t *data, u16_t len);
};
@ -656,20 +657,20 @@ int bt_mesh_gatts_service_register(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, u16_t len, u16_t offset);
const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t len, u16_t offset);
ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t buf_len, u16_t offset,
const void *value, u16_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, u16_t len, u16_t offset);
const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t len, u16_t offset);
ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr, void *buf,
u16_t len, u16_t offset);
const struct bt_mesh_gatt_attr *attr, void *buf,
u16_t len, u16_t offset);
int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr,
const void *data, u16_t len);
@ -682,6 +683,8 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc);
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb);
u8_t bt_mesh_gattc_get_free_conn_count(void);
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn);
int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid);
@ -716,10 +719,10 @@ bool bt_mesh_check_public_key(const uint8_t key[64]);
int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u8_t idx);
int bt_mesh_encrypt_le(const u8_t key[16], const u8_t plaintext[16],
u8_t enc_data[16]);
u8_t enc_data[16]);
int bt_mesh_encrypt_be(const u8_t key[16], const u8_t plaintext[16],
u8_t enc_data[16]);
u8_t enc_data[16]);
enum {
BLE_MESH_EXCEP_LIST_ADD = 0,

View file

@ -280,7 +280,6 @@ struct bt_mesh_prov {
*
* @param bearer Provisioning bearer.
* @param reason Provisioning link close reason(disconnect reason)
* 0xFF: disconnect due to provisioner_pb_gatt_disable()
*/
void (*prov_link_close)(bt_mesh_prov_bearer_t bearer, u8_t reason);
@ -555,10 +554,13 @@ bool bt_mesh_iv_update(void);
* 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);
int bt_mesh_lpn_set(bool enable, bool force);
/** @brief Send out a Friend Poll message.
*
@ -578,6 +580,15 @@ int bt_mesh_lpn_poll(void);
*/
void bt_mesh_lpn_set_cb(void (*cb)(u16_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, u16_t lpn_addr, u8_t reason));
/**
* @}
*/

View file

@ -55,8 +55,11 @@
#define POLL_TIMEOUT_MAX(lpn) ((CONFIG_BLE_MESH_LPN_POLL_TIMEOUT * 100) - \
REQ_RETRY_DURATION(lpn))
/* Update 4 to 20 for BQB test case MESH/NODE/FRND/LPM/BI-02-C */
#define REQ_ATTEMPTS(lpn) (POLL_TIMEOUT_MAX(lpn) < K_SECONDS(3) ? 2 : 4)
/**
* 1. Should use 20 attempts for BQB test case MESH/NODE/FRND/LPM/BI-02-C.
* 2. We should use more specific value for each PollTimeout range.
*/
#define REQ_ATTEMPTS(lpn) (POLL_TIMEOUT_MAX(lpn) < K_SECONDS(3) ? 2 : 6)
#define CLEAR_ATTEMPTS 2
@ -70,9 +73,10 @@
/* 2 transmissions, 20ms interval */
#define POLL_XMIT BLE_MESH_TRANSMIT(1, 20)
#define FIRST_POLL_ATTEMPTS 6
static void (*lpn_cb)(u16_t friend_addr, bool established);
#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER)
static const char *state2str(int state)
{
switch (state) {
@ -94,17 +98,16 @@ static const char *state2str(int state)
return "recv delay";
case BLE_MESH_LPN_WAIT_UPDATE:
return "wait update";
case BLE_MESH_LPN_OFFER_RECV:
return "offer recv";
default:
return "(unknown)";
}
}
#endif /* CONFIG_BLE_MESH_DEBUG_LOW_POWER */
static inline void lpn_set_state(int state)
{
#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER)
BT_DBG("%s -> %s", state2str(bt_mesh.lpn.state), state2str(state));
#endif
bt_mesh.lpn.state = state;
}
@ -149,6 +152,8 @@ static inline void group_clear(bt_mesh_atomic_t *target, bt_mesh_atomic_t *sourc
static void clear_friendship(bool force, bool disable);
static bool scan_after_clear;
static void friend_clear_sent(int err, void *user_data)
{
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
@ -156,7 +161,10 @@ static void friend_clear_sent(int err, void *user_data)
/* We're switching away from Low Power behavior, so permanently
* enable scanning.
*/
bt_mesh_scan_enable();
if (scan_after_clear == false) {
bt_mesh_scan_enable();
scan_after_clear = true;
}
lpn->req_attempts++;
@ -261,6 +269,11 @@ static void clear_friendship(bool force, bool disable)
lpn_set_state(BLE_MESH_LPN_ENABLED);
k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT);
scan_after_clear = false;
if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) {
bt_mesh_scan_disable();
}
}
static void friend_req_sent(u16_t duration, int err, void *user_data)
@ -269,6 +282,10 @@ static void friend_req_sent(u16_t duration, int err, void *user_data)
if (err) {
BT_ERR("%s, Sending Friend Request failed (err %d)", __func__, err);
if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) {
bt_mesh_scan_enable();
}
return;
}
@ -322,10 +339,8 @@ static void req_sent(u16_t duration, int err, void *user_data)
{
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER)
BT_DBG("req 0x%02x duration %u err %d state %s",
lpn->sent_req, duration, err, state2str(lpn->state));
#endif
if (err) {
BT_ERR("%s, Sending request failed (err %d)", __func__, err);
@ -346,6 +361,12 @@ static void req_sent(u16_t duration, int err, void *user_data)
LPN_RECV_DELAY - SCAN_LATENCY);
} else {
lpn_set_state(BLE_MESH_LPN_OFFER_RECV);
/**
* Friend Update is replied by Friend Node with TTL set to 0 and Network
* Transmit set to 30ms which will cause the packet easy to be missed.
* Regarding this situation, here we can reduce the duration of receiving
* the first Friend Update.
*/
k_delayed_work_submit(&lpn->timer,
LPN_RECV_DELAY + duration +
lpn->recv_win);
@ -404,7 +425,7 @@ void bt_mesh_lpn_disable(bool force)
clear_friendship(force, true);
}
int bt_mesh_lpn_set(bool enable)
int bt_mesh_lpn_set(bool enable, bool force)
{
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
@ -442,7 +463,7 @@ int bt_mesh_lpn_set(bool enable)
k_delayed_work_cancel(&lpn->timer);
lpn_set_state(BLE_MESH_LPN_DISABLED);
} else {
bt_mesh_lpn_disable(false);
bt_mesh_lpn_disable(force);
}
}
@ -543,6 +564,10 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
lpn->counter++;
if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) {
bt_mesh_scan_disable();
}
return 0;
}
@ -720,7 +745,7 @@ static void update_timeout(struct bt_mesh_lpn *lpn)
bt_mesh_scan_disable();
}
if (lpn->req_attempts < 6) {
if (lpn->req_attempts < FIRST_POLL_ATTEMPTS) {
BT_WARN("Retrying first Friend Poll");
lpn->sent_req = 0U;
if (send_friend_poll() == 0) {
@ -737,9 +762,7 @@ static void lpn_timeout(struct k_work *work)
{
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER)
BT_DBG("state: %s", state2str(lpn->state));
#endif
switch (lpn->state) {
case BLE_MESH_LPN_DISABLED:
@ -774,9 +797,15 @@ static void lpn_timeout(struct k_work *work)
k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT);
break;
case BLE_MESH_LPN_OFFER_RECV:
BT_WARN("No Friend Update received after the first Friend Poll");
lpn->sent_req = 0U;
send_friend_poll();
if (lpn->req_attempts < FIRST_POLL_ATTEMPTS) {
BT_WARN("Retrying the first Friend Poll, %d attempts", lpn->req_attempts);
lpn->sent_req = 0U;
send_friend_poll();
break;
}
BT_ERR("Timeout waiting for the first Friend Update");
clear_friendship(true, false);
break;
case BLE_MESH_LPN_ESTABLISHED:
if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) {
@ -1047,9 +1076,7 @@ int bt_mesh_lpn_init(void)
k_delayed_work_init(&lpn->timer, lpn_timeout);
if (lpn->state == BLE_MESH_LPN_ENABLED) {
if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) {
bt_mesh_scan_disable();
} else {
if (!IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) {
bt_mesh_scan_enable();
}

View file

@ -28,11 +28,11 @@
#include "transport.h"
#include "access.h"
#include "foundation.h"
#include "proxy.h"
#include "proxy_server.h"
#include "settings.h"
#include "mesh.h"
#include "provisioner_prov.h"
#include "provisioner_proxy.h"
#include "proxy_client.h"
#include "provisioner_main.h"
static volatile bool provisioner_en = false;
@ -127,7 +127,7 @@ void bt_mesh_reset(void)
bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY);
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
bt_mesh_proxy_gatt_disable();
}
@ -296,7 +296,7 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
#if CONFIG_BLE_MESH_NODE
extern struct bt_mesh_gatt_service proxy_svc;
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
bt_mesh_gatts_service_register(&proxy_svc);
}
@ -340,8 +340,9 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
#if CONFIG_BLE_MESH_NODE
bt_mesh_proxy_init();
#endif
#if CONFIG_BLE_MESH_PROVISIONER
provisioner_proxy_init();
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
bt_mesh_proxy_prov_client_init();
#endif
}
@ -390,18 +391,13 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
(bearers & BLE_MESH_PROV_ADV)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL);
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL);
}
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
(bearers & BLE_MESH_PROV_GATT)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL);
}
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV, NULL);
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL);
}
#endif
@ -469,7 +465,7 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action)
* here. The node needs to send some status messages to the phone
* while it is connected.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
bt_mesh_proxy_gatt_disable();
}
#endif
@ -490,7 +486,7 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action)
}
#if 0
/* Mesh Proxy GATT will be re-enabled on application layer */
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_NOT_SUPPORTED) {
bt_mesh_proxy_gatt_enable();
bt_mesh_adv_update();

View file

@ -26,7 +26,7 @@
#include "net.h"
#include "lpn.h"
#include "friend.h"
#include "proxy.h"
#include "proxy_server.h"
#include "transport.h"
#include "access.h"
#include "foundation.h"
@ -34,6 +34,7 @@
#include "settings.h"
#include "prov.h"
#include "provisioner_main.h"
#include "proxy_client.h"
/* Minimum valid Mesh Network PDU length. The Network headers
* themselves take up 9 bytes. After that there is a minumum of 1 byte
@ -89,6 +90,10 @@ struct bt_mesh_net bt_mesh = {
static u32_t dup_cache[4];
static int dup_cache_next;
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#define BLE_MESH_MAX_STORED_RELAY_COUNT (CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT / 2)
#endif
static bool check_dup(struct net_buf_simple *data)
{
const u8_t *tail = net_buf_simple_tail(data);
@ -187,7 +192,7 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
BT_DBG("NetID %s", bt_hex(keys->net_id, 8));
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
err = bt_mesh_identity_key(key, keys->identity);
if (err) {
BT_ERR("%s, Unable to generate IdentityKey", __func__);
@ -469,7 +474,7 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
sub->net_idx = idx;
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED;
} else {
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
@ -477,7 +482,7 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
bt_mesh.iv_index = iv_index;
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS,
BLE_MESH_IV_UPDATE(flags));
BLE_MESH_IV_UPDATE(flags));
/* Set minimum required hours, since the 96-hour minimum requirement
* doesn't apply straight after provisioning (since we can't know how
@ -609,7 +614,7 @@ void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub)
bt_mesh_friend_sec_update(sub ? sub->net_idx : BLE_MESH_KEY_ANY);
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) {
#if CONFIG_BLE_MESH_NODE
bt_mesh_proxy_beacon_send(sub);
@ -724,8 +729,8 @@ u32_t bt_mesh_next_seq(void)
}
if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS) &&
bt_mesh.seq > IV_UPDATE_SEQ_LIMIT &&
bt_mesh_subnet_get(BLE_MESH_KEY_PRIMARY)) {
bt_mesh.seq > IV_UPDATE_SEQ_LIMIT &&
bt_mesh_subnet_get(BLE_MESH_KEY_PRIMARY)) {
#if CONFIG_BLE_MESH_NODE
bt_mesh_beacon_ivu_initiator(true);
#endif
@ -785,8 +790,8 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
}
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
bt_mesh_proxy_relay(&buf->b, dst)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
bt_mesh_proxy_relay(&buf->b, dst)) {
send_cb_finalize(cb, cb_data);
return 0;
}
@ -897,12 +902,29 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
*/
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
tx->ctx->send_ttl != 1U) {
if (bt_mesh_proxy_relay(&buf->b, tx->ctx->addr) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* Notify completion if this only went
* through the Mesh Proxy.
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
tx->ctx->send_ttl != 1U) {
if (bt_mesh_proxy_relay(&buf->b, tx->ctx->addr) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* Notify completion if this only went
* through the Mesh Proxy.
*/
send_cb_finalize(cb, cb_data);
err = 0;
goto done;
}
}
}
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
if (tx->ctx->send_ttl != 1U) {
if (bt_mesh_proxy_client_send(&buf->b, tx->ctx->addr)) {
/* If Proxy Client succeeds to send messages with GATT bearer,
* we can directly finish here. And if not, which means no
* connection has been created with Proxy Client, here we will
* use advertising bearer for the messages.
*/
send_cb_finalize(cb, cb_data);
@ -910,7 +932,6 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
goto done;
}
}
}
#endif
/* Deliver to local network interface if necessary */
@ -1028,11 +1049,11 @@ static int net_decrypt(struct bt_mesh_subnet *sub, const u8_t *enc,
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY) &&
rx->net_if == BLE_MESH_NET_IF_PROXY_CFG) {
return bt_mesh_net_decrypt(enc, buf, BLE_MESH_NET_IVI_RX(rx),
true);
}
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY) &&
rx->net_if == BLE_MESH_NET_IF_PROXY_CFG) {
return bt_mesh_net_decrypt(enc, buf, BLE_MESH_NET_IVI_RX(rx),
true);
}
}
#endif
@ -1202,7 +1223,25 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
transmit = bt_mesh_net_transmit_get();
}
/**
* When the node tries to relay a Segment ACK message, in this case
* the corresponding segment packets (if exist) can be removed from
* the relay queue.
*/
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, transmit, K_NO_WAIT);
#else
/**
* Check if the number of relay packets in queue is too large, if so
* use minimum relay retransmit value for later relay packets.
*/
if (bt_mesh_get_stored_relay_count() >= BLE_MESH_MAX_STORED_RELAY_COUNT) {
transmit = BLE_MESH_TRANSMIT(0, 20);
}
buf = bt_mesh_relay_adv_create(BLE_MESH_ADV_DATA, transmit, K_NO_WAIT);
#endif
if (!buf) {
BT_ERR("%s, Out of relay buffers", __func__);
return;
@ -1246,7 +1285,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
/* Sending to the GATT bearer should only happen if GATT Proxy
* is enabled or the message originates from the local node.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
(bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED ||
rx->net_if == BLE_MESH_NET_IF_LOCAL)) {
if (bt_mesh_proxy_relay(&buf->b, rx->ctx.recv_dst) &&
@ -1256,7 +1295,11 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
}
if (relay_to_adv(rx->net_if)) {
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
bt_mesh_adv_send(buf, NULL, NULL);
#else
bt_mesh_relay_adv_send(buf, NULL, NULL, rx->ctx.addr, rx->ctx.recv_dst);
#endif
}
done:
@ -1373,7 +1416,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
net_if == BLE_MESH_NET_IF_PROXY) {
bt_mesh_proxy_addr_add(data, rx.ctx.addr);
}
@ -1402,11 +1445,11 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
*/
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_provisioned()) {
if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.recv_dst) ||
(!rx.local_match && !rx.friend_match)) {
net_buf_simple_restore(&buf, &state);
bt_mesh_net_relay(&buf, &rx);
}
if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.recv_dst) ||
(!rx.local_match && !rx.friend_match)) {
net_buf_simple_restore(&buf, &state);
bt_mesh_net_relay(&buf, &rx);
}
}
#endif
}
@ -1448,7 +1491,7 @@ void bt_mesh_net_start(void)
bt_mesh_beacon_disable();
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_NOT_SUPPORTED) {
bt_mesh_proxy_gatt_enable();
bt_mesh_adv_update();
@ -1457,7 +1500,7 @@ void bt_mesh_net_start(void)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Add Mesh beacon type (Secure Network Beacon) to the exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL);
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL);
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) {

View file

@ -67,7 +67,7 @@ struct bt_mesh_subnet {
u8_t nid; /* NID */
u8_t enc[16]; /* EncKey */
u8_t net_id[8]; /* Network ID */
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
u8_t identity[16]; /* IdentityKey */
#endif
u8_t privacy[16]; /* PrivacyKey */
@ -393,7 +393,7 @@ void friend_cred_clear(struct friend_cred *cred);
int friend_cred_del(u16_t net_idx, u16_t addr);
static inline void send_cb_finalize(const struct bt_mesh_send_cb *cb,
void *cb_data)
void *cb_data)
{
if (!cb) {
return;

View file

@ -37,11 +37,11 @@
/** @def BT_UUID_MESH_PROV
* @brief Mesh Provisioning Service
*/
*/
#define BT_UUID_MESH_PROV_VAL 0x1827
/** @def BT_UUID_MESH_PROXY
* @brief Mesh Proxy Service
*/
*/
#define BT_UUID_MESH_PROXY_VAL 0x1828
/** @def BT_UUID_GATT_CCC
* @brief GATT Client Characteristic Configuration
@ -128,12 +128,12 @@ void bt_mesh_hci_init(void)
}
static struct ble_gap_disc_params scan_param;
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static struct gattc_prov_info {
/* Service to be found depends on the type of adv pkt received */
struct bt_mesh_conn conn;
BD_ADDR addr;
u8_t addr_type;
bt_mesh_addr_t addr;
u16_t service_uuid;
u16_t mtu;
bool wr_desc_done; /* Indicate if write char descriptor event is received */
@ -147,18 +147,18 @@ static struct gattc_prov_info {
static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
static int ble_on_subscribe(uint16_t conn_handle,
const struct ble_gatt_error *error,
struct ble_gatt_attr *attr,
void *arg)
const struct ble_gatt_error *error,
struct ble_gatt_attr *attr,
void *arg)
{
struct bt_mesh_conn *conn = NULL;
uint8_t value[2] = {0x01, 0x00};
int i = (int)arg, j, len;
MODLOG_DFLT(INFO, "Subscribe complete; status=%d conn_handle=%d "
"attr_handle=%d\n",
"attr_handle=%d\n",
error->status, conn_handle, attr->handle);
for (j = i+1; j < ARRAY_SIZE(bt_mesh_gattc_info); j++) {
for (j = i + 1; j < ARRAY_SIZE(bt_mesh_gattc_info); j++) {
if ((bt_mesh_gattc_info[j].conn.handle == conn_handle) && bt_mesh_gattc_info[j].ccc_handle) {
break;
}
@ -175,7 +175,7 @@ static int ble_on_subscribe(uint16_t conn_handle,
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_write_descr != NULL) {
len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].conn, bt_mesh_gattc_info[i].addr);
len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn);
if (len < 0) {
BT_ERR("%s, prov_write_descr failed", __func__);
bt_mesh_gattc_disconnect(conn);
@ -185,12 +185,13 @@ static int ble_on_subscribe(uint16_t conn_handle,
}
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_write_descr != NULL) {
len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].conn);
len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn);
if (len < 0) {
BT_ERR("%s, proxy_write_descr failed", __func__);
bt_mesh_gattc_disconnect(conn);
return 0;
}
bt_mesh_gattc_info[i].wr_desc_done = true;
}
}
@ -203,8 +204,8 @@ static int ble_on_subscribe(uint16_t conn_handle,
}
static int dsc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
void *arg)
uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
void *arg)
{
int rc = 0, j, i = (int)arg; /* char index */
uint8_t value[2] = {0x01, 0x00};
@ -218,9 +219,9 @@ static int dsc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
/* All descriptors in this characteristic discovered; start discovering
* descriptors in the next characteristic.
*/
for (j = i+1; j < ARRAY_SIZE(bt_mesh_gattc_info); j++) {
for (j = i + 1; j < ARRAY_SIZE(bt_mesh_gattc_info); j++) {
if ((bt_mesh_gattc_info[j].conn.handle == conn_handle) && bt_mesh_gattc_info[j].data_out_handle) {
break;
break;
}
}
if (j == ARRAY_SIZE(bt_mesh_gattc_info)) {
@ -251,7 +252,7 @@ static int dsc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
const struct ble_gatt_chr *chr, void *arg)
const struct ble_gatt_chr *chr, void *arg)
{
int rc = 0, j;
uint16_t uuid16 = 0;
@ -284,9 +285,9 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
/* All characteristics in this service discovered; start discovering
* characteristics in the next service.
*/
for (j = i+1; j < ARRAY_SIZE(bt_mesh_gattc_info); j++) {
for (j = i + 1; j < ARRAY_SIZE(bt_mesh_gattc_info); j++) {
if ((bt_mesh_gattc_info[j].conn.handle == conn_handle) && (bt_mesh_gattc_info[j].start_handle > bt_mesh_gattc_info[j].end_handle)) {
break;
break;
}
}
if (j == ARRAY_SIZE(bt_mesh_gattc_info)) {
@ -298,7 +299,7 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
ble_gattc_disc_all_dscs(conn_handle, bt_mesh_gattc_info[j].data_out_handle, 0xffff, dsc_disced, (void *)j);
} else {
ble_gattc_disc_all_chrs(conn_handle, bt_mesh_gattc_info[j].start_handle, bt_mesh_gattc_info[j].end_handle,
chr_disced, (void *)j);
chr_disced, (void *)j);
}
break;
@ -312,7 +313,7 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
const struct ble_gatt_svc *service, void *arg)
const struct ble_gatt_svc *service, void *arg)
{
struct bt_mesh_conn *conn = NULL;
int rc = 0, i;
@ -326,7 +327,7 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
uuid = &service->uuid;
uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
if (uuid_length != 2) {
return 0;
return 0;
}
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].service_uuid == (uint16_t)BLE_UUID16(uuid)->value) {
@ -358,10 +359,10 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
/* Get the characteristic num within Mesh Provisioning/Proxy Service */
ble_gattc_disc_all_chrs(conn_handle, bt_mesh_gattc_info[i].start_handle, bt_mesh_gattc_info[i].end_handle,
chr_disced, (void *)i);
chr_disced, (void *)i);
break;
default:
default:
rc = error->status;
break;
}
@ -370,13 +371,14 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
}
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
static int disc_cb(struct ble_gap_event *event, void *arg)
{
struct ble_gap_disc_desc *desc;
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
int rc, i;
uint8_t notif_data[100];
uint16_t notif_len;
@ -401,7 +403,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
}
osi_free(buf);
break;
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status == 0) {
/* Connection successfully established. */
@ -412,9 +415,9 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->connected != NULL) {
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr, conn_desc.peer_id_addr.val, BLE_MESH_ADDR_LEN)) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, conn_desc.peer_id_addr.val, BLE_MESH_ADDR_LEN)) {
bt_mesh_gattc_info[i].conn.handle = event->connect.conn_handle;
(bt_mesh_gattc_conn_cb->connected)(bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i);
(bt_mesh_gattc_conn_cb->connected)(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i);
break;
}
}
@ -441,24 +444,36 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->disconnected != NULL) {
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
memcpy(&conn_desc, &event->disconnect.conn, sizeof(conn_desc));
if (!memcmp(bt_mesh_gattc_info[i].addr, conn_desc.peer_ota_addr.val, BLE_MESH_ADDR_LEN)) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, conn_desc.peer_ota_addr.val, BLE_MESH_ADDR_LEN)) {
if (bt_mesh_gattc_info[i].conn.handle == event->disconnect.conn.conn_handle) {
(bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].conn, event->disconnect.reason);
(bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, event->disconnect.reason);
if (!bt_mesh_gattc_info[i].wr_desc_done) {
/* Add this in case connection is established, connected event comes, but
* connection is terminated before server->filter_type is set to PROV.
*/
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr);
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr.val);
}
#endif
}
} else {
/* Add this in case connection is failed to be established, and here we
* need to clear some provision link info, like connecting flag, device
* uuid, address info, etc.
*/
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr);
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr.val);
}
#endif
}
/* Decrease prov pbg_count */
provisioner_pbg_count_dec();
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
/* Decrease prov pbg_count */
provisioner_pbg_count_dec();
}
#endif
/* Reset corresponding gattc info */
memset(&bt_mesh_gattc_info[i], 0, sizeof(bt_mesh_gattc_info[i]));
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
@ -514,8 +529,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
/* Data isn't populated yet */
return 0;
}
if (memcmp(bt_mesh_gattc_info[i].addr, conn_desc.peer_id_addr.val, BLE_MESH_ADDR_LEN) ||
if (memcmp(bt_mesh_gattc_info[i].addr.val, conn_desc.peer_id_addr.val, BLE_MESH_ADDR_LEN) ||
(bt_mesh_gattc_info[i].data_out_handle != event->notify_rx.attr_handle) ||
(event->notify_rx.indication != 0)) {
BT_ERR("%s, Notification error", __func__);
@ -693,7 +708,7 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
u16_t len = 0;
uint16_t ccc_val = 0;
if (event->subscribe.prev_notify != event->subscribe.cur_notify) {
if (event->subscribe.prev_notify != event->subscribe.cur_notify) {
ccc_val = event->subscribe.cur_notify;
} else if (event->subscribe.prev_indicate != event->subscribe.cur_indicate) {
if (event->subscribe.cur_indicate) {
@ -705,12 +720,12 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
if (attr != NULL && attr->write != NULL) {
if ((len = attr->write(&bt_mesh_gatts_conn[index], attr,
&ccc_val,
sizeof(ccc_val),
0 /* offset */, 0)) > 0) {
&ccc_val,
sizeof(ccc_val),
0 /* offset */, 0)) > 0) {
}
}
return 0;
case BLE_GAP_EVENT_MTU:
@ -917,7 +932,7 @@ static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle)
}
static void bt_mesh_gatts_foreach_attr(u16_t start_handle, u16_t end_handle,
bt_mesh_gatt_attr_func_t func, void *user_data)
bt_mesh_gatt_attr_func_t func, void *user_data)
{
struct bt_mesh_gatt_service *svc = NULL;
@ -984,8 +999,8 @@ struct gatts_incl {
} __packed;
ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
const struct bt_mesh_gatt_attr *attr,
void *buf, u16_t len, u16_t offset)
{
struct bt_mesh_gatt_attr *incl = attr->user_data;
struct bt_mesh_uuid *uuid = incl->user_data;
@ -1021,7 +1036,7 @@ ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn,
}
return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset,
BLE_MESH_UUID_128(uuid)->val, 16);
BLE_MESH_UUID_128(uuid)->val, 16);
}
struct gatts_chrc {
@ -1186,12 +1201,28 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc)
}
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb)
{
bt_mesh_gattc_conn_cb = cb;
}
u8_t bt_mesh_gattc_get_free_conn_count(void)
{
u8_t count = 0;
u8_t i;
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == 0xFFFF &&
bt_mesh_gattc_info[i].service_uuid == 0x0000) {
++count;
}
}
return count;
}
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
{
int i;
@ -1225,22 +1256,22 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
int i, rc;
if (!addr || !memcmp(addr->val, zero, BLE_MESH_ADDR_LEN) ||
(addr->type > BLE_ADDR_RANDOM)) {
(addr->type > BLE_ADDR_RANDOM)) {
BT_ERR("%s, Invalid remote address", __func__);
return -EINVAL;
}
if (service_uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
BT_ERR("%s, Invalid service uuid 0x%04x", __func__, service_uuid);
return -EINVAL;
}
/* Check if already creating connection with the device */
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (!memcmp(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN)) {
if (!memcmp(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN)) {
BT_WARN("%s, Already create connection with %s",
__func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
__func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
return -EALREADY;
}
}
@ -1248,9 +1279,9 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
/* Find empty element in queue to store device info */
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if ((bt_mesh_gattc_info[i].conn.handle == 0xFFFF) &&
(bt_mesh_gattc_info[i].service_uuid == 0x0000)) {
memcpy(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN);
bt_mesh_gattc_info[i].addr_type = addr->type;
(bt_mesh_gattc_info[i].service_uuid == 0x0000)) {
memcpy(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN);
bt_mesh_gattc_info[i].addr.type = addr->type;
/* Service to be found after exhanging mtu size */
bt_mesh_gattc_info[i].service_uuid = service_uuid;
break;
@ -1270,10 +1301,10 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
}
}
#else
rc = ble_gap_disc_cancel();
if (rc != 0) {
return -1;
}
rc = ble_gap_disc_cancel();
if (rc != 0) {
return -1;
}
#endif /* BLE_MESH_DEV */
BT_DBG("%s, create conn with %s", __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
@ -1296,19 +1327,17 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
ble_addr_t peer_addr;
memcpy(peer_addr.val, addr->val, 6);
peer_addr.type = addr->type;
peer_addr.type = addr->type;
rc = ble_gap_connect(BLE_OWN_ADDR_PUBLIC, &peer_addr, BLE_HS_FOREVER, &conn_params,
disc_cb, NULL);
/* Increment pbg_count */
provisioner_pbg_count_inc();
return 0;
return i;
}
static int mtu_cb(uint16_t conn_handle,
const struct ble_gatt_error *error,
uint16_t mtu, void *arg)
const struct ble_gatt_error *error,
uint16_t mtu, void *arg)
{
int i;
if (error->status == 0) {
@ -1417,7 +1446,7 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
* Mesh Proxy Data In: 0x2ADD
* Mesh PROXY Data Out: 0x2ADE
*/
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn)
{
@ -1437,7 +1466,7 @@ void bt_mesh_conn_unref(struct bt_mesh_conn *conn)
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR || ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(attr_handle);
@ -1445,14 +1474,14 @@ static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle,
u16_t len = 0;
BT_DBG("%s, write: handle = %d, len = %d, data = %s", __func__, attr_handle,
ctxt->om->om_len,
bt_hex(ctxt->om->om_data, ctxt->om->om_len));
ctxt->om->om_len,
bt_hex(ctxt->om->om_data, ctxt->om->om_len));
if (attr != NULL && attr->write != NULL) {
if ((len = attr->write(&bt_mesh_gatts_conn[index], attr,
ctxt->om->om_data,
ctxt->om->om_len,
0 /* offset */, 0)) > 0) {
ctxt->om->om_data,
ctxt->om->om_len,
0 /* offset */, 0)) > 0) {
}
}
} else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR || ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
@ -1462,7 +1491,7 @@ static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle,
}
static int dummy_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
/*
* We should never never enter this callback - it's attached to notify-only
@ -1474,50 +1503,54 @@ static int dummy_access_cb(uint16_t conn_handle, uint16_t attr_handle,
}
static const struct ble_gatt_svc_def svc_defs [] = {
#ifdef CONFIG_BLE_MESH_GATT_PROXY
{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL),
#ifdef CONFIG_BLE_MESH_GATT_PROXY_SERVER
{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL),
.includes = NULL,
.characteristics = (struct ble_gatt_chr_def[]) { {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_DATA_IN_VAL),
.access_cb = proxy_char_access_cb,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_DATA_OUT_VAL),
.access_cb = dummy_access_cb,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
0, /* No more characteristics in this service. */
} },
},
.characteristics = (struct ble_gatt_chr_def[])
{ {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_DATA_IN_VAL),
.access_cb = proxy_char_access_cb,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_DATA_OUT_VAL),
.access_cb = dummy_access_cb,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
0, /* No more characteristics in this service. */
}
},
},
#endif
#ifdef CONFIG_BLE_MESH_PB_GATT
{
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_VAL),
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_VAL),
.includes = NULL,
.characteristics = (struct ble_gatt_chr_def[]) { {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_DATA_IN_VAL),
.access_cb = proxy_char_access_cb,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_DATA_OUT_VAL),
.access_cb = dummy_access_cb,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
0, /* No more characteristics in this service. */
} },
},
.characteristics = (struct ble_gatt_chr_def[])
{ {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_DATA_IN_VAL),
.access_cb = proxy_char_access_cb,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
.uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_DATA_OUT_VAL),
.access_cb = dummy_access_cb,
.flags = BLE_GATT_CHR_F_NOTIFY,
}, {
0, /* No more characteristics in this service. */
}
},
},
#endif
{
0, /* No more services. */
},
0, /* No more services. */
},
};
#endif
void gatt_register_cb(struct ble_gatt_register_ctxt *ctxt,
void * arg )
void *arg )
{
if (ctxt->op == BLE_GATT_REGISTER_OP_SVC) {
if (ble_uuid_cmp(ctxt->svc.svc_def->uuid, BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL)) == 0) {
@ -1551,7 +1584,8 @@ void bt_mesh_gatt_init(void)
ble_gatts_svc_set_visibility(proxy_svc_start_handle, 0);
#endif
#if CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
bt_mesh_gattc_info[i].mtu = BLE_ATT_MTU_DFLT;
@ -1665,7 +1699,7 @@ exit:
}
int ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
uint8_t *our_priv_key, uint8_t *out_dhkey);
uint8_t *our_priv_key, uint8_t *out_dhkey);
int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u8_t idx)
{

View file

@ -24,7 +24,7 @@
#include "net.h"
#include "access.h"
#include "foundation.h"
#include "proxy.h"
#include "proxy_server.h"
#include "prov.h"
#if CONFIG_BLE_MESH_NODE
@ -292,7 +292,7 @@ static void reset_adv_link(void)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Remove the link id from exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id);
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id);
#endif
reset_state();
@ -1000,7 +1000,7 @@ static int bt_mesh_calc_dh_key(void)
}
int bt_mesh_set_oob_pub_key(const u8_t pub_key_x[32], const u8_t pub_key_y[32],
const u8_t pri_key[32])
const u8_t pri_key[32])
{
if (!pub_key_x || !pub_key_y || !pri_key) {
BT_ERR("%s, Invalid parameter", __func__);
@ -1203,7 +1203,7 @@ static void prov_data(const u8_t *data)
link.expect = 0U;
/* Store info, since bt_mesh_provision() will end up clearing it */
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
identity_enable = is_pb_gatt();
} else {
identity_enable = false;
@ -1218,7 +1218,7 @@ static void prov_data(const u8_t *data)
/* After PB-GATT provisioning we should start advertising
* using Node Identity.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && identity_enable) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && identity_enable) {
bt_mesh_proxy_identity_enable();
}
}
@ -1333,7 +1333,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Add the link id into exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id);
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id);
#endif
bearer_ctl_send(LINK_ACK, NULL, 0);
@ -1416,7 +1416,7 @@ static void prov_msg_recv(void)
if (1 + prov_handlers[type].len != link.rx.buf->len) {
BT_ERR("%s, Invalid length %u for type 0x%02x",
__func__, link.rx.buf->len, type);
__func__, link.rx.buf->len, type);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
@ -1466,7 +1466,7 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf)
((link.rx.last_seg - 1) * 23U));
if (expect_len != buf->len) {
BT_ERR("%s, Incorrect last seg len: %u != %u",
__func__, expect_len, buf->len);
__func__, expect_len, buf->len);
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
return;
}
@ -1526,7 +1526,7 @@ static void gen_prov_start(struct prov_rx *rx, struct net_buf_simple *buf)
if (link.rx.buf->len > link.rx.buf->size) {
BT_ERR("%s, Too large provisioning PDU (%u bytes)",
__func__, link.rx.buf->len);
__func__, link.rx.buf->len);
/* Zephyr uses prov_send_fail_msg() here */
return;
}

View file

@ -22,7 +22,7 @@ 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 u8_t pub_key_x[32], const u8_t pub_key_y[32],
const u8_t pri_key[32]);
const u8_t pri_key[32]);
const struct bt_mesh_prov *bt_mesh_prov_get(void);

View file

@ -30,7 +30,7 @@
#include "access.h"
#include "provisioner_prov.h"
#include "provisioner_proxy.h"
#include "proxy_client.h"
#include "provisioner_main.h"
#if CONFIG_BLE_MESH_PROVISIONER
@ -240,7 +240,7 @@ int provisioner_upper_init(void)
which has been initialized in the application layer */
bt_mesh.iv_index = prov->iv_index;
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS,
BLE_MESH_IV_UPDATE(prov->flags));
BLE_MESH_IV_UPDATE(prov->flags));
/* Set minimum required hours, since the 96-hour minimum requirement
* doesn't apply straight after provisioning (since we can't know how
@ -256,7 +256,9 @@ int provisioner_upper_init(void)
BT_DBG("netkey: %s, nid: 0x%x", bt_hex(sub->keys[0].net, 16), sub->keys[0].nid);
BT_DBG("enckey: %s", bt_hex(sub->keys[0].enc, 16));
BT_DBG("network id: %s", bt_hex(sub->keys[0].net_id, 8));
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
BT_DBG("identity: %s", bt_hex(sub->keys[0].identity, 16));
#endif
BT_DBG("privacy: %s", bt_hex(sub->keys[0].privacy, 16));
BT_DBG("beacon: %s", bt_hex(sub->keys[0].beacon, 16));

View file

@ -27,15 +27,13 @@
#include "adv.h"
#include "mesh.h"
#include "provisioner_prov.h"
#include "provisioner_proxy.h"
#include "proxy_client.h"
#include "provisioner_main.h"
#if CONFIG_BLE_MESH_PROVISIONER
/* Service data length has minus 1 type length & 2 uuid length*/
#define BLE_MESH_PROV_SRV_DATA_LEN 0x12
#define BLE_MESH_PROXY_SRV_DATA_LEN1 0x09
#define BLE_MESH_PROXY_SRV_DATA_LEN2 0x11
_Static_assert(BLE_MESH_MAX_CONN >= CONFIG_BLE_MESH_PBG_SAME_TIME,
"Too large BLE Mesh PB-GATT count");
/* 3 transmissions, 20ms interval */
#define PROV_XMIT BLE_MESH_TRANSMIT(2, 20)
@ -378,14 +376,14 @@ void provisioner_pbg_count_dec(void)
}
}
void provisioner_pbg_count_inc(void)
static inline void provisioner_pbg_count_inc(void)
{
prov_ctx.pbg_count++;
}
#if defined(CONFIG_BLE_MESH_PB_GATT)
void provisioner_clear_link_conn_info(const u8_t addr[6])
{
#if defined(CONFIG_BLE_MESH_PB_GATT)
u8_t i;
if (!addr) {
@ -411,9 +409,9 @@ void provisioner_clear_link_conn_info(const u8_t addr[6])
}
BT_WARN("%s, Address %s is not found", __func__, bt_hex(addr, BLE_MESH_ADDR_LEN));
#endif
return;
}
#endif
const struct bt_mesh_prov *provisioner_get_prov_info(void)
{
@ -522,7 +520,7 @@ static bool is_unprov_dev_being_provision(const u8_t uuid[16])
for (i = 0U; i < BLE_MESH_PROV_SAME_TIME; i++) {
#if defined(CONFIG_BLE_MESH_PB_ADV) && defined(CONFIG_BLE_MESH_PB_GATT)
if (link[i].linking || link[i].connecting ||
bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) {
bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) {
#elif defined(CONFIG_BLE_MESH_PB_ADV) && !defined(CONFIG_BLE_MESH_PB_GATT)
if (link[i].linking || bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) {
#else
@ -542,7 +540,7 @@ static bool is_unprov_dev_uuid_match(const u8_t uuid[16])
{
if (prov_ctx.match_length && prov_ctx.match_value) {
if (memcmp(uuid + prov_ctx.match_offset,
prov_ctx.match_value, prov_ctx.match_length)) {
prov_ctx.match_value, prov_ctx.match_length)) {
return false;
}
}
@ -601,7 +599,7 @@ static int provisioner_check_unprov_dev_info(const u8_t uuid[16])
#if defined(CONFIG_BLE_MESH_PB_ADV)
static int provisioner_start_prov_pb_adv(const u8_t uuid[16],
const bt_mesh_addr_t *addr, u16_t oob_info)
const bt_mesh_addr_t *addr, u16_t oob_info)
{
u8_t zero[6] = {0};
int addr_cmp;
@ -643,7 +641,7 @@ static int provisioner_start_prov_pb_adv(const u8_t uuid[16],
#if defined(CONFIG_BLE_MESH_PB_GATT)
static int provisioner_start_prov_pb_gatt(const u8_t uuid[16],
const bt_mesh_addr_t *addr, u16_t oob_info)
const bt_mesh_addr_t *addr, u16_t oob_info)
{
u8_t zero[6] = {0};
int addr_cmp;
@ -671,7 +669,7 @@ static int provisioner_start_prov_pb_gatt(const u8_t uuid[16],
link[i].addr.type = addr->type;
memcpy(link[i].addr.val, addr->val, BLE_MESH_ADDR_LEN);
}
if (bt_mesh_gattc_conn_create(&link[i].addr, BLE_MESH_UUID_MESH_PROV_VAL)) {
if (bt_mesh_gattc_conn_create(&link[i].addr, BLE_MESH_UUID_MESH_PROV_VAL) < 0) {
memset(link[i].uuid, 0, 16);
link[i].oob_info = 0x0;
memset(&link[i].addr, 0, sizeof(bt_mesh_addr_t));
@ -680,6 +678,7 @@ static int provisioner_start_prov_pb_gatt(const u8_t uuid[16],
}
/* If creating connection successfully, set connecting flag to 1 */
link[i].connecting = true;
provisioner_pbg_count_inc();
osi_mutex_unlock(&prov_ctx.pb_gatt_lock);
return 0;
}
@ -709,7 +708,7 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u
uuid_cmp = memcmp(add_dev->uuid, zero, 16);
if (add_dev->bearer == 0x0 || ((uuid_cmp == 0) &&
((addr_cmp == 0) || add_dev->addr_type > BLE_MESH_ADDR_RANDOM))) {
((addr_cmp == 0) || add_dev->addr_type > BLE_MESH_ADDR_RANDOM))) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
@ -805,7 +804,7 @@ start:
/* Check if current provisioned node count + active link reach max limit */
if (prov_ctx.node_count + prov_ctx.pba_count + \
prov_ctx.pbg_count >= ARRAY_SIZE(prov_nodes)) {
prov_ctx.pbg_count >= ARRAY_SIZE(prov_nodes)) {
BT_WARN("%s, Node count + active link count reach max limit", __func__);
return -EIO;
}
@ -821,7 +820,7 @@ start:
return -EIO;
}
if ((err = provisioner_start_prov_pb_adv(
add_dev->uuid, &add_addr, add_dev->oob_info))) {
add_dev->uuid, &add_addr, add_dev->oob_info))) {
return err;
}
#endif
@ -832,7 +831,7 @@ start:
return -EIO;
}
if ((err = provisioner_start_prov_pb_gatt(
add_dev->uuid, &add_addr, add_dev->oob_info))) {
add_dev->uuid, &add_addr, add_dev->oob_info))) {
return err;
}
#endif
@ -1135,7 +1134,7 @@ static void reset_link(const u8_t idx, u8_t reason)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Remove the link id from exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[idx].link_id);
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[idx].link_id);
#endif
/* Clear everything except the retransmit delayed work config */
@ -1295,7 +1294,7 @@ static void send_link_open(const u8_t idx)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Add the link id into exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[idx].link_id);
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[idx].link_id);
#endif
bearer_ctl_send(idx, LINK_OPEN, link[idx].uuid, 16);
@ -1424,7 +1423,7 @@ static int prov_send_gatt(const u8_t idx, struct net_buf_simple *msg)
return -ENOTCONN;
}
err = provisioner_proxy_send(link[idx].conn, BLE_MESH_PROXY_PROV, msg);
err = bt_mesh_proxy_prov_client_send(link[idx].conn, BLE_MESH_PROXY_PROV, msg);
if (err) {
BT_ERR("%s, Failed to send PB-GATT pdu", __func__);
return err;
@ -1449,9 +1448,9 @@ static inline int prov_send(const u8_t idx, struct net_buf_simple *buf)
#if defined(CONFIG_BLE_MESH_PB_GATT)
if (idx < BLE_MESH_PROV_SAME_TIME
#if defined(CONFIG_BLE_MESH_PB_ADV)
&& idx >= CONFIG_BLE_MESH_PBA_SAME_TIME
&& idx >= CONFIG_BLE_MESH_PBA_SAME_TIME
#endif
) {
) {
return prov_send_gatt(idx, buf);
}
#endif
@ -1961,12 +1960,12 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx)
* to output a value, and wait for prov input complete pdu.
*/
if (prov_auth(idx, link[idx].auth_method,
link[idx].auth_action, link[idx].auth_size) < 0) {
link[idx].auth_action, link[idx].auth_size) < 0) {
BT_ERR("%s, Failed to authenticate", __func__);
goto fail;
}
if (link[idx].auth_method == AUTH_METHOD_OUTPUT ||
link[idx].auth_method == AUTH_METHOD_INPUT) {
link[idx].auth_method == AUTH_METHOD_INPUT) {
return;
}
@ -2091,7 +2090,7 @@ static void prov_input_complete(const u8_t idx, const u8_t *data)
static void prov_confirm(const u8_t idx, const u8_t *data)
{
/**
/**
* Zephyr uses PROV_BUF(16). Currently test with PROV_BUF(16)
* and PROV_BUF(17) on branch feature/btdm_ble_mesh_debug both
* work fine.
@ -2398,9 +2397,9 @@ static void prov_complete(const u8_t idx, const u8_t *data)
prov_ctx.node_count++;
err = provisioner_node_provision(j, prov_nodes[j].uuid, prov_nodes[j].oob_info,
prov_nodes[j].unicast_addr, prov_nodes[j].element_num,
prov_nodes[j].net_idx, prov_nodes[j].flags,
prov_nodes[j].iv_index, device_key);
prov_nodes[j].unicast_addr, prov_nodes[j].element_num,
prov_nodes[j].net_idx, prov_nodes[j].flags,
prov_nodes[j].iv_index, device_key);
if (err) {
BT_ERR("%s, Failed to store node info", __func__);
close_link(idx, CLOSE_REASON_FAILED);
@ -2461,9 +2460,9 @@ static void close_link(const u8_t idx, u8_t reason)
#if defined(CONFIG_BLE_MESH_PB_GATT)
if (idx < BLE_MESH_PROV_SAME_TIME
#if defined(CONFIG_BLE_MESH_PB_ADV)
&& idx >= CONFIG_BLE_MESH_PBA_SAME_TIME
&& idx >= CONFIG_BLE_MESH_PBA_SAME_TIME
#endif
) {
) {
if (link[idx].conn) {
bt_mesh_gattc_disconnect(link[idx].conn);
}
@ -2660,7 +2659,7 @@ static void gen_prov_cont(const u8_t idx, struct prov_rx *rx, struct net_buf_sim
if (rx->xact_id != link[idx].rx.trans_id) {
BT_WARN("%s, Data for unknown transaction (%u != %u)",
__func__, rx->xact_id, link[idx].rx.trans_id);
__func__, rx->xact_id, link[idx].rx.trans_id);
/**
* If Provisioner receives a Provisioning PDU with a mismatch
* transaction number, it just ignore it.
@ -2678,7 +2677,7 @@ static void gen_prov_cont(const u8_t idx, struct prov_rx *rx, struct net_buf_sim
(23 * (link[idx].rx.last_seg - 1)));
if (expect_len != buf->len) {
BT_ERR("%s, Incorrect last seg len: %u != %u",
__func__, expect_len, buf->len);
__func__, expect_len, buf->len);
goto fail;
}
}
@ -2763,7 +2762,7 @@ static void gen_prov_start(const u8_t idx, struct prov_rx *rx, struct net_buf_si
if (link[idx].rx.buf->len > link[idx].rx.buf->size) {
BT_ERR("%s, Too large provisioning PDU (%u bytes)",
__func__, link[idx].rx.buf->len);
__func__, link[idx].rx.buf->len);
// close_link(i, CLOSE_REASON_FAILED);
return;
}
@ -2951,7 +2950,7 @@ int provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr)
BT_DBG("conn %p", conn);
/**
/**
* Double check if the device is currently being provisioned using PB-ADV.
* Provisioner binds conn with proper device when proxy_prov_connected()
* is invoked, and here after proper GATT procedures are completed, we just
@ -3088,7 +3087,7 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info)
}
static bool is_unprov_dev_info_callback_to_app(bt_mesh_prov_bearer_t bearer,
const u8_t uuid[16], const bt_mesh_addr_t *addr, u16_t oob_info)
const u8_t uuid[16], const bt_mesh_addr_t *addr, u16_t oob_info)
{
u16_t index;
@ -3106,7 +3105,7 @@ static bool is_unprov_dev_info_callback_to_app(bt_mesh_prov_bearer_t bearer,
if (!(unprov_dev[index].bearer & bearer)) {
BT_WARN("Device in queue not support PB-%s",
(bearer == BLE_MESH_PROV_ADV) ? "ADV" : "GATT");
(bearer == BLE_MESH_PROV_ADV) ? "ADV" : "GATT");
if (notify_unprov_adv_pkt_cb) {
notify_unprov_adv_pkt_cb(addr->val, addr->type, adv_type, uuid, oob_info, bearer);
}
@ -3145,7 +3144,7 @@ void provisioner_unprov_beacon_recv(struct net_buf_simple *buf)
}
if (is_unprov_dev_info_callback_to_app(
BLE_MESH_PROV_ADV, uuid, addr, oob_info)) {
BLE_MESH_PROV_ADV, uuid, addr, oob_info)) {
return;
}
@ -3153,85 +3152,7 @@ void provisioner_unprov_beacon_recv(struct net_buf_simple *buf)
#endif /* CONFIG_BLE_MESH_PB_ADV */
}
bool provisioner_flags_match(struct net_buf_simple *buf)
{
u8_t flags;
if (buf->len != 1) {
BT_DBG("%s, Unexpected flags length", __func__);
return false;
}
flags = net_buf_simple_pull_u8(buf);
BT_DBG("Received adv pkt with flags: 0x%02x", flags);
/* Flags context will not be checked curently */
return true;
}
u16_t provisioner_srv_uuid_recv(struct net_buf_simple *buf)
{
u16_t uuid;
if (buf->len != 2) {
BT_DBG("Length not match mesh service uuid");
return false;
}
uuid = net_buf_simple_pull_le16(buf);
BT_DBG("Received adv pkt with service UUID: %d", uuid);
if ((uuid != BLE_MESH_UUID_MESH_PROV_VAL) && (uuid != BLE_MESH_UUID_MESH_PROXY_VAL)) {
return false;
}
return uuid;
}
static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr);
void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid)
{
u16_t uuid_type;
if (!buf || !addr) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
uuid_type = net_buf_simple_pull_le16(buf);
if (uuid_type != uuid) {
BT_DBG("%s, Invalid Mesh Service Data UUID 0x%04x", __func__, uuid_type);
return;
}
switch (uuid) {
case BLE_MESH_UUID_MESH_PROV_VAL:
if (buf->len != BLE_MESH_PROV_SRV_DATA_LEN) {
BT_WARN("%s, Invalid Mesh Prov Service Data length %d", __func__, buf->len);
return;
}
BT_DBG("Start to deal with Mesh Prov Service Data");
provisioner_prov_srv_data_recv(buf, addr);
break;
case BLE_MESH_UUID_MESH_PROXY_VAL:
if (buf->len != BLE_MESH_PROXY_SRV_DATA_LEN1 &&
buf->len != BLE_MESH_PROXY_SRV_DATA_LEN2) {
BT_ERR("%s, Invalid Mesh Proxy Service Data length %d", __func__, buf->len);
return;
}
BT_DBG("Start to deal with Mesh Proxy Service Data");
provisioner_proxy_srv_data_recv(buf);
break;
default:
break;
}
}
static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr)
void provisioner_prov_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr)
{
#if defined(CONFIG_BLE_MESH_PB_GATT)
const u8_t *uuid = NULL;
@ -3242,6 +3163,11 @@ static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_
return;
}
if (bt_mesh_gattc_get_free_conn_count() == 0) {
BT_WARN("%s, max connections", __func__);
return;
}
uuid = buf->data;
net_buf_simple_pull(buf, 16);
/* Mesh beacon uses big-endian to send beacon data */
@ -3252,7 +3178,7 @@ static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_
}
if (is_unprov_dev_info_callback_to_app(
BLE_MESH_PROV_GATT, uuid, addr, oob_info)) {
BLE_MESH_PROV_GATT, uuid, addr, oob_info)) {
return;
}

View file

@ -75,13 +75,6 @@ struct bt_mesh_prov_data_info {
*/
void provisioner_pbg_count_dec(void);
/**
* @brief This function increments the current PB-GATT count.
*
* @return None
*/
void provisioner_pbg_count_inc(void);
/**
* @brief This function clears the part of the link info of the proper device.
*
@ -165,37 +158,7 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info);
*/
void provisioner_unprov_beacon_recv(struct net_buf_simple *buf);
/**
* @brief This function parses the flags part of the
* received connectable mesh provisioning advertising packets.
*
* @param[in] buf: Pointer to the buffer containing advertising flags part
*
* @return True - success, False - fail
*/
bool provisioner_flags_match(struct net_buf_simple *buf);
/**
* @brief This function parses the service UUID part of the
* received connectable mesh provisioning advertising packets.
*
* @param[in] buf: Pointer to the buffer containing service UUID part
*
* @return Zero - fail, otherwise - Service UUID(0x1827 or 0x1828)
*/
u16_t provisioner_srv_uuid_recv(struct net_buf_simple *buf);
/**
* @brief This function parses the service data part of the
* received connectable mesh provisioning advertising packets.
*
* @param[in] buf: Pointer to the buffer containing the remianing service data part
* @param[in] addr: Pointer to the received device address
* @param[in] uuid: Service UUID contained in the service UUID part
*
* @return None
*/
void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid);
void provisioner_prov_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr);
/**
* @brief This function gets the bt_mesh_prov pointer.

View file

@ -1,608 +0,0 @@
// Copyright 2017-2019 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.
#include <string.h>
#include <errno.h>
#include "sdkconfig.h"
#include "mesh_bearer_adapt.h"
#include "mesh_trace.h"
#include "net.h"
#include "beacon.h"
#include "foundation.h"
#include "provisioner_prov.h"
#include "provisioner_proxy.h"
#include "provisioner_beacon.h"
#if CONFIG_BLE_MESH_PROVISIONER
#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define PDU_SAR(data) (data[0] >> 6)
#define SAR_COMPLETE 0x00
#define SAR_FIRST 0x01
#define SAR_CONT 0x02
#define SAR_LAST 0x03
#define CFG_FILTER_SET 0x00
#define CFG_FILTER_ADD 0x01
#define CFG_FILTER_REMOVE 0x02
#define CFG_FILTER_STATUS 0x03
#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
#define SERVER_BUF_SIZE 68
#define ID_TYPE_NET 0x00
#define ID_TYPE_NODE 0x01
#define NODE_ID_LEN 19
#define NET_ID_LEN 11
#define CLOSE_REASON_PROXY 0xFF
static int conn_count;
static struct bt_mesh_proxy_server {
struct bt_mesh_conn *conn;
/* Provisioner can use filter to double check the dst within mesh messages */
u16_t filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE];
enum __packed {
NONE,
WHITELIST,
BLACKLIST,
PROV,
} filter_type;
u8_t msg_type;
struct net_buf_simple buf;
} servers[BLE_MESH_MAX_CONN];
static u8_t server_buf_data[SERVER_BUF_SIZE * BLE_MESH_MAX_CONN];
static struct bt_mesh_proxy_server *find_server(struct bt_mesh_conn *conn)
{
int i;
for (i = 0; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn == conn) {
return &servers[i];
}
}
return NULL;
}
static int filter_status(struct bt_mesh_proxy_server *server,
struct net_buf_simple *buf)
{
/* TODO: Deal with received proxy configuration status messages */
return 0;
}
#if 0
static void send_filter_set(struct bt_mesh_proxy_server *server,
struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf)
{
/* TODO: Act as proxy client, send proxy configuration set messages */
}
static void send_filter_add(struct bt_mesh_proxy_server *server,
struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf)
{
/* TODO: Act as proxy client, send proxy configuration add messages */
}
static void send_filter_remove(struct bt_mesh_proxy_server *server,
struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf)
{
/* TODO: Act as proxy client, send proxy configuration remove messages */
}
#endif
static void proxy_cfg(struct bt_mesh_proxy_server *server)
{
NET_BUF_SIMPLE_DEFINE(buf, 29);
struct bt_mesh_net_rx rx;
u8_t opcode;
int err;
/** In order to deal with proxy configuration messages, provisioner should
* do sth. like create mesh network after each device is provisioned.
*/
err = bt_mesh_net_decode(&server->buf, BLE_MESH_NET_IF_PROXY_CFG,
&rx, &buf);
if (err) {
BT_ERR("%s, Failed to decode Proxy Configuration (err %d)", __func__, err);
return;
}
/* Remove network headers */
net_buf_simple_pull(&buf, BLE_MESH_NET_HDR_LEN);
BT_DBG("%u bytes: %s", buf.len, bt_hex(buf.data, buf.len));
if (buf.len < 1) {
BT_WARN("Too short proxy configuration PDU");
return;
}
opcode = net_buf_simple_pull_u8(&buf);
switch (opcode) {
case CFG_FILTER_STATUS:
filter_status(server, &buf);
break;
default:
BT_WARN("Unhandled configuration OpCode 0x%02x", opcode);
break;
}
}
static void proxy_complete_pdu(struct bt_mesh_proxy_server *server)
{
switch (server->msg_type) {
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
case BLE_MESH_PROXY_NET_PDU:
BT_DBG("Mesh Network PDU");
bt_mesh_net_recv(&server->buf, 0, BLE_MESH_NET_IF_PROXY);
break;
case BLE_MESH_PROXY_BEACON:
BT_DBG("Mesh Beacon PDU");
provisioner_beacon_recv(&server->buf);
break;
case BLE_MESH_PROXY_CONFIG:
BT_DBG("Mesh Configuration PDU");
proxy_cfg(server);
break;
#endif
#if defined(CONFIG_BLE_MESH_PB_GATT)
case BLE_MESH_PROXY_PROV:
BT_DBG("Mesh Provisioning PDU");
provisioner_pb_gatt_recv(server->conn, &server->buf);
break;
#endif
default:
BT_WARN("Unhandled Message Type 0x%02x", server->msg_type);
break;
}
net_buf_simple_reset(&server->buf);
}
#define ATTR_IS_PROV(uuid) (uuid == BLE_MESH_UUID_MESH_PROV_VAL)
static ssize_t proxy_recv(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr, const void *buf,
u16_t len, u16_t offset, u8_t flags)
{
struct bt_mesh_proxy_server *server = find_server(conn);
const u8_t *data = buf;
u16_t srvc_uuid = 0;
if (!server) {
return -ENOTCONN;
}
if (len < 1) {
BT_WARN("Too small Proxy PDU");
return -EINVAL;
}
srvc_uuid = bt_mesh_gattc_get_service_uuid(conn);
if (!srvc_uuid) {
BT_ERR("%s, No service uuid found", __func__);
return -ENOTCONN;
}
if (ATTR_IS_PROV(srvc_uuid) != (PDU_TYPE(data) == BLE_MESH_PROXY_PROV)) {
BT_WARN("Proxy PDU type doesn't match GATT service uuid");
return -EINVAL;
}
if (len - 1 > net_buf_simple_tailroom(&server->buf)) {
BT_WARN("Too big proxy PDU");
return -EINVAL;
}
switch (PDU_SAR(data)) {
case SAR_COMPLETE:
if (server->buf.len) {
BT_WARN("Complete PDU while a pending incomplete one");
return -EINVAL;
}
server->msg_type = PDU_TYPE(data);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
proxy_complete_pdu(server);
break;
case SAR_FIRST:
if (server->buf.len) {
BT_WARN("First PDU while a pending incomplete one");
return -EINVAL;
}
server->msg_type = PDU_TYPE(data);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
break;
case SAR_CONT:
if (!server->buf.len) {
BT_WARN("Continuation with no prior data");
return -EINVAL;
}
if (server->msg_type != PDU_TYPE(data)) {
BT_WARN("Unexpected message type in continuation");
return -EINVAL;
}
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
break;
case SAR_LAST:
if (!server->buf.len) {
BT_WARN("Last SAR PDU with no prior data");
return -EINVAL;
}
if (server->msg_type != PDU_TYPE(data)) {
BT_WARN("Unexpected message type in last SAR PDU");
return -EINVAL;
}
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
proxy_complete_pdu(server);
break;
}
return len;
}
static void proxy_prov_connected(const u8_t addr[6], struct bt_mesh_conn *conn, int id)
{
struct bt_mesh_proxy_server *server = NULL;
conn_count++;
if (!servers[id].conn) {
server = &servers[id];
}
if (!server) {
BT_ERR("%s, No matching Proxy Client objects", __func__);
/** Disconnect current connection, clear part of prov_link
* information, like uuid, dev_addr, linking flag, etc.
*/
return;
}
server->conn = bt_mesh_conn_ref(conn);
server->filter_type = NONE;
memset(server->filter, 0, sizeof(server->filter));
net_buf_simple_reset(&server->buf);
#if defined(CONFIG_BLE_MESH_PB_GATT)
if (provisioner_set_prov_conn(addr, server->conn)) {
BT_ERR("%s, provisioner_set_prov_conn failed", __func__);
bt_mesh_gattc_disconnect(server->conn);
return;
}
#endif
bt_mesh_gattc_exchange_mtu(id);
}
static void proxy_prov_disconnected(struct bt_mesh_conn *conn, u8_t reason)
{
struct bt_mesh_proxy_server *server = NULL;
int i;
BT_DBG("conn %p, handle is %d, reason 0x%02x", conn, conn->handle, reason);
if (conn_count) {
conn_count--;
}
for (i = 0; i < ARRAY_SIZE(servers); i++) {
server = &servers[i];
if (server->conn == conn) {
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
server->filter_type == PROV) {
provisioner_pb_gatt_close(conn, reason);
}
server->conn = NULL;
break;
}
}
}
#if defined(CONFIG_BLE_MESH_PB_GATT)
static ssize_t prov_write_ccc_descr(struct bt_mesh_conn *conn, u8_t *addr)
{
struct bt_mesh_proxy_server *server;
server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server found", __func__);
return -ENOTCONN;
}
if (server->filter_type == NONE) {
server->filter_type = PROV;
return provisioner_pb_gatt_open(conn, addr);
}
return -EINVAL;
}
static ssize_t prov_notification(struct bt_mesh_conn *conn, u8_t *data, u16_t len)
{
struct bt_mesh_proxy_server *server;
server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server found", __func__);
return -ENOTCONN;
}
if (server->filter_type == PROV) {
return proxy_recv(conn, NULL, data, len, 0, 0);
}
return -EINVAL;
}
int provisioner_pb_gatt_enable(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn) {
servers[i].filter_type = PROV;
}
}
return 0;
}
int provisioner_pb_gatt_disable(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (server->conn && server->filter_type == PROV) {
bt_mesh_gattc_disconnect(server->conn);
server->filter_type = NONE;
}
}
return 0;
}
#endif /* CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
static ssize_t proxy_write_ccc_descr(struct bt_mesh_conn *conn)
{
struct bt_mesh_proxy_server *server;
server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server found", __func__);
return -ENOTCONN;
}
if (server->filter_type == NONE) {
server->filter_type = WHITELIST;
return 0;
}
return -EINVAL;
}
static ssize_t proxy_notification(struct bt_mesh_conn *conn, u8_t *data, u16_t len)
{
return proxy_recv(conn, NULL, data, len, 0, 0);
}
/** Currently provisioner does't need bt_mesh_provisioner_proxy_enable()
* and bt_mesh_provisioner_proxy_disable() functions, and once they are
* used, provisioner can be enabled to parse node_id_adv and net_id_adv
* in order to support proxy client role.
* And if gatt_proxy is disabled, provisioner can stop dealing with
* these two kinds of connectable advertising packets.
*/
int bt_mesh_provisioner_proxy_enable(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn) {
servers[i].filter_type = WHITELIST;
}
}
/** TODO: Once at leat one device has been provisioned, provisioner
* can be set to allow receiving and parsing node_id & net_id adv
* packets, and we may use a global flag to indicate this.
*/
return 0;
}
static void bt_mesh_proxy_gatt_proxy_disconnect(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (server->conn && (server->filter_type == WHITELIST ||
server->filter_type == BLACKLIST)) {
server->filter_type = NONE;
bt_mesh_gattc_disconnect(server->conn);
}
}
}
int bt_mesh_provisioner_proxy_disable(void)
{
BT_DBG("%s", __func__);
/** TODO: Once this function is invoked, provisioner shall stop
* receiving and parsing node_id & net_id adv packets, and if
* proxy connection exists, we should disconnect it.
*/
bt_mesh_proxy_gatt_proxy_disconnect();
return 0;
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY */
static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t len)
{
BT_DBG("%u bytes: %s", len, bt_hex(data, len));
#if defined(CONFIG_BLE_MESH_GATT_PROXY) || defined(CONFIG_BLE_MESH_PB_GATT)
return bt_mesh_gattc_write_no_rsp(conn, NULL, data, len);
#endif
return 0;
}
static int proxy_prov_segment_and_send(struct bt_mesh_conn *conn, u8_t type,
struct net_buf_simple *msg)
{
u16_t mtu;
if (conn == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
BT_DBG("conn %p type 0x%02x len %u: %s", conn, type, msg->len,
bt_hex(msg->data, msg->len));
mtu = bt_mesh_gattc_get_mtu_info(conn);
if (!mtu) {
BT_ERR("%s, Conn used to get mtu does not exist", __func__);
return -ENOTCONN;
}
/* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */
mtu -= 3;
if (mtu > msg->len) {
net_buf_simple_push_u8(msg, PDU_HDR(SAR_COMPLETE, type));
return proxy_send(conn, msg->data, msg->len);
}
net_buf_simple_push_u8(msg, PDU_HDR(SAR_FIRST, type));
proxy_send(conn, msg->data, mtu);
net_buf_simple_pull(msg, mtu);
while (msg->len) {
if (msg->len + 1 < mtu) {
net_buf_simple_push_u8(msg, PDU_HDR(SAR_LAST, type));
proxy_send(conn, msg->data, msg->len);
break;
}
net_buf_simple_push_u8(msg, PDU_HDR(SAR_CONT, type));
proxy_send(conn, msg->data, mtu);
net_buf_simple_pull(msg, mtu);
}
return 0;
}
int provisioner_proxy_send(struct bt_mesh_conn *conn, u8_t type,
struct net_buf_simple *msg)
{
struct bt_mesh_proxy_server *server = find_server(conn);
if (!server) {
BT_ERR("$%s, No Proxy Server found", __func__);
return -ENOTCONN;
}
if ((server->filter_type == PROV) != (type == BLE_MESH_PROXY_PROV)) {
BT_ERR("%s, Invalid PDU type for Proxy Client", __func__);
return -EINVAL;
}
return proxy_prov_segment_and_send(conn, type, msg);
}
static struct bt_mesh_prov_conn_cb conn_callbacks = {
.connected = proxy_prov_connected,
.disconnected = proxy_prov_disconnected,
#if defined(CONFIG_BLE_MESH_PB_GATT)
.prov_write_descr = prov_write_ccc_descr,
.prov_notify = prov_notification,
#endif /* CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
.proxy_write_descr = proxy_write_ccc_descr,
.proxy_notify = proxy_notification,
#endif /* CONFIG_BLE_MESH_GATT_PROXY */
};
void provisioner_proxy_srv_data_recv(struct net_buf_simple *buf)
{
/** TODO: Parse node_id_adv or net_id_adv pkts. Currently we
* don't support this function, and if realized later, proxy
* client need to check if there is server structure left
* before create connection with a server.
* check conn_count & CONFIG_BLE_MESH_PBG_SAME_TIME
*/
}
int provisioner_proxy_init(void)
{
int i;
/* Initialize the server receive buffers */
for (i = 0; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
server->buf.size = SERVER_BUF_SIZE;
server->buf.__buf = server_buf_data + (i * SERVER_BUF_SIZE);
}
bt_mesh_gattc_conn_cb_register(&conn_callbacks);
return 0;
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */

View file

@ -1,89 +0,0 @@
// Copyright 2017-2019 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 _PROVISIONER_PROXY_H_
#define _PROVISIONER_PROXY_H_
#include "mesh_buf.h"
#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
/**
* @brief This function is called to send proxy protocol messages.
*
* @param[in] conn: Pointer to bt_conn structure
* @param[in] type: Proxy protocol message type
* @param[in] msg: Pointer to the buffer contains sending message.
*
* @return Zero-success, other-fail
*/
int provisioner_proxy_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg);
/**
* @brief This function is called to parse received node identity and net
* id adv pkts and create connection if deceided to.
*
* @param[in] buf: Pointer to the buffer contains received message.
*
* @return None
*/
void provisioner_proxy_srv_data_recv(struct net_buf_simple *buf);
/**
* @brief This function is called to initialize proxy provisioner structure
* and register proxy connection related callbacks.
*
* @return Zero-success, other-fail
*/
int provisioner_proxy_init(void);
/**
* @brief This function is called to enable dealing with proxy provisioning
* messages.
*
* @return Zero-success, other-fail
*/
int provisioner_pb_gatt_enable(void);
/**
* @brief This function is called to disable dealing with proxy provisioning
* messages and if proxy provisioning connections exist, the connections
* will be disconnected.
*
* @return Zero-success, other-fail
*/
int provisioner_pb_gatt_disable(void);
/* The following APIs are for application use */
/**
* @brief This function is called to enable receiving node identity and net
* id adv pkts.
*
* @return Zero-success, other-fail
*/
int bt_mesh_provisioner_proxy_enable(void);
/**
* @brief This function is called to disable receiving node identity and net
* id adv pkts, and if proxy connections exist, these connections will
* be disconnected.
*
* @return Zero-success, other-fail
*/
int bt_mesh_provisioner_proxy_disable(void);
#endif /* _PROVISIONER_PROXY_H_ */

View file

@ -0,0 +1,998 @@
// Copyright 2017-2019 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.
#include <string.h>
#include <errno.h>
#include "sdkconfig.h"
#include "mesh.h"
#include "mesh_bearer_adapt.h"
#include "mesh_trace.h"
#include "mesh_common.h"
#include "net.h"
#include "access.h"
#include "beacon.h"
#include "foundation.h"
#include "provisioner_prov.h"
#include "proxy_client.h"
#include "provisioner_beacon.h"
#include "provisioner_main.h"
#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define PDU_SAR(data) (data[0] >> 6)
#define PROXY_SAR_TIMEOUT K_SECONDS(20)
#define SAR_COMPLETE 0x00
#define SAR_FIRST 0x01
#define SAR_CONT 0x02
#define SAR_LAST 0x03
#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
#define SERVER_BUF_SIZE 68
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static struct bt_mesh_proxy_server {
struct bt_mesh_conn *conn;
enum __packed {
NONE,
PROV,
PROXY,
} conn_type;
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
u16_t net_idx;
#endif
u8_t msg_type;
struct k_delayed_work sar_timer;
struct net_buf_simple buf;
} servers[BLE_MESH_MAX_CONN];
static u8_t server_buf_data[SERVER_BUF_SIZE * BLE_MESH_MAX_CONN];
static struct bt_mesh_proxy_server *find_server(struct bt_mesh_conn *conn)
{
u8_t i;
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn == conn) {
return &servers[i];
}
}
return NULL;
}
static void proxy_sar_timeout(struct k_work *work)
{
struct bt_mesh_proxy_server *server = NULL;
BT_DBG("%s", __func__);
server = CONTAINER_OF(work, struct bt_mesh_proxy_server, sar_timer.work);
if (!server || !server->conn) {
BT_ERR("%s, Invalid proxy server parameter", __func__);
return;
}
net_buf_simple_reset(&server->buf);
bt_mesh_gattc_disconnect(server->conn);
}
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
/**
* The following callbacks are used to notify proper information
* to the application layer.
*/
static proxy_client_recv_adv_cb_t proxy_client_adv_recv_cb;
static proxy_client_connect_cb_t proxy_client_connect_cb;
static proxy_client_disconnect_cb_t proxy_client_disconnect_cb;
static proxy_client_recv_filter_status_cb_t proxy_client_filter_status_recv_cb;
void bt_mesh_proxy_client_set_adv_recv_cb(proxy_client_recv_adv_cb_t cb)
{
proxy_client_adv_recv_cb = cb;
}
void bt_mesh_proxy_client_set_conn_cb(proxy_client_connect_cb_t cb)
{
proxy_client_connect_cb = cb;
}
void bt_mesh_proxy_client_set_disconn_cb(proxy_client_disconnect_cb_t cb)
{
proxy_client_disconnect_cb = cb;
}
void bt_mesh_proxy_client_set_filter_status_cb(proxy_client_recv_filter_status_cb_t cb)
{
proxy_client_filter_status_recv_cb = cb;
}
static void filter_status(struct bt_mesh_proxy_server *server,
struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf)
{
u8_t filter_type;
u16_t list_size;
if (buf->len != 3) {
BT_ERR("%s, Invalid Proxy Filter Status length %d", __func__, buf->len);
return;
}
filter_type = net_buf_simple_pull_u8(buf);
if (filter_type > 0x01) {
BT_ERR("%s, Invalid filter type 0x%02x", __func__, filter_type);
return;
}
list_size = net_buf_simple_pull_be16(buf);
BT_DBG("%s, filter_type 0x%02x list_size %d", __func__, filter_type, list_size);
if (proxy_client_filter_status_recv_cb) {
proxy_client_filter_status_recv_cb(server - servers, rx->ctx.addr, server->net_idx, filter_type, list_size);
}
return;
}
static void proxy_cfg(struct bt_mesh_proxy_server *server)
{
NET_BUF_SIMPLE_DEFINE(buf, 29);
struct bt_mesh_net_rx rx = {0};
u8_t opcode;
int err;
err = bt_mesh_net_decode(&server->buf, BLE_MESH_NET_IF_PROXY_CFG,
&rx, &buf);
if (err) {
BT_ERR("%s, Failed to decode Proxy Configuration (err %d)", __func__, err);
return;
}
if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.addr)) {
BT_ERR("%s, Proxy Configuration from non-unicast addr 0x%04x", __func__, rx.ctx.addr);
return;
}
/* Remove network headers */
net_buf_simple_pull(&buf, BLE_MESH_NET_HDR_LEN);
BT_DBG("%u bytes: %s", buf.len, bt_hex(buf.data, buf.len));
if (buf.len < 3) {
BT_WARN("Too short proxy configuration PDU");
return;
}
opcode = net_buf_simple_pull_u8(&buf);
switch (opcode) {
case BLE_MESH_PROXY_CFG_FILTER_STATUS:
filter_status(server, &rx, &buf);
break;
default:
BT_WARN("Unknown Proxy Configuration OpCode 0x%02x", opcode);
break;
}
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
static void proxy_complete_pdu(struct bt_mesh_proxy_server *server)
{
switch (server->msg_type) {
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_PROXY_NET_PDU:
BT_DBG("Mesh Network PDU");
bt_mesh_net_recv(&server->buf, 0, BLE_MESH_NET_IF_PROXY);
break;
case BLE_MESH_PROXY_BEACON:
BT_DBG("Mesh Beacon PDU");
if (bt_mesh_is_provisioner_en()) {
#if CONFIG_BLE_MESH_PROVISIONER
provisioner_beacon_recv(&server->buf);
#endif
} else {
#if CONFIG_BLE_MESH_NODE
bt_mesh_beacon_recv(&server->buf);
#endif
}
break;
case BLE_MESH_PROXY_CONFIG:
BT_DBG("Mesh Configuration PDU");
proxy_cfg(server);
break;
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
case BLE_MESH_PROXY_PROV:
BT_DBG("Mesh Provisioning PDU");
provisioner_pb_gatt_recv(server->conn, &server->buf);
break;
#endif
default:
BT_WARN("Unhandled Message Type 0x%02x", server->msg_type);
break;
}
net_buf_simple_reset(&server->buf);
}
#define ATTR_IS_PROV(uuid) (uuid == BLE_MESH_UUID_MESH_PROV_VAL)
static ssize_t proxy_recv(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr, const void *buf,
u16_t len, u16_t offset, u8_t flags)
{
struct bt_mesh_proxy_server *server = find_server(conn);
const u8_t *data = buf;
u16_t srvc_uuid;
if (!server) {
BT_ERR("%s, No Proxy Server object found", __func__);
return -ENOTCONN;
}
if (len < 1) {
BT_WARN("Too small Proxy PDU");
return -EINVAL;
}
srvc_uuid = bt_mesh_gattc_get_service_uuid(conn);
if (!srvc_uuid) {
BT_ERR("%s, No service uuid found", __func__);
return -ENOTCONN;
}
if (ATTR_IS_PROV(srvc_uuid) != (PDU_TYPE(data) == BLE_MESH_PROXY_PROV)) {
BT_WARN("Proxy PDU type doesn't match GATT service uuid");
return -EINVAL;
}
if (len - 1 > net_buf_simple_tailroom(&server->buf)) {
BT_WARN("Too big proxy PDU");
return -EINVAL;
}
switch (PDU_SAR(data)) {
case SAR_COMPLETE:
if (server->buf.len) {
BT_WARN("Complete PDU while a pending incomplete one");
return -EINVAL;
}
server->msg_type = PDU_TYPE(data);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
proxy_complete_pdu(server);
break;
case SAR_FIRST:
if (server->buf.len) {
BT_WARN("First PDU while a pending incomplete one");
return -EINVAL;
}
k_delayed_work_submit(&server->sar_timer, PROXY_SAR_TIMEOUT);
server->msg_type = PDU_TYPE(data);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
break;
case SAR_CONT:
if (!server->buf.len) {
BT_WARN("Continuation with no prior data");
return -EINVAL;
}
if (server->msg_type != PDU_TYPE(data)) {
BT_WARN("Unexpected message type in continuation");
return -EINVAL;
}
k_delayed_work_submit(&server->sar_timer, PROXY_SAR_TIMEOUT);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
break;
case SAR_LAST:
if (!server->buf.len) {
BT_WARN("Last SAR PDU with no prior data");
return -EINVAL;
}
if (server->msg_type != PDU_TYPE(data)) {
BT_WARN("Unexpected message type in last SAR PDU");
return -EINVAL;
}
k_delayed_work_cancel(&server->sar_timer);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
proxy_complete_pdu(server);
break;
}
return len;
}
static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t len)
{
BT_DBG("%u bytes: %s", len, bt_hex(data, len));
return bt_mesh_gattc_write_no_rsp(conn, NULL, data, len);
}
static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type,
struct net_buf_simple *msg)
{
u16_t mtu;
int err;
if (conn == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
BT_DBG("conn %p type 0x%02x len %u: %s", conn, type, msg->len,
bt_hex(msg->data, msg->len));
mtu = bt_mesh_gattc_get_mtu_info(conn);
if (!mtu) {
BT_ERR("%s, Conn used to get mtu does not exist", __func__);
return -ENOTCONN;
}
/* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */
mtu -= 3;
if (mtu > msg->len) {
net_buf_simple_push_u8(msg, PDU_HDR(SAR_COMPLETE, type));
return proxy_send(conn, msg->data, msg->len);
}
net_buf_simple_push_u8(msg, PDU_HDR(SAR_FIRST, type));
err = proxy_send(conn, msg->data, mtu);
net_buf_simple_pull(msg, mtu);
while (msg->len) {
if (msg->len + 1 < mtu) {
net_buf_simple_push_u8(msg, PDU_HDR(SAR_LAST, type));
err = proxy_send(conn, msg->data, msg->len);
break;
}
net_buf_simple_push_u8(msg, PDU_HDR(SAR_CONT, type));
err = proxy_send(conn, msg->data, mtu);
net_buf_simple_pull(msg, mtu);
}
return err;
}
int bt_mesh_proxy_prov_client_send(struct bt_mesh_conn *conn, u8_t type,
struct net_buf_simple *msg)
{
struct bt_mesh_proxy_server *server = find_server(conn);
if (!server) {
BT_ERR("$%s, No Proxy Server object found", __func__);
return -ENOTCONN;
}
if ((server->conn_type == PROV) != (type == BLE_MESH_PROXY_PROV)) {
BT_ERR("%s, Invalid PDU type for Proxy Server", __func__);
return -EINVAL;
}
return proxy_segment_and_send(conn, type, msg);
}
static void proxy_connected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int id)
{
struct bt_mesh_proxy_server *server = NULL;
if (!servers[id].conn) {
server = &servers[id];
}
if (!server) {
BT_ERR("%s, No free Proxy Server objects", __func__);
/** Disconnect current connection, clear part of prov_link
* information, like uuid, dev_addr, linking flag, etc.
*/
bt_mesh_gattc_disconnect(conn);
return;
}
server->conn = bt_mesh_conn_ref(conn);
server->conn_type = NONE;
net_buf_simple_reset(&server->buf);
bt_mesh_gattc_exchange_mtu(id);
return;
}
static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, u8_t reason)
{
struct bt_mesh_proxy_server *server = find_server(conn);
BT_DBG("conn %p, handle is %d, reason 0x%02x", conn, conn->handle, reason);
if (!server) {
BT_ERR("%s, No Proxy Server object found", __func__);
return;
}
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (server->conn_type == PROV) {
provisioner_pb_gatt_close(conn, reason);
}
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
if (server->conn_type == PROXY) {
if (proxy_client_disconnect_cb) {
proxy_client_disconnect_cb(addr, server - servers, server->net_idx, reason);
}
}
#endif
k_delayed_work_cancel(&server->sar_timer);
server->conn = NULL;
server->conn_type = NONE;
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
server->net_idx = BLE_MESH_KEY_UNUSED;
#endif
return;
}
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
{
struct bt_mesh_proxy_server *server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server object found", __func__);
return -ENOTCONN;
}
if (server->conn_type == NONE) {
server->conn_type = PROV;
if (provisioner_set_prov_conn(addr->val, server->conn)) {
BT_ERR("%s, provisioner_set_prov_conn failed", __func__);
bt_mesh_gattc_disconnect(server->conn);
return -EIO;
}
return provisioner_pb_gatt_open(conn, addr->val);
}
return -ENOMEM;
}
static ssize_t prov_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len)
{
struct bt_mesh_proxy_server *server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server object found", __func__);
return -ENOTCONN;
}
if (server->conn_type == PROV) {
return proxy_recv(conn, NULL, data, len, 0, 0);
}
return -EINVAL;
}
int provisioner_pb_gatt_enable(void)
{
u8_t i;
BT_DBG("%s", __func__);
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn) {
servers[i].conn_type = PROV;
}
}
return 0;
}
int provisioner_pb_gatt_disable(void)
{
u8_t i;
BT_DBG("%s", __func__);
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (server->conn && server->conn_type == PROV) {
bt_mesh_gattc_disconnect(server->conn);
server->conn_type = NONE;
}
}
return 0;
}
#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
static ssize_t proxy_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
{
struct bt_mesh_proxy_server *server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server object found", __func__);
return -ENOTCONN;
}
if (server->conn_type == NONE) {
server->conn_type = PROXY;
if (proxy_client_connect_cb) {
proxy_client_connect_cb(addr, server - servers, server->net_idx);
}
return 0;
}
return -EINVAL;
}
static ssize_t proxy_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len)
{
struct bt_mesh_proxy_server *server = find_server(conn);
if (!server) {
BT_ERR("%s, No Proxy Server object found", __func__);
return -ENOTCONN;
}
if (server->conn_type == PROXY) {
return proxy_recv(conn, NULL, data, len, 0, 0);
}
return -EINVAL;
}
/**
* Currently proxy client does't need bt_mesh_proxy_client_enable() and
* bt_mesh_proxy_client_disable() functions, and once they are used,
* proxy client can be enabled to parse node_id_adv and net_id_adv in
* order to support proxy client role.
* And if gatt proxy is disabled, proxy client can stop handling these
* two kinds of connectable advertising packets.
*/
int bt_mesh_proxy_client_enable(void)
{
u8_t i;
BT_DBG("%s", __func__);
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn) {
servers[i].conn_type = PROXY;
}
}
/**
* TODO:
* Once at leat one device has been provisioned, proxy client can be
* set to allow receiving and parsing node_id & net_id adv packets,
* and we may use a global flag to indicate this.
*/
return 0;
}
int bt_mesh_proxy_client_disable(void)
{
u8_t i;
BT_DBG("%s", __func__);
/**
* TODO:
* Once this function is invoked, proxy client shall stop handling
* node_id & net_id adv packets, and if proxy connection exists,
* it should be disconnected.
*/
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (server->conn && server->conn_type == PROXY) {
bt_mesh_gattc_disconnect(server->conn);
server->conn_type = NONE;
}
}
return 0;
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
static struct bt_mesh_prov_conn_cb conn_callbacks = {
.connected = proxy_connected,
.disconnected = proxy_disconnected,
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
.prov_write_descr = prov_write_ccc,
.prov_notify = prov_recv_ntf,
#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
.proxy_write_descr = proxy_write_ccc,
.proxy_notify = proxy_recv_ntf,
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
};
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
static struct bt_mesh_subnet *bt_mesh_is_net_id_exist(const u8_t net_id[8])
{
struct bt_mesh_subnet *sub = NULL;
size_t size, i;
size = bt_mesh_rx_netkey_size();
for (i = 0U; i < size; i++) {
sub = bt_mesh_rx_netkey_get(i);
if (sub && !memcmp(sub->keys[sub->kr_flag].net_id, net_id, 8)) {
return sub;
}
}
return NULL;
}
void proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr)
{
bt_mesh_proxy_adv_ctx_t ctx = {0};
u8_t type;
/* Check if connection reaches the maximum limitation */
if (bt_mesh_gattc_get_free_conn_count() == 0) {
BT_WARN("%s, max connections", __func__);
return;
}
type = net_buf_simple_pull_u8(buf);
switch (type) {
case BLE_MESH_PROXY_ADV_NET_ID: {
struct bt_mesh_subnet *sub = NULL;
sub = bt_mesh_is_net_id_exist(buf->data);
if (!sub) {
return;
}
memcpy(ctx.net_id.net_id, buf->data, buf->len);
ctx.net_id.net_idx = sub->net_idx;
break;
}
case BLE_MESH_PROXY_ADV_NODE_ID:
/* Gets node identity information.
* hash = aes-ecb(identity key, 16 octets(padding + random + src)) mod 2^64,
* If Proxy Client wants to get src, it may encrypts multiple times and compare
* the hash value (8 octets) with the received one.
*/
return;
default:
BT_DBG("%s, Unknwon Mesh Proxy adv type 0x%02x", __func__, type);
return;
}
if (proxy_client_adv_recv_cb) {
proxy_client_adv_recv_cb(addr, type, &ctx);
}
}
int bt_mesh_proxy_client_connect(const u8_t addr[6], u8_t addr_type, u16_t net_idx)
{
bt_mesh_addr_t remote_addr = {0};
int result;
if (!addr || addr_type > BLE_MESH_ADDR_RANDOM) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
memcpy(remote_addr.val, addr, BLE_MESH_ADDR_LEN);
remote_addr.type = addr_type;
result = bt_mesh_gattc_conn_create(&remote_addr, BLE_MESH_UUID_MESH_PROXY_VAL);
if (result < 0) {
return result;
}
/* Store corresponding net_idx which can be used for sending Proxy Configuration */
servers[result].net_idx = net_idx;
return 0;
}
int bt_mesh_proxy_client_disconnect(u8_t conn_handle)
{
struct bt_mesh_conn *conn;
if (conn_handle >= BLE_MESH_MAX_CONN) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
BT_DBG("conn_handle %d", conn_handle);
conn = servers[conn_handle].conn;
if (!conn) {
BT_ERR("%s, Not connected, conn_handle %d", __func__, conn_handle);
return -ENOTCONN;
}
bt_mesh_gattc_disconnect(conn);
return 0;
}
bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst)
{
bool send = false;
int err;
u8_t i;
BT_DBG("%u bytes to dst 0x%04x", buf->len, dst);
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
NET_BUF_SIMPLE_DEFINE(msg, 32);
if (!server->conn || server->conn_type != PROXY) {
continue;
}
/* Proxy PDU sending modifies the original buffer,
* so we need to make a copy.
*/
net_buf_simple_init(&msg, 1);
net_buf_simple_add_mem(&msg, buf->data, buf->len);
err = bt_mesh_proxy_prov_client_send(server->conn, BLE_MESH_PROXY_NET_PDU, &msg);
if (err) {
BT_ERR("%s, Failed to send proxy net message (err %d)", __func__, err);
} else {
send = true;
}
}
return send;
}
static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub)
{
NET_BUF_SIMPLE_DEFINE(buf, 23);
net_buf_simple_init(&buf, 1);
bt_mesh_beacon_create(sub, &buf);
return bt_mesh_proxy_prov_client_send(conn, BLE_MESH_PROXY_BEACON, &buf);
}
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub)
{
bool send = false;
int err;
u8_t i;
/* NULL means we send Secure Network Beacon on all subnets */
if (!sub) {
if (bt_mesh_is_provisioner_en()) {
#if CONFIG_BLE_MESH_PROVISIONER
for (i = 0U; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
if (bt_mesh.p_sub[i] && bt_mesh.p_sub[i]->net_idx != BLE_MESH_KEY_UNUSED) {
send = bt_mesh_proxy_client_beacon_send(bt_mesh.p_sub[i]);
}
}
#endif
} else {
#if CONFIG_BLE_MESH_NODE
for (i = 0U; i < ARRAY_SIZE(bt_mesh.sub); i++) {
if (bt_mesh.sub[i].net_idx != BLE_MESH_KEY_UNUSED) {
send = bt_mesh_proxy_client_beacon_send(&bt_mesh.sub[i]);
}
}
#endif
}
return send;
}
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn && servers[i].conn_type == PROXY) {
err = beacon_send(servers[i].conn, sub);
if (err) {
BT_ERR("%s, Failed to send proxy beacon message (err %d)", __func__, err);
} else {
send = true;
}
}
}
return send;
}
static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_mesh_proxy_cfg_pdu *cfg)
{
struct bt_mesh_msg_ctx ctx = {
.net_idx = net_idx,
.app_idx = BLE_MESH_KEY_UNUSED, /* CTL shall be set to 1 */
.addr = BLE_MESH_ADDR_UNASSIGNED, /* DST shall be set to the unassigned address */
.send_ttl = 0U, /* TTL shall be set to 0 */
};
struct bt_mesh_net_tx tx = {
.ctx = &ctx,
.src = bt_mesh_primary_addr(),
};
struct net_buf_simple *buf = NULL;
u16_t alloc_len;
int err;
if (bt_mesh_is_provisioner_en()) {
#if CONFIG_BLE_MESH_PROVISIONER
tx.sub = provisioner_subnet_get(net_idx);
#endif
} else {
#if CONFIG_BLE_MESH_NODE
tx.sub = bt_mesh_subnet_get(net_idx);
#endif
}
if (!tx.sub) {
BT_ERR("%s, Failed to find subnet", __func__);
return -EIO;
}
switch (cfg->opcode) {
case BLE_MESH_PROXY_CFG_FILTER_SET:
if (cfg->set.filter_type > 0x01) {
BT_ERR("%s, Invalid filter type 0x%02x", __func__, cfg->set.filter_type);
return -EINVAL;
}
alloc_len = sizeof(cfg->opcode) + sizeof(cfg->set.filter_type);
break;
case BLE_MESH_PROXY_CFG_FILTER_ADD:
if (cfg->add.addr == NULL || cfg->add.addr_num == 0) {
BT_ERR("%s, Add address list is NULL", __func__);
return -EINVAL;
}
alloc_len = sizeof(cfg->opcode) + (cfg->add.addr_num << 1);
break;
case BLE_MESH_PROXY_CFG_FILTER_REMOVE:
if (cfg->remove.addr == NULL || cfg->remove.addr_num == 0) {
BT_ERR("%s, Remove address list is NULL", __func__);
return -EINVAL;
}
alloc_len = sizeof(cfg->opcode) + (cfg->remove.addr_num << 1);
break;
default:
BT_ERR("%s, Unknown Proxy Configuration opcode 0x%02x", __func__, cfg->opcode);
return -EINVAL;
}
/**
* For Proxy Configuration PDU:
* 1 octet Proxy PDU type + 9 octets network pdu header + Tranport PDU + 8 octets NetMIC
*/
buf = bt_mesh_alloc_buf(1 + BLE_MESH_NET_HDR_LEN + alloc_len + 8);
if (!buf) {
return -ENOMEM;
}
net_buf_simple_reset(buf);
net_buf_simple_reserve(buf, 10);
net_buf_simple_add_u8(buf, cfg->opcode);
switch (cfg->opcode) {
case BLE_MESH_PROXY_CFG_FILTER_SET:
net_buf_simple_add_u8(buf, cfg->set.filter_type);
break;
case BLE_MESH_PROXY_CFG_FILTER_ADD:
for (u16_t i = 0U; i < cfg->add.addr_num; i++) {
net_buf_simple_add_le16(buf, cfg->add.addr[i]);
}
break;
case BLE_MESH_PROXY_CFG_FILTER_REMOVE:
for (u16_t i = 0U; i < cfg->remove.addr_num; i++) {
net_buf_simple_add_le16(buf, cfg->remove.addr[i]);
}
break;
}
BT_DBG("%s, len %u bytes: %s", __func__, buf->len, bt_hex(buf->data, buf->len));
err = bt_mesh_net_encode(&tx, buf, true);
if (err) {
BT_ERR("%s, Encoding Proxy message failed (err %d)", __func__, err);
bt_mesh_free_buf(buf);
return err;
}
err = bt_mesh_proxy_prov_client_send(conn, BLE_MESH_PROXY_CONFIG, buf);
if (err) {
BT_ERR("%s, Failed to send proxy cfg message (err %d)", __func__, err);
}
bt_mesh_free_buf(buf);
return err;
}
int bt_mesh_proxy_client_send_cfg(u8_t conn_handle, u16_t net_idx, struct bt_mesh_proxy_cfg_pdu *pdu)
{
struct bt_mesh_conn *conn;
if (conn_handle >= BLE_MESH_MAX_CONN || !pdu || pdu->opcode > BLE_MESH_PROXY_CFG_FILTER_REMOVE) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
BT_DBG("conn_handle %d, net_idx 0x%04x", conn_handle, net_idx);
conn = servers[conn_handle].conn;
if (!conn) {
BT_ERR("%s, Not connected, conn_handle %d", __func__, conn_handle);
return -ENOTCONN;
}
/**
* Check if net_idx used to encrypt Proxy Configuration are the same
* with the one added when creating proxy connection.
*/
if (servers[conn_handle].net_idx != net_idx) {
BT_ERR("%s, NetKey Index 0x%04x mismatch, expect 0x%04x",
__func__, net_idx, servers[conn_handle].net_idx);
return -EIO;
}
return send_proxy_cfg(conn, net_idx, pdu);
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
int bt_mesh_proxy_prov_client_init(void)
{
u8_t i;
/* Initialize the server receive buffers */
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
k_delayed_work_init(&server->sar_timer, proxy_sar_timeout);
server->buf.size = SERVER_BUF_SIZE;
server->buf.__buf = server_buf_data + (i * SERVER_BUF_SIZE);
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
server->net_idx = BLE_MESH_KEY_UNUSED;
#endif
}
bt_mesh_gattc_conn_cb_register(&conn_callbacks);
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN && CONFIG_BLE_MESH_GATT_PROXY_CLIENT
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD,
BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV, NULL);
#endif
return 0;
}
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */

View file

@ -0,0 +1,102 @@
// Copyright 2017-2019 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 _PROVISIONER_PROXY_H_
#define _PROVISIONER_PROXY_H_
#include "mesh_buf.h"
#include "net.h"
#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 {
u8_t net_id[8];
u16_t net_idx;
} net_id;
struct {
u16_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 {
u8_t opcode;
union {
struct cfg_filter_set {
u8_t filter_type;
} set;
struct cfg_addr_add {
u16_t *addr;
u16_t addr_num;
} add;
struct cfg_addr_remove {
u16_t *addr;
u16_t addr_num;
} remove;
};
};
typedef struct {
u8_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_prov_client_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg);
int provisioner_pb_gatt_enable(void);
int provisioner_pb_gatt_disable(void);
int bt_mesh_proxy_client_enable(void);
int bt_mesh_proxy_client_disable(void);
typedef void (*proxy_client_recv_adv_cb_t)(const bt_mesh_addr_t *addr, u8_t type, bt_mesh_proxy_adv_ctx_t *ctx);
typedef void (*proxy_client_connect_cb_t)(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx);
typedef void (*proxy_client_disconnect_cb_t)(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx, u8_t reason);
typedef void (*proxy_client_recv_filter_status_cb_t)(u8_t conn_handle, u16_t src, u16_t net_idx, u8_t filter_type, u16_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 proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr);
int bt_mesh_proxy_client_connect(const u8_t addr[6], u8_t addr_type, u16_t net_idx);
int bt_mesh_proxy_client_disconnect(u8_t conn_handle);
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub);
bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst);
int bt_mesh_proxy_client_send_cfg(u8_t conn_handle, u16_t net_idx, struct bt_mesh_proxy_cfg_pdu *pdu);
int bt_mesh_proxy_prov_client_init(void);
#endif /* _PROVISIONER_PROXY_H_ */

View file

@ -24,10 +24,14 @@
#include "beacon.h"
#include "foundation.h"
#include "access.h"
#include "proxy.h"
#include "proxy_server.h"
#if CONFIG_BLE_MESH_NODE
/* Not support enabling Proxy Client and Proxy Server simultaneously */
_Static_assert(!(IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)),
"Not support Proxy Server and Proxy Client simultaneously");
#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define PDU_SAR(data) (data[0] >> 6)
@ -67,7 +71,7 @@ static const struct bt_mesh_adv_param fast_adv_param = {
static bool proxy_adv_enabled;
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
static void proxy_send_beacons(struct k_work *work);
static u16_t proxy_ccc_val;
#endif
@ -87,14 +91,14 @@ static struct bt_mesh_proxy_client {
PROV,
} filter_type;
u8_t msg_type;
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
struct k_work send_beacons;
#endif
struct k_delayed_work sar_timer;
struct net_buf_simple buf;
} clients[BLE_MESH_MAX_CONN] = {
[0 ... (BLE_MESH_MAX_CONN - 1)] = {
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
.send_beacons = _K_WORK_INITIALIZER(proxy_send_beacons),
#endif
},
@ -158,7 +162,7 @@ static void proxy_sar_timeout(struct k_work *work)
bt_mesh_gatts_disconnect(client->conn, 0x13);
}
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
/* Next subnet in queue to be advertised */
static int next_idx;
@ -439,7 +443,7 @@ int bt_mesh_proxy_identity_enable(void)
static void proxy_complete_pdu(struct bt_mesh_proxy_client *client)
{
switch (client->msg_type) {
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
case BLE_MESH_PROXY_NET_PDU:
BT_DBG("Mesh Network PDU");
bt_mesh_net_recv(&client->buf, 0, BLE_MESH_NET_IF_PROXY);
@ -666,7 +670,7 @@ static ssize_t prov_ccc_read(struct bt_mesh_conn *conn,
u16_t *value = attr->user_data;
return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset, value,
sizeof(*value));
sizeof(*value));
}
/* Mesh Provisioning Service Declaration */
@ -761,7 +765,7 @@ int bt_mesh_proxy_prov_disable(bool disconnect)
#endif /* CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
static ssize_t proxy_ccc_write(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
const void *buf, u16_t len,
@ -801,7 +805,7 @@ static ssize_t proxy_ccc_read(struct bt_mesh_conn *conn,
u16_t *value = attr->user_data;
return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset, value,
sizeof(*value));
sizeof(*value));
}
/* Mesh Proxy Service Declaration */
@ -968,13 +972,13 @@ bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst)
return relayed;
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY */
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t len)
{
BT_DBG("%u bytes: %s", len, bt_hex(data, len));
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
if (gatt_svc == MESH_GATT_PROXY) {
return bt_mesh_gatts_notify(conn, &proxy_attrs[4], data, len);
}
@ -1051,7 +1055,7 @@ static const struct bt_mesh_adv_data prov_ad[] = {
};
#endif /* PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
#define ID_TYPE_NET 0x00
#define ID_TYPE_NODE 0x01
@ -1360,7 +1364,7 @@ s32_t bt_mesh_proxy_adv_start(void)
}
#endif /* PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY)
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
if (bt_mesh_is_provisioned()) {
return gatt_proxy_advertise(next_sub());
}

View file

@ -27,7 +27,7 @@
#include "transport.h"
#include "access.h"
#include "foundation.h"
#include "proxy.h"
#include "proxy_server.h"
#include "cfg_srv.h"
#include "settings_nvs.h"
@ -656,7 +656,7 @@ static int model_set(bool vnd, const char *name)
model = bt_mesh_model_get(vnd, elem_idx, model_idx);
if (!model) {
BT_ERR("%s, Failed to get %s model, elem_idx %u model_idx %u",
__func__, vnd ? "vnd" : "sig", elem_idx, model_idx);
__func__, vnd ? "vnd" : "sig", elem_idx, model_idx);
err = -ENOENT;
goto free;
}
@ -743,7 +743,7 @@ static int subnet_init(struct bt_mesh_subnet *sub)
}
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED;
} else {
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
@ -1227,7 +1227,7 @@ static void store_pending_mod_bind(struct bt_mesh_model *model, bool vnd)
err = bt_mesh_add_core_settings_item(vnd ? "mesh/vnd" : "mesh/sig", model_key);
if (err) {
BT_ERR("%s, Failed to add 0x%04x to %s", __func__, model_key,
vnd ? "mesh/vnd" : "mesh/sig");
vnd ? "mesh/vnd" : "mesh/sig");
}
return;
@ -1257,7 +1257,7 @@ static void store_pending_mod_sub(struct bt_mesh_model *model, bool vnd)
err = bt_mesh_add_core_settings_item(vnd ? "mesh/vnd" : "mesh/sig", model_key);
if (err) {
BT_ERR("%s, Failed to add 0x%04x to %s", __func__, model_key,
vnd ? "mesh/vnd" : "mesh/sig");
vnd ? "mesh/vnd" : "mesh/sig");
}
return;
@ -1301,7 +1301,7 @@ static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
err = bt_mesh_add_core_settings_item(vnd ? "mesh/vnd" : "mesh/sig", model_key);
if (err) {
BT_ERR("%s, Failed to add 0x%04x to %s", __func__, model_key,
vnd ? "mesh/vnd" : "mesh/sig");
vnd ? "mesh/vnd" : "mesh/sig");
}
return;

View file

@ -121,7 +121,7 @@ static int settings_save(nvs_handle handle, const char *key, const u8_t *val, si
}
if (err != ESP_OK) {
BT_ERR("%s, Failed to %s %s data (err %d)", __func__,
val ? "set" : "erase", key, err);
val ? "set" : "erase", key, err);
return -EIO;
}

View file

@ -40,7 +40,7 @@
* count.
*/
_Static_assert(CONFIG_BLE_MESH_ADV_BUF_COUNT >= (CONFIG_BLE_MESH_TX_SEG_MAX + 3),
"Too small BLE Mesh adv buffer count");
"Too small BLE Mesh adv buffer count");
#define AID_MASK ((u8_t)(BIT_MASK(6)))
@ -140,31 +140,31 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
net_buf_add_mem(buf, sdu->data, sdu->len);
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx,
tx->src, tx->ctx->addr,
NULL, 1)) {
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
BT_ERR("Not enough space in Friend Queue");
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx,
tx->src, tx->ctx->addr,
NULL, 1)) {
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
BT_ERR("Not enough space in Friend Queue");
net_buf_unref(buf);
return -ENOBUFS;
} else {
BT_WARN("No space in Friend Queue");
goto send;
}
}
if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE,
NULL, 1, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
net_buf_unref(buf);
return -ENOBUFS;
} else {
BT_WARN("No space in Friend Queue");
goto send;
send_cb_finalize(cb, cb_data);
return 0;
}
}
if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE,
NULL, 1, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
net_buf_unref(buf);
send_cb_finalize(cb, cb_data);
return 0;
}
}
}
send:
@ -380,12 +380,12 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
BT_DBG("SeqZero 0x%04x", seq_zero);
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) &&
!bt_mesh_friend_queue_has_space(tx->sub->net_idx, net_tx->src,
tx->dst, &tx->seq_auth,
tx->seg_n + 1) &&
BLE_MESH_ADDR_IS_UNICAST(tx->dst)) {
!bt_mesh_friend_queue_has_space(tx->sub->net_idx, net_tx->src,
tx->dst, &tx->seq_auth,
tx->seg_n + 1) &&
BLE_MESH_ADDR_IS_UNICAST(tx->dst)) {
BT_ERR("Not enough space in Friend Queue for %u segments",
tx->seg_n + 1);
tx->seg_n + 1);
seg_tx_reset(tx);
return -ENOBUFS;
}
@ -428,10 +428,10 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
}
if (bt_mesh_friend_enqueue_tx(net_tx, type,
&tx->seq_auth,
tx->seg_n + 1,
&seg->b) &&
BLE_MESH_ADDR_IS_UNICAST(net_tx->ctx->addr)) {
&tx->seq_auth,
tx->seg_n + 1,
&seg->b) &&
BLE_MESH_ADDR_IS_UNICAST(net_tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
@ -466,10 +466,10 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
}
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
bt_mesh_lpn_established()) {
bt_mesh_lpn_poll();
}
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
bt_mesh_lpn_established()) {
bt_mesh_lpn_poll();
}
}
return 0;
@ -760,7 +760,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
BLE_MESH_NET_IVI_RX(rx));
if (err) {
BT_DBG("Unable to decrypt with AppKey 0x%03x",
key->app_idx);
key->app_idx);
continue;
}
@ -927,45 +927,45 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, u8_t hdr,
}
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && !bt_mesh_lpn_established()) {
switch (ctl_op) {
case TRANS_CTL_OP_FRIEND_POLL:
return bt_mesh_friend_poll(rx, buf);
case TRANS_CTL_OP_FRIEND_REQ:
return bt_mesh_friend_req(rx, buf);
case TRANS_CTL_OP_FRIEND_CLEAR:
return bt_mesh_friend_clear(rx, buf);
case TRANS_CTL_OP_FRIEND_CLEAR_CFM:
return bt_mesh_friend_clear_cfm(rx, buf);
case TRANS_CTL_OP_FRIEND_SUB_ADD:
return bt_mesh_friend_sub_add(rx, buf);
case TRANS_CTL_OP_FRIEND_SUB_REM:
return bt_mesh_friend_sub_rem(rx, buf);
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && !bt_mesh_lpn_established()) {
switch (ctl_op) {
case TRANS_CTL_OP_FRIEND_POLL:
return bt_mesh_friend_poll(rx, buf);
case TRANS_CTL_OP_FRIEND_REQ:
return bt_mesh_friend_req(rx, buf);
case TRANS_CTL_OP_FRIEND_CLEAR:
return bt_mesh_friend_clear(rx, buf);
case TRANS_CTL_OP_FRIEND_CLEAR_CFM:
return bt_mesh_friend_clear_cfm(rx, buf);
case TRANS_CTL_OP_FRIEND_SUB_ADD:
return bt_mesh_friend_sub_add(rx, buf);
case TRANS_CTL_OP_FRIEND_SUB_REM:
return bt_mesh_friend_sub_rem(rx, buf);
}
}
}
#if defined(CONFIG_BLE_MESH_LOW_POWER)
if (ctl_op == TRANS_CTL_OP_FRIEND_OFFER) {
return bt_mesh_lpn_friend_offer(rx, buf);
}
if (rx->ctx.addr == bt_mesh.lpn.frnd) {
if (ctl_op == TRANS_CTL_OP_FRIEND_CLEAR_CFM) {
return bt_mesh_lpn_friend_clear_cfm(rx, buf);
if (ctl_op == TRANS_CTL_OP_FRIEND_OFFER) {
return bt_mesh_lpn_friend_offer(rx, buf);
}
if (!rx->friend_cred) {
BT_WARN("Message from friend with wrong credentials");
return -EINVAL;
}
if (rx->ctx.addr == bt_mesh.lpn.frnd) {
if (ctl_op == TRANS_CTL_OP_FRIEND_CLEAR_CFM) {
return bt_mesh_lpn_friend_clear_cfm(rx, buf);
}
switch (ctl_op) {
case TRANS_CTL_OP_FRIEND_UPDATE:
return bt_mesh_lpn_friend_update(rx, buf);
case TRANS_CTL_OP_FRIEND_SUB_CFM:
return bt_mesh_lpn_friend_sub_cfm(rx, buf);
if (!rx->friend_cred) {
BT_WARN("Message from friend with wrong credentials");
return -EINVAL;
}
switch (ctl_op) {
case TRANS_CTL_OP_FRIEND_UPDATE:
return bt_mesh_lpn_friend_update(rx, buf);
case TRANS_CTL_OP_FRIEND_SUB_CFM:
return bt_mesh_lpn_friend_sub_cfm(rx, buf);
}
}
}
#endif /* CONFIG_BLE_MESH_LOW_POWER */
}
@ -1056,7 +1056,7 @@ int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE,
seq_auth, 1, &buf->b) &&
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go
* out through the Friend Queue.
*/
@ -1281,7 +1281,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
if (is_replay(net_rx, &rpl)) {
BT_WARN("Replay: src 0x%04x dst 0x%04x seq 0x%06x",
net_rx->ctx.addr, net_rx->ctx.recv_dst, net_rx->seq);
net_rx->ctx.addr, net_rx->ctx.recv_dst, net_rx->seq);
return -EINVAL;
}
@ -1375,11 +1375,11 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
* case this message is destined to an LPN of ours.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) &&
net_rx->friend_match && !net_rx->local_match &&
!bt_mesh_friend_queue_has_space(net_rx->sub->net_idx,
net_rx->ctx.addr,
net_rx->ctx.recv_dst, seq_auth,
*seg_count)) {
net_rx->friend_match && !net_rx->local_match &&
!bt_mesh_friend_queue_has_space(net_rx->sub->net_idx,
net_rx->ctx.addr,
net_rx->ctx.recv_dst, seq_auth,
*seg_count)) {
BT_ERR("No space in Friend Queue for %u segments", *seg_count);
send_ack(net_rx->sub, net_rx->ctx.recv_dst, net_rx->ctx.addr,
net_rx->ctx.send_ttl, seq_auth, 0,
@ -1504,12 +1504,12 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
* be encrypted using the Friend Credentials.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
bt_mesh_lpn_established() && rx->net_if == BLE_MESH_NET_IF_ADV &&
(!bt_mesh_lpn_waiting_update() || !rx->friend_cred)) {
BT_WARN("Ignoring unexpected message in Low Power mode");
return -EAGAIN;
}
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
bt_mesh_lpn_established() && rx->net_if == BLE_MESH_NET_IF_ADV &&
(!bt_mesh_lpn_waiting_update() || !rx->friend_cred)) {
BT_WARN("Ignoring unexpected message in Low Power mode");
return -EAGAIN;
}
}
/* Save the app-level state so the buffer can later be placed in
@ -1545,7 +1545,7 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) &&
(bt_mesh_lpn_timer() ||
(bt_mesh_lpn_established() && bt_mesh_lpn_waiting_update()))) {
(bt_mesh_lpn_established() && bt_mesh_lpn_waiting_update()))) {
bt_mesh_lpn_msg_received(rx);
}
}
@ -1556,10 +1556,10 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && rx->friend_match && !err) {
if (seq_auth == TRANS_SEQ_AUTH_NVAL) {
bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL,
seg_count, buf);
seg_count, buf);
} else {
bt_mesh_friend_enqueue_rx(rx, pdu_type, &seq_auth,
seg_count, buf);
seg_count, buf);
}
}
}
@ -1666,5 +1666,5 @@ void bt_mesh_heartbeat_send(void)
BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
NULL, NULL, NULL);
NULL, NULL, NULL);
}

View file

@ -26,15 +26,32 @@
#include "mesh.h"
#include "client_common.h"
static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t tx_dst)
{
if (sys_slist_is_empty(list)) {
return NULL;
}
sys_snode_t *cur = NULL; bt_mesh_client_node_t *node = NULL;
for (cur = sys_slist_peek_head(list);
cur != NULL; cur = sys_slist_peek_next(cur)) {
node = (bt_mesh_client_node_t *)cur;
if (node->ctx.addr == tx_dst) {
return node;
}
}
return NULL;
}
bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub)
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub)
{
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_user_data_t *cli = NULL;
bt_mesh_client_node_t *node = NULL;
u32_t rsp;
if (!model || !ctx || !buf) {
BT_ERR("%s, Invalid parameter", __func__);
@ -47,16 +64,14 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
return NULL;
}
rsp = ctx->recv_op;
/** If the received message address is not a unicast address,
* the address may be a group/virtual address, and we push
* this message to the application layer.
*/
if (!BLE_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) {
BT_DBG("Unexpected status message 0x%x", rsp);
BT_DBG("Unexpected status message 0x%x", ctx->recv_op);
if (cli->publish_status && need_pub) {
cli->publish_status(rsp, model, ctx, buf);
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
return NULL;
}
@ -73,17 +88,17 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
}
if ((node = bt_mesh_client_pick_node(&data->queue, ctx->addr)) == NULL) {
BT_DBG("Unexpected status message 0x%x", rsp);
BT_DBG("Unexpected status message 0x%x", ctx->recv_op);
if (cli->publish_status && need_pub) {
cli->publish_status(rsp, model, ctx, buf);
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
return NULL;
}
if (node->op_pending != rsp) {
BT_DBG("Unexpected status message 0x%x", rsp);
if (node->op_pending != ctx->recv_op) {
BT_DBG("Unexpected status message 0x%x", ctx->recv_op);
if (cli->publish_status && need_pub) {
cli->publish_status(rsp, model, ctx, buf);
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
return NULL;
}
@ -91,26 +106,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
return node;
}
bool bt_mesh_client_find_opcode_in_list(sys_slist_t *list, u32_t opcode)
{
if (sys_slist_is_empty(list)) {
return false;
}
sys_snode_t *cur = NULL; bt_mesh_client_node_t *node = NULL;
for (cur = sys_slist_peek_head(list);
cur != NULL; cur = sys_slist_peek_next(cur)) {
node = (bt_mesh_client_node_t *)cur;
if (node->op_pending == opcode) {
return true;
}
return NULL;
}
return node;
}
bool bt_mesh_client_check_node_in_list(sys_slist_t *list, u16_t tx_dst)
static bool bt_mesh_client_check_node_in_list(sys_slist_t *list, u16_t tx_dst)
{
if (sys_slist_is_empty(list)) {
return false;
@ -128,24 +124,6 @@ bool bt_mesh_client_check_node_in_list(sys_slist_t *list, u16_t tx_dst)
return false;
}
bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t tx_dst)
{
if (sys_slist_is_empty(list)) {
return NULL;
}
sys_snode_t *cur = NULL; bt_mesh_client_node_t *node = NULL;
for (cur = sys_slist_peek_head(list);
cur != NULL; cur = sys_slist_peek_next(cur)) {
node = (bt_mesh_client_node_t *)cur;
if (node->ctx.addr == tx_dst) {
return node;
}
}
return NULL;
}
static u32_t bt_mesh_client_get_status_op(const bt_mesh_client_op_pair_t *op_pair,
int size, u32_t opcode)
{

View file

@ -157,7 +157,7 @@ static void timeout_handler(struct k_work *work)
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_generic_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}

View file

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _MODEL_COMMON_H_
#define _MODEL_COMMON_H_
#ifndef _CLIENT_COMMON_H_
#define _CLIENT_COMMON_H_
#include "mesh_access.h"
@ -94,15 +94,9 @@ int bt_mesh_client_init(struct bt_mesh_model *model);
* @return 0 on success, or (negative) error code on failure.
*/
bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub);
bool bt_mesh_client_find_opcode_in_list(sys_slist_t *list, u32_t opcode);
bool bt_mesh_client_check_node_in_list(sys_slist_t *list, uint16_t tx_dst);
bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t tx_dst);
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub);
int bt_mesh_client_send_msg(struct bt_mesh_model *model,
u32_t opcode,
@ -136,5 +130,5 @@ typedef struct {
*/
int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common);
#endif /* _MODEL_COMMON_H_ */
#endif /* _CLIENT_COMMON_H_ */

View file

@ -166,7 +166,7 @@ static void timeout_handler(struct k_work *work)
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_lighting_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}

View file

@ -95,7 +95,7 @@ static void timeout_handler(struct k_work *work)
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_sensor_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}

View file

@ -111,7 +111,7 @@ static void timeout_handler(struct k_work *work)
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
if (node) {
bt_mesh_time_scene_client_cb_evt_to_btc(node->opcode,
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
// Don't forget to release the node at the end.
bt_mesh_client_free_node(node);
}

View file

@ -0,0 +1,150 @@
// Copyright 2017-2019 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.
#include <string.h>
#include <stdint.h>
#include "mesh_types.h"
#include "server_common.h"
#include "device_property.h"
static struct bt_mesh_dev_prop {
u16_t prop_id;
u8_t len;
} device_properties [] = {
{ BLE_MESH_INVALID_DEVICE_PROPERTY_ID, 0xFF },
{ BLE_MESH_AVERAGE_AMBIENT_TEMPERATURE_IN_A_PERIOD_OF_DAY, 0x03 },
{ BLE_MESH_AVERAGE_INPUT_CURRENT, 0x03 },
{ BLE_MESH_AVERAGE_INPUT_VOLTAGE, 0x03 },
{ BLE_MESH_AVERAGE_OUTPUT_CURRENT, 0x03 },
{ BLE_MESH_AVERAGE_OUTPUT_VOLTAGE, 0x03 },
{ BLE_MESH_CENTER_BEAM_INTENSITY_AT_FULL_POWER, 0x02 },
{ BLE_MESH_CHROMATICITY_TOLERANCE, 0x01 },
{ BLE_MESH_COLOR_RENDERING_INDEX_R9, 0x01 },
{ BLE_MESH_COLOR_RENDERING_INDEX_RA, 0x01 },
{ BLE_MESH_DEVICE_APPEARANCE, 0x02 },
{ BLE_MESH_DEVICE_COUNTRY_OF_ORIGIN, 0x02 },
{ BLE_MESH_DEVICE_DATE_OF_MANUFACTURE, 0x04 },
{ BLE_MESH_DEVICE_ENERGY_USE_SINCE_TURN_ON, 0x04 },
{ BLE_MESH_DEVICE_FIRMWARE_REVISION, 0x08 },
{ BLE_MESH_DEVICE_GLOBAL_TRADE_ITEM_NUMBER, 0x08 },
{ BLE_MESH_DEVICE_HARDWARE_REVISION, 0x16 },
{ BLE_MESH_DEVICE_MANUFACTURER_NAME, 0x36 },
{ BLE_MESH_DEVICE_MODEL_NUMBER, 0x24 },
{ BLE_MESH_DEVICE_OPERATING_TEMPERATURE_RANGE_SPECIFICATION, 0x04 },
{ BLE_MESH_DEVICE_OPERATING_TEMPERATURE_STATISTICAL_VALUES, 0x09 },
{ BLE_MESH_DEVICE_OVER_TEMPERATURE_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_DEVICE_POWER_RANGE_SPECIFICATION, 0x12 },
{ BLE_MESH_DEVICE_RUNTIME_SINCE_TURN_ON, 0x04 },
{ BLE_MESH_DEVICE_RUNTIME_WARRANTY, 0x04 },
{ BLE_MESH_DEVICE_SERIAL_NUMBER, 0x16 },
{ BLE_MESH_DEVICE_SOFTWARE_REVISION, 0x08 },
{ BLE_MESH_DEVICE_UNDER_TEMPERATURE_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_INDOOR_AMBIENT_TEMPERATURE_STATISTICAL_VALUES, 0x05 },
{ BLE_MESH_INITIAL_CIE_1931_CHROMATICITY_COORDINATES, 0x04 },
{ BLE_MESH_INITIAL_CORRELATED_COLOR_TEMPERATURE, 0x02 },
{ BLE_MESH_INITIAL_LUMINOUS_FLUX, 0x02 },
{ BLE_MESH_INITIAL_PLANCKIAN_DISTANCE, 0x02 },
{ BLE_MESH_INPUT_CURRENT_RANGE_SPECIFICATION, 0x06 },
{ BLE_MESH_INPUT_CURRENT_STATISTICS, 0x09 },
{ BLE_MESH_INPUT_OVER_CURRENT_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_INPUT_OVER_RIPPLE_VOLTAGE_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_INPUT_OVER_VOLTAGE_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_INPUT_UNDER_CURRENT_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_INPUT_UNDER_VOLTAGE_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_INPUT_VOLTAGE_RANGE_SPECIFICATION, 0x06 },
{ BLE_MESH_INPUT_VOLTAGE_RIPPLE_SPECIFICATION, 0x01 },
{ BLE_MESH_INPUT_VOLTAGE_STATISTICS, 0x09 },
{ BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_ON, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_PROLONG, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_STANDBY, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_LIGHTNESS_ON, 0x02 },
{ BLE_MESH_LIGHT_CONTROL_LIGHTNESS_PROLONG, 0x02 },
{ BLE_MESH_LIGHT_CONTROL_LIGHTNESS_STANDBY, 0x02 },
{ BLE_MESH_LIGHT_CONTROL_REGULATOR_ACCURACY, 0x01 },
{ BLE_MESH_LIGHT_CONTROL_REGULATOR_KID, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_REGULATOR_KIU, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_REGULATOR_KPD, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_REGULATOR_KPU, 0x04 },
{ BLE_MESH_LIGHT_CONTROL_TIME_FADE, 0x03 },
{ BLE_MESH_LIGHT_CONTROL_TIME_FADE_ON, 0x03 },
{ BLE_MESH_LIGHT_CONTROL_TIME_FADE_STANDBY_AUTO, 0x03 },
{ BLE_MESH_LIGHT_CONTROL_TIME_FADE_STANDBY_MANUAL, 0x03 },
{ BLE_MESH_LIGHT_CONTROL_TIME_OCCUPANCY_DELAY, 0x03 },
{ BLE_MESH_LIGHT_CONTROL_TIME_PROLONG, 0x03 },
{ BLE_MESH_LIGHT_CONTROL_TIME_RUN_ON, 0x03 },
{ BLE_MESH_LUMEN_MAINTENANCE_FACTOR, 0x01 },
{ BLE_MESH_LUMINOUS_EFFICACY, 0x02 },
{ BLE_MESH_LUMINOUS_ENERGY_SINCE_TURN_ON, 0x04 },
{ BLE_MESH_LUMINOUS_EXPOSURE, 0x04 },
{ BLE_MESH_LUMINOUS_FLUX_RANGE, 0x04 },
{ BLE_MESH_MOTION_SENSED, 0x01 },
{ BLE_MESH_MOTION_THRESHOLD, 0x01 },
{ BLE_MESH_OPEN_CIRCUIT_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_OUTDOOR_STATISTICAL_VALUES, 0x05 },
{ BLE_MESH_OUTPUT_CURRENT_RANGE, 0x04 },
{ BLE_MESH_OUTPUT_CURRENT_STATISTICS, 0x09 },
{ BLE_MESH_OUTPUT_RIPPLE_VOLTAGE_SPECIFICATION, 0x01 },
{ BLE_MESH_OUTPUT_VOLTAGE_RANGE, 0x06 },
{ BLE_MESH_OUTPUT_VOLTAGE_STATISTICS, 0x09 },
{ BLE_MESH_OVER_OUTPUT_RIPPLE_VOLTAGE_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_PEOPLE_COUNT, 0x02 },
{ BLE_MESH_PRESENCE_DETECTED, 0x01 },
{ BLE_MESH_PRESENT_AMBIENT_LIGHT_LEVEL, 0x04 },
{ BLE_MESH_PRESENT_AMBIENT_TEMPERATURE, 0x01 },
{ BLE_MESH_PRESENT_CIE_1931_CHROMATICITY, 0x04 },
{ BLE_MESH_PRESENT_CORRELATED_COLOR_TEMPERATURE, 0x02 },
{ BLE_MESH_PRESENT_DEVICE_INPUT_POWER, 0x04 },
{ BLE_MESH_PRESENT_DEVICE_OPERATING_EFFICIENCY, 0x01 },
{ BLE_MESH_PRESENT_DEVICE_OPERATING_TEMPERATURE, 0x02 },
{ BLE_MESH_PRESENT_ILLUMINANCE, 0x04 },
{ BLE_MESH_PRESENT_INDOOR_AMBIENT_TEMPERATURE, 0x01 },
{ BLE_MESH_PRESENT_INPUT_CURRENT, 0x02 },
{ BLE_MESH_PRESENT_INPUT_RIPPLE_VOLTAGE, 0x01 },
{ BLE_MESH_PRESENT_INPUT_VOLTAGE, 0x02 },
{ BLE_MESH_PRESENT_LUMINOUS_FLUX, 0x02 },
{ BLE_MESH_PRESENT_OUTDOOR_AMBIENT_TEMPERATURE, 0x01 },
{ BLE_MESH_PRESENT_OUTPUT_CURRENT, 0x02 },
{ BLE_MESH_PRESENT_OUTPUT_VOLTAGE, 0x02 },
{ BLE_MESH_PRESENT_PLANCKIAN_DISTANCE, 0x02 },
{ BLE_MESH_PRESENT_RELATIVE_OUTPUT_RIPPLE_VOLTAGE, 0x01 },
{ BLE_MESH_RELATIVE_DEVICE_ENERGY_USE_IN_A_PERIOD_OF_DAY, 0x06 },
{ BLE_MESH_RELATIVE_DEVICE_RUNTIME_IN_A_GENERIC_LEVEL_RANGE, 0x05 },
{ BLE_MESH_RELATIVE_EXPOSURE_TIME_IN_AN_ILLUMINANCE_RANGE, 0x09 },
{ BLE_MESH_RELATIVE_RUNTIME_IN_A_CORRELATED_COLOR_TEMPERATURE_RANGE, 0x04 },
{ BLE_MESH_RELATIVE_RUNTIME_IN_A_DEVICE_OPERATING_TEMPERATURE_RANGE, 0x05 },
{ BLE_MESH_RELATIVE_RUNTIME_IN_AN_INPUT_CURRENT_RANGE, 0x05 },
{ BLE_MESH_RELATIVE_RUNTIME_IN_AN_INPUT_VOLTAGE_RANGE, 0x05 },
{ BLE_MESH_SHORT_CIRCUIT_EVENT_STATISTICS, 0x06 },
{ BLE_MESH_TIME_SINCE_MOTION_SENSED, 0x02 },
{ BLE_MESH_TIME_SINCE_PRESENCE_DETECTED, 0x02 },
{ BLE_MESH_TOTAL_DEVICE_ENERGY_USE, 0x04 },
{ BLE_MESH_TOTAL_DEVICE_OFF_ON_CYCLES, 0x04 },
{ BLE_MESH_TOTAL_DEVICE_POWER_ON_CYCLES, 0x04 },
{ BLE_MESH_TOTAL_DEVICE_POWER_ON_TIME, 0x04 },
{ BLE_MESH_TOTAL_DEVICE_RUNTIME, 0x04 },
{ BLE_MESH_TOTAL_LIGHT_EXPOSURE_TIME, 0x04 },
{ BLE_MESH_TOTAL_LUMINOUS_ENERGY, 0x04 },
};
u8_t bt_mesh_get_dev_prop_len(u16_t prop_id)
{
if (prop_id > BLE_MESH_TOTAL_LUMINOUS_ENERGY) {
BT_ERR("%s, Unknown Device Property ID 0x%04x", __func__, prop_id);
return UINT8_MAX;
}
return device_properties[prop_id].len;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

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

View file

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

Some files were not shown because too many files have changed in this diff Show more