mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ble_mesh: Miscellaneous modifications
1. Add an API to set Provisioner static oob value 2. Add an API to deinit BLE Mesh stack 3. Add an API to set Provisioner unicast address 4. Add an API to provision devices with fixed address 5. Add an API to store node composition data 6. Add an API to get node with device uuid 7. Add an API to get node with unicast address 8. Add an API to delete node with device uuid 9. Add an API to delete node with unicast address 10. Add an API for Provisioner to update local AppKey 11. Add an API for Provisioner to update local NetKey 12. Support Provisioner persistent functionality 13. Fix Provisioner entering IV Update procedure 14. Fix an issue which may cause client failing to send msg 15. Use bt_mesh.flags to indicate device role 16. Remove several useless macros 17. Callback RSSI of received mesh provisioning packets 18. Modify the Provisioner disable function 19. Change some log level from debug to info 20. Add parameters to Provisioner bind AppKey completion event 21. Fix node ignoring relay messages issue 22. Support using a specific partition for BLE Mesh 23. Fix compile warning when proxy related macros are disabled 24. Clean up BLE Mesh stack included header files 25. NULL can be input if client message needs no parameters 26. Fix compile warning when BT log is disabled 27. Initilize BLE Mesh stack local variables 28. Support using PSRAM for BLE Mesh mutex, queue and task 29. Add a menuconfig option to enable using memory from PSRAM 30. Clean up sdkconfig.defaults of BLE Mesh examples
This commit is contained in:
parent
df06f7d715
commit
711c8472fc
@ -362,7 +362,6 @@ if(CONFIG_BT_ENABLED)
|
||||
"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/proxy_client.c"
|
||||
|
@ -18,6 +18,13 @@ if BLE_MESH
|
||||
option in the Bluetooth Controller section in menuconfig, which is
|
||||
"Scan Duplicate By Device Address and Advertising Data".
|
||||
|
||||
config BLE_MESH_ALLOC_FROM_PSRAM_FIRST
|
||||
bool "BLE Mesh will first allocate memory from PSRAM"
|
||||
default n
|
||||
help
|
||||
When this option is enabled, BLE Mesh stack will try to allocate memory
|
||||
from PSRAM firstly. This will save the internal RAM if PSRAM exists.
|
||||
|
||||
config BLE_MESH_FAST_PROV
|
||||
bool "Enable BLE Mesh Fast Provisioning"
|
||||
select BLE_MESH_NODE
|
||||
@ -116,7 +123,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_PROVISIONER_APP_KEY_COUNT
|
||||
int "Maximum number of application keys that can be owned by Provisioner"
|
||||
default 9
|
||||
default 3
|
||||
range 1 4096
|
||||
help
|
||||
This option specifies how many application keys the Provisioner can have.
|
||||
@ -168,15 +175,6 @@ if BLE_MESH
|
||||
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_SERVER
|
||||
@ -191,20 +189,25 @@ if BLE_MESH
|
||||
node, it will start to advertise using Node Identity during the time
|
||||
set by this option. And after that, Network ID will be advertised.
|
||||
|
||||
if BLE_MESH_PROXY
|
||||
config BLE_MESH_PROXY_FILTER_SIZE
|
||||
int "Maximum number of filter entries per Proxy Client"
|
||||
depends on BLE_MESH_GATT_PROXY_SERVER
|
||||
default 4
|
||||
range 1 32767
|
||||
help
|
||||
This option specifies how many Proxy Filter entries the local node supports.
|
||||
The entries of Proxy filter (whitelist or blacklist) are used to store a
|
||||
list of addresses which can be used to decide which messages will be forwarded
|
||||
to the Proxy Client by the Proxy Server.
|
||||
|
||||
config BLE_MESH_PROXY_FILTER_SIZE
|
||||
int "Maximum number of filter entries per Proxy Client"
|
||||
default 1
|
||||
default 3 if BLE_MESH_GATT_PROXY_SERVER
|
||||
range 1 32767
|
||||
help
|
||||
This option specifies how many Proxy Filter entries the local node supports.
|
||||
The entries of Proxy filter (whitelist or blacklist) are used to store a
|
||||
list of addresses which can be used to decide which messages will be forwarded
|
||||
to the Proxy Client by the Proxy Server.
|
||||
|
||||
endif # BLE_MESH_PROXY
|
||||
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_NET_BUF_POOL_USAGE
|
||||
bool "BLE Mesh net buffer pool usage tracking"
|
||||
@ -215,16 +218,42 @@ if BLE_MESH
|
||||
devices. Recommend to enable this option as default.
|
||||
|
||||
config BLE_MESH_SETTINGS
|
||||
bool "Store BLE Mesh Node configuration persistently"
|
||||
bool "Store BLE Mesh configuration persistently"
|
||||
default n
|
||||
help
|
||||
When selected, the BLE Mesh stack will take care of storing/restoring the
|
||||
BLE Mesh configuration persistently in flash. Currently this only supports
|
||||
storing BLE Mesh node configuration.
|
||||
Currently enabling this option will only store BLE Mesh nodes' information
|
||||
in the flash.
|
||||
When selected, the BLE Mesh stack will take care of storing/restoring the BLE
|
||||
Mesh configuration persistently in flash.
|
||||
If the device is a BLE Mesh node, when this option is enabled, the configuration
|
||||
of the device will be stored persistently, including unicast address, NetKey,
|
||||
AppKey, etc.
|
||||
And if the device is a BLE Mesh Provisioner, the information of the device will
|
||||
be stored persistently, including the information of provisioned nodes, NetKey,
|
||||
AppKey, etc.
|
||||
|
||||
if BLE_MESH_SETTINGS
|
||||
|
||||
config BLE_MESH_SPECIFIC_PARTITION
|
||||
bool "Use a specific NVS partition for BLE Mesh"
|
||||
default n
|
||||
help
|
||||
When selected, the mesh stack will use a specified NVS partition instead of
|
||||
default NVS partition. Note that the specified partition must be registered
|
||||
with NVS using nvs_flash_init_partition() API, and the partition must exists
|
||||
in the csv file.
|
||||
When Provisioner needs to store a large amount of nodes' information in the
|
||||
flash (e.g. more than 20), this option is recommended to be enabled.
|
||||
|
||||
if BLE_MESH_SPECIFIC_PARTITION
|
||||
|
||||
config BLE_MESH_PARTITION_NAME
|
||||
string "Name of the NVS partition for BLE Mesh"
|
||||
default "ble_mesh"
|
||||
help
|
||||
This value defines the name of the specified NVS partition used by the
|
||||
mesh stack.
|
||||
|
||||
endif # BLE_MESH_SPECIFIC_PARTITION
|
||||
|
||||
config BLE_MESH_STORE_TIMEOUT
|
||||
int "Delay (in seconds) before storing anything persistently"
|
||||
range 0 1000000
|
||||
@ -239,7 +268,7 @@ if BLE_MESH
|
||||
config BLE_MESH_SEQ_STORE_RATE
|
||||
int "How often the sequence number gets updated in storage"
|
||||
range 0 1000000
|
||||
default 128
|
||||
default 6
|
||||
help
|
||||
This value defines how often the local sequence number gets updated in
|
||||
persistent storage (i.e. flash). e.g. a value of 100 means that the
|
||||
@ -403,7 +432,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_TX_SEG_MAX
|
||||
int "Maximum number of segments in outgoing messages"
|
||||
default 20
|
||||
default 32
|
||||
range 2 32
|
||||
help
|
||||
Maximum number of segments supported for outgoing messages.
|
||||
|
@ -17,9 +17,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/alarm.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
@ -31,7 +29,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
SemaphoreHandle_t semaphore = NULL;
|
||||
btc_msg_t msg = {0};
|
||||
esp_err_t ret;
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if (prov == NULL || comp == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -46,7 +44,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
|
||||
// Create a semaphore
|
||||
if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory for the semaphore", __func__);
|
||||
BT_ERR("%s, Failed to allocate memory for the semaphore", __func__);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
@ -61,7 +59,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
|
||||
if (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) != BT_STATUS_SUCCESS) {
|
||||
vSemaphoreDelete(semaphore);
|
||||
LOG_ERROR("%s, BLE Mesh initialise failed", __func__);
|
||||
BT_ERR("%s, BLE Mesh initialise failed", __func__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@ -73,3 +71,12 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param)
|
||||
{
|
||||
if (param == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_deinit(param);
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
|
@ -13,9 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
@ -37,17 +36,17 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
uint8_t op_len = 0, mic_len = 0;
|
||||
uint8_t *msg_data = NULL;
|
||||
btc_msg_t msg = {0};
|
||||
esp_err_t status;
|
||||
esp_err_t status = ESP_OK;
|
||||
|
||||
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__);
|
||||
BT_ERR("%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);
|
||||
BT_ERR("%s, Invalid device role 0x%02x", __func__, device_role);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -66,7 +65,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
|
||||
if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) {
|
||||
if (op_len + length > model->pub->msg->size) {
|
||||
LOG_ERROR("%s, Model publication msg size %d is too small", __func__, model->pub->msg->size);
|
||||
BT_ERR("%s, Model publication msg size %d is too small", __func__, model->pub->msg->size);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
@ -78,7 +77,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
}
|
||||
|
||||
if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) {
|
||||
LOG_ERROR("%s, Data length %d is too large", __func__, length);
|
||||
BT_ERR("%s, Data length %d is too large", __func__, length);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -86,7 +85,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
bt_mesh_model_msg_init(model->pub->msg, opcode);
|
||||
net_buf_simple_add_mem(model->pub->msg, data, length);
|
||||
} else {
|
||||
msg_data = (uint8_t *)osi_malloc(op_len + length);
|
||||
msg_data = (uint8_t *)bt_mesh_malloc(op_len + length);
|
||||
if (msg_data == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
@ -115,7 +114,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
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);
|
||||
bt_mesh_free(msg_data);
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -129,7 +128,7 @@ esp_err_t esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb_t ca
|
||||
|
||||
esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode)
|
||||
{
|
||||
uint16_t val;
|
||||
uint16_t val = 0;
|
||||
|
||||
if (data == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -161,9 +160,23 @@ esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
|
||||
if (model == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return btc_ble_mesh_client_model_init(model);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model)
|
||||
{
|
||||
if (model == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return btc_ble_mesh_client_model_deinit(model);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode,
|
||||
uint16_t length, uint8_t *data)
|
||||
@ -238,7 +251,7 @@ esp_err_t esp_ble_mesh_node_local_reset(void)
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER)
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name)
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(uint16_t index, const char *name)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -260,20 +273,102 @@ esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(int index)
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(uint16_t index)
|
||||
{
|
||||
return bt_mesh_provisioner_get_node_name(index);
|
||||
}
|
||||
|
||||
int esp_ble_mesh_provisioner_get_node_index(const char *name)
|
||||
uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name)
|
||||
{
|
||||
if (!name || (strlen(name) > ESP_BLE_MESH_NODE_NAME_MAX_LEN)) {
|
||||
return -EINVAL;
|
||||
return ESP_BLE_MESH_INVALID_NODE_INDEX;
|
||||
}
|
||||
|
||||
return bt_mesh_provisioner_get_node_index(name);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr, uint8_t *data, uint16_t length)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr) || !data || length <= 14) {
|
||||
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_PROVISIONER_STORE_NODE_COMP_DATA;
|
||||
|
||||
arg.store_node_comp_data.unicast_addr = unicast_addr;
|
||||
arg.store_node_comp_data.length = length;
|
||||
arg.store_node_comp_data.data = data;
|
||||
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_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16])
|
||||
{
|
||||
if (!uuid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_node_with_uuid(uuid);
|
||||
}
|
||||
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr)
|
||||
{
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_node_with_addr(unicast_addr);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16])
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!uuid) {
|
||||
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_PROVISIONER_DELETE_NODE_WITH_UUID;
|
||||
|
||||
memcpy(arg.delete_node_with_uuid.uuid, uuid, 16);
|
||||
|
||||
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_provisioner_delete_node_with_addr(uint16_t unicast_addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) {
|
||||
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_PROVISIONER_DELETE_NODE_WITH_ADDR;
|
||||
|
||||
arg.delete_node_with_addr.unicast_addr = unicast_addr;
|
||||
|
||||
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_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
@ -284,7 +379,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SET_LOCAL_APP_KEY;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_APP_KEY;
|
||||
|
||||
arg.add_local_app_key.net_idx = net_idx;
|
||||
arg.add_local_app_key.app_idx = app_idx;
|
||||
@ -297,6 +392,29 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (app_key == 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_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY;
|
||||
|
||||
memcpy(arg.update_local_app_key.app_key, app_key, 16);
|
||||
arg.update_local_app_key.net_idx = net_idx;
|
||||
arg.update_local_app_key.app_idx = app_idx;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
const uint8_t *esp_ble_mesh_provisioner_get_local_app_key(uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
return bt_mesh_provisioner_local_app_key_get(net_idx, app_idx);
|
||||
@ -351,11 +469,37 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16], uint16_t net_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (net_key == 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_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY;
|
||||
|
||||
memcpy(arg.update_local_net_key.net_key, net_key, 16);
|
||||
arg.update_local_net_key.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);
|
||||
}
|
||||
|
||||
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx)
|
||||
{
|
||||
return bt_mesh_provisioner_local_net_key_get(net_idx);
|
||||
}
|
||||
|
||||
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_prov_node_count();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
#if (CONFIG_BLE_MESH_FAST_PROV)
|
||||
|
@ -13,8 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
@ -285,6 +285,38 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16],
|
||||
esp_ble_mesh_bd_addr_t addr, esp_ble_mesh_addr_type_t addr_type,
|
||||
esp_ble_mesh_prov_bearer_t bearer, uint16_t oob_info, uint16_t unicast_addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (uuid == NULL || (bearer == ESP_BLE_MESH_PROV_GATT && (addr == NULL ||
|
||||
addr_type > ESP_BLE_MESH_ADDR_TYPE_RANDOM)) ||
|
||||
(bearer != ESP_BLE_MESH_PROV_ADV && bearer != ESP_BLE_MESH_PROV_GATT) ||
|
||||
!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) {
|
||||
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_PROVISIONER_PROV_DEV_WITH_ADDR;
|
||||
|
||||
memcpy(arg.provisioner_prov_dev_with_addr.uuid, uuid, 16);
|
||||
if (addr) {
|
||||
memcpy(arg.provisioner_prov_dev_with_addr.addr, addr, BD_ADDR_LEN);
|
||||
arg.provisioner_prov_dev_with_addr.addr_type = addr_type;
|
||||
}
|
||||
arg.provisioner_prov_dev_with_addr.bearer = bearer;
|
||||
arg.provisioner_prov_dev_with_addr.oob_info = oob_info;
|
||||
arg.provisioner_prov_dev_with_addr.unicast_addr = unicast_addr;
|
||||
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_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_dev)
|
||||
{
|
||||
uint8_t val = DEL_DEV_ADDR_FLAG | DEL_DEV_UUID_FLAG;
|
||||
@ -362,6 +394,47 @@ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_inf
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_set_static_oob_value(const uint8_t *value, uint8_t length)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (value == NULL || length == 0 || length > 16) {
|
||||
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_PROVISIONER_SET_STATIC_OOB_VAL;
|
||||
|
||||
arg.set_static_oob_val.length = length;
|
||||
memcpy(arg.set_static_oob_val.value, value, length);
|
||||
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_provisioner_set_primary_elem_addr(uint16_t addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(addr)) {
|
||||
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_PROVISIONER_SET_PRIMARY_ELEM_ADDR;
|
||||
|
||||
arg.set_primary_elem_addr.addr = addr;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
/* The following APIs are for fast provisioning */
|
||||
|
@ -13,8 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
@ -34,4 +34,16 @@
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp);
|
||||
|
||||
/**
|
||||
* @brief De-initialize BLE Mesh module.
|
||||
*
|
||||
* @note This function shall be invoked after esp_ble_mesh_client_model_deinit().
|
||||
*
|
||||
* @param[in] param: Pointer to the structure of BLE Mesh deinit parameters.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param);
|
||||
|
||||
#endif /* _ESP_BLE_MESH_COMMON_API_H_ */
|
||||
|
@ -75,6 +75,18 @@ esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode);
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
|
||||
|
||||
/**
|
||||
* @brief De-initialize the user-defined client model.
|
||||
*
|
||||
* @note This function shall be invoked before esp_ble_mesh_deinit() is called.
|
||||
*
|
||||
* @param[in] model: Pointer of the Client model.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
|
||||
|
||||
/**
|
||||
* @brief Send server model messages(such as server model status messages).
|
||||
*
|
||||
@ -176,7 +188,7 @@ esp_err_t esp_ble_mesh_node_local_reset(void);
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name);
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(uint16_t index, const char *name);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the node (provisioned device) name.
|
||||
@ -188,20 +200,76 @@ esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name);
|
||||
* @return Node name on success, or NULL on failure.
|
||||
*
|
||||
*/
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(int index);
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(uint16_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the node (provisioned device) index.
|
||||
*
|
||||
* @param[in] name: Name of the node (end by '\0').
|
||||
*
|
||||
* @return Node index on success, or (negative) error code from errno.h on failure.
|
||||
* @return Node index on success, or an invalid value (0xFFFF) on failure.
|
||||
*
|
||||
*/
|
||||
int esp_ble_mesh_provisioner_get_node_index(const char *name);
|
||||
uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set the app key for the local BLE Mesh stack.
|
||||
* @brief This function is called to store the Composition Data of the node.
|
||||
*
|
||||
* @param[in] unicast_addr: Element address of the node
|
||||
* @param[in] data: Pointer of Composition Data
|
||||
* @param[in] length: Length of Composition Data
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr, uint8_t *data, uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the provisioned node information
|
||||
* with the node device uuid.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the node
|
||||
*
|
||||
* @return Pointer of the node info struct or NULL on failure.
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the provisioned node information
|
||||
* with the node unicast address.
|
||||
*
|
||||
* @param[in] unicast_addr: Unicast address of the node
|
||||
*
|
||||
* @return Pointer of the node info struct or NULL on failure.
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to delete the provisioned node information
|
||||
* with the node device uuid.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the node
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16]);
|
||||
|
||||
/**
|
||||
* @brief This function is called to delete the provisioned node information
|
||||
* with the node unicast address.
|
||||
*
|
||||
* @param[in] unicast_addr: Unicast address of the node
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_node_with_addr(uint16_t unicast_addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to add a local AppKey for Provisioner.
|
||||
*
|
||||
* @param[in] app_key: The app key to be set for the local BLE Mesh stack.
|
||||
* @param[in] net_idx: The network key index.
|
||||
@ -217,6 +285,19 @@ int esp_ble_mesh_provisioner_get_node_index(const char *name);
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], uint16_t net_idx, uint16_t app_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is used to update a local AppKey for Provisioner.
|
||||
*
|
||||
* @param[in] app_key: Value of the AppKey.
|
||||
* @param[in] net_idx: Corresponding NetKey Index.
|
||||
* @param[in] app_idx: The AppKey Index
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the local app key value.
|
||||
*
|
||||
@ -260,6 +341,17 @@ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to update a local network key.
|
||||
*
|
||||
* @param[in] net_key: Value of the NetKey.
|
||||
* @param[in] net_idx: The NetKey Index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the local network key value.
|
||||
*
|
||||
@ -270,6 +362,14 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
|
||||
*/
|
||||
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get provisioned node count.
|
||||
*
|
||||
* @return Number of the provisioned nodes.
|
||||
*
|
||||
*/
|
||||
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get fast provisioning application key.
|
||||
*
|
||||
|
@ -230,6 +230,32 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare
|
||||
esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t *add_dev,
|
||||
esp_ble_mesh_dev_add_flag_t flags);
|
||||
|
||||
/** @brief Provision an unprovisioned device and assign a fixed unicast address for it in advance.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the unprovisioned device
|
||||
* @param[in] addr: Device address of the unprovisioned device
|
||||
* @param[in] addr_type: Device address type of the unprovisioned device
|
||||
* @param[in] bearer: Provisioning bearer going to be used by Provisioner
|
||||
* @param[in] oob_info: OOB info of the unprovisioned device
|
||||
* @param[in] unicast_addr: Unicast address going to be allocated for the unprovisioned device
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*
|
||||
* @note: 1. Currently address type only supports public address and static random address.
|
||||
* 2. Bearer must be equal to ESP_BLE_MESH_PROV_ADV or ESP_BLE_MESH_PROV_GATT, since
|
||||
* Provisioner will start to provision a device immediately once this function is
|
||||
* invoked. And the input bearer must be identical with the one within the parameters
|
||||
* of the ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT event.
|
||||
* 3. If this function is used by a Provisioner to provision devices, the application
|
||||
* should take care of the assigned unicast address and avoid overlap of the unicast
|
||||
* addresses of different nodes.
|
||||
* 4. Recommend to use only one of the functions "esp_ble_mesh_provisioner_add_unprov_dev"
|
||||
* and "esp_ble_mesh_provisioner_prov_device_with_addr" by a Provisioner.
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16],
|
||||
esp_ble_mesh_bd_addr_t addr, esp_ble_mesh_addr_type_t addr_type,
|
||||
esp_ble_mesh_prov_bearer_t bearer, uint16_t oob_info, uint16_t unicast_addr);
|
||||
|
||||
/**
|
||||
* @brief Delete device from queue, reset current provisioning link and reset the node.
|
||||
*
|
||||
@ -290,6 +316,36 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val,
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_info_t *prov_data_info);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set static oob value used for provisioning.
|
||||
*
|
||||
* @param[in] value: Pointer to the static oob value.
|
||||
* @param[in] length: Length of the static oob value.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_static_oob_value(const uint8_t *value, uint8_t length);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set own Primary element address.
|
||||
*
|
||||
* @note This API must be invoked when BLE Mesh initialization is completed successfully,
|
||||
* and can be invoked before Provisioner functionality is enabled.
|
||||
* Once this API is invoked successfully, the prov_unicast_addr value in the struct
|
||||
* esp_ble_mesh_prov_t will be ignored, and Provisioner will use this address as its
|
||||
* own primary element address.
|
||||
* And if the unicast address going to assigned for the next unprovisioned device is
|
||||
* smaller than the input address + element number of Provisioner, then the address
|
||||
* for the next unprovisioned device will be recalculated internally.
|
||||
*
|
||||
* @param[in] addr: Unicast address of the Primary element of Provisioner.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_primary_elem_addr(uint16_t addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set provisioning data information before starting
|
||||
* fast provisioning.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
@ -34,13 +33,33 @@ esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_c
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
static bool config_client_get_need_param(esp_ble_mesh_opcode_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (!params || !params->model || !ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) ||
|
||||
(config_client_get_need_param(params->opcode) && !get_state)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -62,7 +81,8 @@ esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_
|
||||
btc_ble_mesh_config_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (!params || !params->model || !ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) ||
|
||||
(params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && !set_state)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
@ -27,13 +26,27 @@ esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_cli
|
||||
return (btc_profile_cb_set(BTC_PID_GENERIC_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
static bool generic_client_get_need_param(esp_ble_mesh_opcode_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_generic_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (!params || !params->model || !params->ctx.addr ||
|
||||
(generic_client_get_need_param(params->opcode) && !get_state)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
@ -40,7 +39,8 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_
|
||||
btc_ble_mesh_health_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (!params || !params->model || !params->ctx.addr || (!get_state &&
|
||||
params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
@ -33,7 +32,8 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t
|
||||
btc_ble_mesh_lighting_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (!params || !params->model || !params->ctx.addr || (!get_state &&
|
||||
params->opcode == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
@ -33,7 +32,8 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa
|
||||
btc_ble_mesh_time_scene_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (!params || !params->model || !params->ctx.addr || (!get_state &&
|
||||
params->opcode == ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,10 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "cfg_cli.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_common.h"
|
||||
#include "cfg_cli.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
@ -45,39 +44,53 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
btc_ble_mesh_config_client_args_t *src = (btc_ble_mesh_config_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
|
||||
dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
if (dst->cfg_client_get_state.params && dst->cfg_client_get_state.get_state) {
|
||||
dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->cfg_client_get_state.params) {
|
||||
memcpy(dst->cfg_client_get_state.params, src->cfg_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->cfg_client_get_state.get_state) {
|
||||
dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
if (dst->cfg_client_get_state.get_state) {
|
||||
memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
|
||||
dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
if (dst->cfg_client_set_state.params && dst->cfg_client_set_state.set_state) {
|
||||
dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->cfg_client_set_state.params) {
|
||||
memcpy(dst->cfg_client_set_state.params, src->cfg_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->cfg_client_set_state.set_state) {
|
||||
dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
if (dst->cfg_client_set_state.set_state) {
|
||||
memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -87,7 +100,7 @@ static void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_config_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -96,18 +109,18 @@ static void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE:
|
||||
if (arg->cfg_client_get_state.params) {
|
||||
osi_free(arg->cfg_client_get_state.params);
|
||||
bt_mesh_free(arg->cfg_client_get_state.params);
|
||||
}
|
||||
if (arg->cfg_client_get_state.get_state) {
|
||||
osi_free(arg->cfg_client_get_state.get_state);
|
||||
bt_mesh_free(arg->cfg_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE:
|
||||
if (arg->cfg_client_set_state.params) {
|
||||
osi_free(arg->cfg_client_set_state.params);
|
||||
bt_mesh_free(arg->cfg_client_set_state.params);
|
||||
}
|
||||
if (arg->cfg_client_set_state.set_state) {
|
||||
osi_free(arg->cfg_client_set_state.set_state);
|
||||
bt_mesh_free(arg->cfg_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -119,17 +132,17 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *p_dest_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_cfg_client_cb_param_t *p_src_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,7 +161,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.comp_data_status.composition_data->len;
|
||||
p_dest_data->status_cb.comp_data_status.composition_data = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.comp_data_status.composition_data) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.comp_data_status.composition_data,
|
||||
@ -164,7 +177,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.model_sub_list.sub_addr->len;
|
||||
p_dest_data->status_cb.model_sub_list.sub_addr = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.model_sub_list.sub_addr) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.model_sub_list.sub_addr,
|
||||
@ -178,7 +191,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.netkey_list.net_idx->len;
|
||||
p_dest_data->status_cb.netkey_list.net_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.netkey_list.net_idx) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.netkey_list.net_idx,
|
||||
@ -192,7 +205,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.appkey_list.app_idx->len;
|
||||
p_dest_data->status_cb.appkey_list.app_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.appkey_list.app_idx) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.appkey_list.app_idx,
|
||||
@ -208,7 +221,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.model_app_list.app_idx->len;
|
||||
p_dest_data->status_cb.model_app_list.app_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.model_app_list.app_idx) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.model_app_list.app_idx,
|
||||
@ -232,7 +245,7 @@ static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_cfg_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -274,7 +287,7 @@ static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -286,7 +299,7 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) {
|
||||
@ -308,11 +321,11 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -330,7 +343,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown config client event type %d", __func__, evt_type);
|
||||
BT_ERR("%s, Unknown config client event type %d", __func__, evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -361,7 +374,7 @@ void btc_ble_mesh_config_client_publish_callback(u32_t opcode,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -377,10 +390,30 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
if (get == NULL) {
|
||||
BT_ERR("%s, Invalid config client get", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = BLE_MESH_KEY_DEV;
|
||||
ctx.addr = params->ctx.addr;
|
||||
@ -439,7 +472,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx));
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
@ -452,8 +485,13 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !set || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
if (!params || !cb) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set == NULL) {
|
||||
BT_ERR("%s, Invalid config client set", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -592,7 +630,7 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit));
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
@ -606,7 +644,7 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -618,7 +656,7 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
|
||||
@ -634,7 +672,7 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
|
||||
@ -658,7 +696,7 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -667,7 +705,7 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_config_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_free_req_data(msg);
|
||||
@ -690,7 +728,7 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) {
|
||||
@ -710,11 +748,11 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -723,7 +761,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown config server event type %d", __func__, evt_type);
|
||||
BT_ERR("%s, Unknown config server event type %d", __func__, evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -749,7 +787,7 @@ void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -758,6 +796,6 @@ void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_config_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,9 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "generic_client.h"
|
||||
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
@ -38,30 +37,37 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t *dst = (btc_ble_mesh_generic_client_args_t *)p_dest;
|
||||
btc_ble_mesh_generic_client_args_t *src = (btc_ble_mesh_generic_client_args_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
|
||||
dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
if (dst->generic_client_get_state.params && dst->generic_client_get_state.get_state) {
|
||||
dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->generic_client_get_state.params) {
|
||||
memcpy(dst->generic_client_get_state.params, src->generic_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->generic_client_get_state.get_state) {
|
||||
dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
if (dst->generic_client_get_state.get_state) {
|
||||
memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
|
||||
dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
if (dst->generic_client_set_state.params && dst->generic_client_set_state.set_state) {
|
||||
memcpy(dst->generic_client_set_state.params, src->generic_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
@ -74,7 +80,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
length = src->generic_client_set_state.set_state->user_property_set.property_value->len;
|
||||
dst->generic_client_set_state.set_state->user_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!dst->generic_client_set_state.set_state->user_property_set.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->generic_client_set_state.set_state->user_property_set.property_value,
|
||||
@ -87,7 +93,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
length = src->generic_client_set_state.set_state->admin_property_set.property_value->len;
|
||||
dst->generic_client_set_state.set_state->admin_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!dst->generic_client_set_state.set_state->admin_property_set.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->generic_client_set_state.set_state->admin_property_set.property_value,
|
||||
@ -99,12 +105,12 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -114,7 +120,7 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -123,10 +129,10 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
|
||||
if (arg->generic_client_get_state.params) {
|
||||
osi_free(arg->generic_client_get_state.params);
|
||||
bt_mesh_free(arg->generic_client_get_state.params);
|
||||
}
|
||||
if (arg->generic_client_get_state.get_state) {
|
||||
osi_free(arg->generic_client_get_state.get_state);
|
||||
bt_mesh_free(arg->generic_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
|
||||
@ -143,10 +149,10 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->generic_client_set_state.set_state);
|
||||
bt_mesh_free(arg->generic_client_set_state.set_state);
|
||||
}
|
||||
if (arg->generic_client_set_state.params) {
|
||||
osi_free(arg->generic_client_set_state.params);
|
||||
bt_mesh_free(arg->generic_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -158,17 +164,17 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *p_dest_data = (esp_ble_mesh_generic_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_generic_client_cb_param_t *p_src_data = (esp_ble_mesh_generic_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -187,7 +193,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.user_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.user_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.user_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.user_properties_status.property_ids,
|
||||
@ -202,7 +208,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.user_property_status.property_value->len;
|
||||
p_dest_data->status_cb.user_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.user_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.user_property_status.property_value,
|
||||
@ -216,7 +222,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.admin_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.admin_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.admin_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.admin_properties_status.property_ids,
|
||||
@ -231,7 +237,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.admin_property_status.property_value->len;
|
||||
p_dest_data->status_cb.admin_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.admin_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.admin_property_status.property_value,
|
||||
@ -245,7 +251,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.manufacturer_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.manufacturer_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.manufacturer_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_properties_status.property_ids,
|
||||
@ -260,7 +266,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.manufacturer_property_status.property_value->len;
|
||||
p_dest_data->status_cb.manufacturer_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.manufacturer_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_property_status.property_value,
|
||||
@ -274,7 +280,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.client_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.client_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.client_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.client_properties_status.property_ids,
|
||||
@ -298,7 +304,7 @@ static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_generic_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -347,7 +353,7 @@ static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -359,7 +365,7 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) {
|
||||
@ -381,11 +387,11 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -403,7 +409,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown generic client event type %d", __func__, evt_type);
|
||||
BT_ERR("%s, Unknown generic client event type %d", __func__, evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -434,7 +440,7 @@ void btc_ble_mesh_generic_client_publish_callback(u32_t opcode,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -452,7 +458,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -464,7 +470,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -490,7 +496,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -524,7 +530,7 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_generic_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -533,7 +539,7 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_generic_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_free_req_data(msg);
|
||||
@ -557,10 +563,10 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
{
|
||||
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;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -573,7 +579,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -587,7 +593,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -607,7 +613,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -621,7 +627,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -643,7 +649,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -687,7 +693,7 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) {
|
||||
@ -708,11 +714,11 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -727,7 +733,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Generic Server event type", __func__);
|
||||
BT_ERR("%s, Unknown Generic Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -753,7 +759,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -762,7 +768,7 @@ void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_free_req_data(msg);
|
||||
|
@ -15,13 +15,10 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "btc/btc_task.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "foundation.h"
|
||||
#include "mesh_common.h"
|
||||
#include "health_srv.h"
|
||||
#include "health_cli.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
@ -46,39 +43,46 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
btc_ble_mesh_health_client_args_t *src = (btc_ble_mesh_health_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
|
||||
dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
if (dst->health_client_get_state.params && dst->health_client_get_state.get_state) {
|
||||
dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->health_client_get_state.params) {
|
||||
memcpy(dst->health_client_get_state.params, src->health_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->health_client_get_state.get_state) {
|
||||
dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
if (dst->health_client_get_state.get_state) {
|
||||
memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
|
||||
dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
if (dst->health_client_set_state.params && dst->health_client_set_state.set_state) {
|
||||
memcpy(dst->health_client_set_state.params, src->health_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->health_client_set_state.set_state, src->health_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -88,7 +92,7 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_health_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,18 +101,18 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE:
|
||||
if (arg->health_client_get_state.params) {
|
||||
osi_free(arg->health_client_get_state.params);
|
||||
bt_mesh_free(arg->health_client_get_state.params);
|
||||
}
|
||||
if (arg->health_client_get_state.get_state) {
|
||||
osi_free(arg->health_client_get_state.get_state);
|
||||
bt_mesh_free(arg->health_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE:
|
||||
if (arg->health_client_set_state.params) {
|
||||
osi_free(arg->health_client_set_state.params);
|
||||
bt_mesh_free(arg->health_client_set_state.params);
|
||||
}
|
||||
if (arg->health_client_set_state.set_state) {
|
||||
osi_free(arg->health_client_set_state.set_state);
|
||||
bt_mesh_free(arg->health_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -120,17 +124,17 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *p_dest_data = (esp_ble_mesh_health_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_health_client_cb_param_t *p_src_data = (esp_ble_mesh_health_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,7 +152,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.current_status.fault_array->len;
|
||||
p_dest_data->status_cb.current_status.fault_array = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.current_status.fault_array) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.current_status.fault_array,
|
||||
@ -164,7 +168,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.fault_status.fault_array->len;
|
||||
p_dest_data->status_cb.fault_status.fault_array = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.fault_status.fault_array) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.fault_status.fault_array,
|
||||
@ -188,7 +192,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_health_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -215,7 +219,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -227,7 +231,7 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) {
|
||||
@ -249,11 +253,11 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -271,7 +275,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown health client event type %d", __func__, evt_type);
|
||||
BT_ERR("%s, Unknown health client event type %d", __func__, evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -302,7 +306,7 @@ void btc_ble_mesh_health_publish_callback(u32_t opcode,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -318,7 +322,12 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET && get == NULL) {
|
||||
BT_ERR("%s, Invalid health client get", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -338,7 +347,7 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
return (cb->error_code = bt_mesh_health_fault_get(&ctx, get->fault_get.company_id));
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
@ -352,7 +361,7 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !set || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -390,7 +399,7 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false));
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
@ -404,7 +413,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -416,7 +425,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
|
||||
@ -432,7 +441,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
|
||||
@ -456,7 +465,7 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_health_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -465,7 +474,7 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_health_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_free_req_data(msg);
|
||||
@ -487,7 +496,7 @@ static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_serv
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -502,7 +511,7 @@ void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -517,7 +526,7 @@ static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
|
||||
static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -532,7 +541,7 @@ static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -548,7 +557,7 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) {
|
||||
@ -569,7 +578,7 @@ void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
|
||||
btc_ble_mesh_health_server_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -595,7 +604,7 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_health_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -604,7 +613,7 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_HEALTH_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_health_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_server_free_req_data(msg);
|
||||
|
@ -15,10 +15,9 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "lighting_client.h"
|
||||
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
@ -40,39 +39,46 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo
|
||||
btc_ble_mesh_lighting_client_args_t *src = (btc_ble_mesh_lighting_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
|
||||
dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
if (dst->light_client_get_state.params && dst->light_client_get_state.get_state) {
|
||||
dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->light_client_get_state.params) {
|
||||
memcpy(dst->light_client_get_state.params, src->light_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->light_client_get_state.get_state) {
|
||||
dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
if (dst->light_client_get_state.get_state) {
|
||||
memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
|
||||
dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
if (dst->light_client_set_state.params && dst->light_client_set_state.set_state) {
|
||||
memcpy(dst->light_client_set_state.params, src->light_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->light_client_set_state.set_state, src->light_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -82,7 +88,7 @@ static void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_lighting_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,18 +97,18 @@ static void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE:
|
||||
if (arg->light_client_get_state.params) {
|
||||
osi_free(arg->light_client_get_state.params);
|
||||
bt_mesh_free(arg->light_client_get_state.params);
|
||||
}
|
||||
if (arg->light_client_get_state.get_state) {
|
||||
osi_free(arg->light_client_get_state.get_state);
|
||||
bt_mesh_free(arg->light_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE:
|
||||
if (arg->light_client_set_state.params) {
|
||||
osi_free(arg->light_client_set_state.params);
|
||||
bt_mesh_free(arg->light_client_set_state.params);
|
||||
}
|
||||
if (arg->light_client_set_state.set_state) {
|
||||
osi_free(arg->light_client_set_state.set_state);
|
||||
bt_mesh_free(arg->light_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -114,17 +120,17 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *p_dest_data = (esp_ble_mesh_light_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_light_client_cb_param_t *p_src_data = (esp_ble_mesh_light_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -144,7 +150,7 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
length = p_src_data->status_cb.lc_property_status.property_value->len;
|
||||
p_dest_data->status_cb.lc_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.lc_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.lc_property_status.property_value,
|
||||
@ -168,7 +174,7 @@ static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_light_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -191,7 +197,7 @@ static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -203,7 +209,7 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) {
|
||||
@ -225,11 +231,11 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -247,7 +253,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown lighting client event type", __func__);
|
||||
BT_ERR("%s, Unknown lighting client event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -278,7 +284,7 @@ void btc_ble_mesh_lighting_client_publish_callback(u32_t opcode,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -296,7 +302,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -308,7 +314,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -334,7 +340,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -368,7 +374,7 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_light_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -377,7 +383,7 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_lighting_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_client_free_req_data(msg);
|
||||
@ -401,10 +407,10 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
{
|
||||
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;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -416,7 +422,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -432,7 +438,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -447,7 +453,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
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);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.status.sensor_status.data,
|
||||
@ -466,7 +472,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -499,7 +505,7 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) {
|
||||
@ -520,11 +526,11 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -542,7 +548,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Lighting Server event type", __func__);
|
||||
BT_ERR("%s, Unknown Lighting Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -568,7 +574,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -577,7 +583,7 @@ void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_free_req_data(msg);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,10 +15,9 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "sensor_client.h"
|
||||
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
@ -38,17 +37,17 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t *dst = (btc_ble_mesh_sensor_client_args_t *)p_dest;
|
||||
btc_ble_mesh_sensor_client_args_t *src = (btc_ble_mesh_sensor_client_args_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
|
||||
dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
if (dst->sensor_client_get_state.params && dst->sensor_client_get_state.get_state) {
|
||||
memcpy(dst->sensor_client_get_state.params, src->sensor_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
@ -61,7 +60,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_get_state.get_state->column_get.raw_value_x->len;
|
||||
dst->sensor_client_get_state.get_state->column_get.raw_value_x = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->column_get.raw_value_x) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->column_get.raw_value_x,
|
||||
@ -74,7 +73,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_get_state.get_state->series_get.raw_value_x1->len;
|
||||
dst->sensor_client_get_state.get_state->series_get.raw_value_x1 = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x1) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x1,
|
||||
@ -85,7 +84,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_get_state.get_state->series_get.raw_value_x2->len;
|
||||
dst->sensor_client_get_state.get_state->series_get.raw_value_x2 = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x2) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x2,
|
||||
@ -97,13 +96,13 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
|
||||
dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
if (dst->sensor_client_set_state.params && dst->sensor_client_set_state.set_state) {
|
||||
memcpy(dst->sensor_client_set_state.params, src->sensor_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
@ -116,7 +115,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down,
|
||||
@ -127,7 +126,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up,
|
||||
@ -138,7 +137,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low,
|
||||
@ -149,7 +148,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high,
|
||||
@ -162,7 +161,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw->len;
|
||||
dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw,
|
||||
@ -174,12 +173,12 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -189,7 +188,7 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -211,10 +210,10 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_get_state.get_state);
|
||||
bt_mesh_free(arg->sensor_client_get_state.get_state);
|
||||
}
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
osi_free(arg->sensor_client_get_state.params);
|
||||
bt_mesh_free(arg->sensor_client_get_state.params);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
|
||||
@ -234,10 +233,10 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_set_state.set_state);
|
||||
bt_mesh_free(arg->sensor_client_set_state.set_state);
|
||||
}
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
osi_free(arg->sensor_client_set_state.params);
|
||||
bt_mesh_free(arg->sensor_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -249,17 +248,17 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_sensor_client_cb_param_t *p_src_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -278,7 +277,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.descriptor_status.descriptor->len;
|
||||
p_dest_data->status_cb.descriptor_status.descriptor = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.descriptor_status.descriptor) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.descriptor_status.descriptor,
|
||||
@ -293,7 +292,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.cadence_status.sensor_cadence_value->len;
|
||||
p_dest_data->status_cb.cadence_status.sensor_cadence_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.cadence_status.sensor_cadence_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.cadence_status.sensor_cadence_value,
|
||||
@ -307,7 +306,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.settings_status.sensor_setting_property_ids->len;
|
||||
p_dest_data->status_cb.settings_status.sensor_setting_property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.settings_status.sensor_setting_property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.settings_status.sensor_setting_property_ids,
|
||||
@ -322,7 +321,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.setting_status.sensor_setting_raw->len;
|
||||
p_dest_data->status_cb.setting_status.sensor_setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.setting_status.sensor_setting_raw) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.setting_status.sensor_setting_raw,
|
||||
@ -336,7 +335,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.sensor_status.marshalled_sensor_data->len;
|
||||
p_dest_data->status_cb.sensor_status.marshalled_sensor_data = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.sensor_status.marshalled_sensor_data) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.sensor_status.marshalled_sensor_data,
|
||||
@ -350,7 +349,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.column_status.sensor_column_value->len;
|
||||
p_dest_data->status_cb.column_status.sensor_column_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.column_status.sensor_column_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.column_status.sensor_column_value,
|
||||
@ -364,7 +363,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.series_status.sensor_series_value->len;
|
||||
p_dest_data->status_cb.series_status.sensor_series_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.series_status.sensor_series_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.series_status.sensor_series_value,
|
||||
@ -388,7 +387,7 @@ static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_sensor_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -436,7 +435,7 @@ static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -448,7 +447,7 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) {
|
||||
@ -470,11 +469,11 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -492,7 +491,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown sensor client event type %d", __func__, evt_type);
|
||||
BT_ERR("%s, Unknown sensor client event type %d", __func__, evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -523,7 +522,7 @@ void btc_ble_mesh_sensor_client_publish_callback(u32_t opcode,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -541,7 +540,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -553,7 +552,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -579,7 +578,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -613,7 +612,7 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -622,7 +621,7 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_sensor_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_free_req_data(msg);
|
||||
@ -646,10 +645,10 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
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;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -661,7 +660,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -672,7 +671,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -683,7 +682,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -694,7 +693,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -707,7 +706,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -722,7 +721,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -734,7 +733,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -750,7 +749,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_cadence.cadence,
|
||||
@ -763,7 +762,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%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,
|
||||
@ -782,7 +781,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -826,7 +825,7 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) {
|
||||
@ -847,11 +846,11 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -866,7 +865,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Sensor Server event type", __func__);
|
||||
BT_ERR("%s, Unknown Sensor Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -892,7 +891,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -901,7 +900,7 @@ void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_free_req_data(msg);
|
||||
|
@ -15,10 +15,9 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "time_scene_client.h"
|
||||
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
@ -40,39 +39,46 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest,
|
||||
btc_ble_mesh_time_scene_client_args_t *src = (btc_ble_mesh_time_scene_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
|
||||
dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
if (dst->time_scene_client_get_state.params && dst->time_scene_client_get_state.get_state) {
|
||||
dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->time_scene_client_get_state.params) {
|
||||
memcpy(dst->time_scene_client_get_state.params, src->time_scene_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->time_scene_client_get_state.get_state) {
|
||||
dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
if (dst->time_scene_client_get_state.get_state) {
|
||||
memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
|
||||
dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
if (dst->time_scene_client_set_state.params && dst->time_scene_client_set_state.set_state) {
|
||||
memcpy(dst->time_scene_client_set_state.params, src->time_scene_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->time_scene_client_set_state.set_state, src->time_scene_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -82,7 +88,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,18 +97,18 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE:
|
||||
if (arg->time_scene_client_get_state.params) {
|
||||
osi_free(arg->time_scene_client_get_state.params);
|
||||
bt_mesh_free(arg->time_scene_client_get_state.params);
|
||||
}
|
||||
if (arg->time_scene_client_get_state.get_state) {
|
||||
osi_free(arg->time_scene_client_get_state.get_state);
|
||||
bt_mesh_free(arg->time_scene_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE:
|
||||
if (arg->time_scene_client_set_state.params) {
|
||||
osi_free(arg->time_scene_client_set_state.params);
|
||||
bt_mesh_free(arg->time_scene_client_set_state.params);
|
||||
}
|
||||
if (arg->time_scene_client_set_state.set_state) {
|
||||
osi_free(arg->time_scene_client_set_state.set_state);
|
||||
bt_mesh_free(arg->time_scene_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -114,17 +120,17 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_dest_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_src_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
u16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,7 +151,7 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p
|
||||
length = p_src_data->status_cb.scene_register_status.scenes->len;
|
||||
p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.scene_register_status.scenes) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
|
||||
@ -169,7 +175,7 @@ static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -193,7 +199,7 @@ static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -205,7 +211,7 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) {
|
||||
@ -227,11 +233,11 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -249,7 +255,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown time scene client event type %d", __func__, evt_type);
|
||||
BT_ERR("%s, Unknown time scene client event type %d", __func__, evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -280,7 +286,7 @@ void btc_ble_mesh_time_scene_client_publish_callback(u32_t opcode,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -298,7 +304,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -310,7 +316,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -336,7 +342,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
BT_ERR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
@ -370,7 +376,7 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -379,7 +385,7 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_time_scene_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_free_req_data(msg);
|
||||
@ -403,7 +409,7 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) {
|
||||
@ -424,11 +430,11 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
|
||||
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;
|
||||
size_t length = 0U;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -446,7 +452,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Time Scene Server event type", __func__);
|
||||
BT_ERR("%s, Unknown Time Scene Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -472,7 +478,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -481,7 +487,7 @@ void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -15,8 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_CONFIG_MODEL_H_
|
||||
#define _BTC_BLE_MESH_CONFIG_MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -15,8 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_GENERIC_MODEL_H_
|
||||
#define _BTC_BLE_MESH_GENERIC_MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -15,8 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_HEALTH_MODEL_H_
|
||||
#define _BTC_BLE_MESH_HEALTH_MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -15,8 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_LIGHTING_MODEL_H_
|
||||
#define _BTC_BLE_MESH_LIGHTING_MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -15,15 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_PROV_H_
|
||||
#define _BTC_BLE_MESH_PROV_H_
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "mesh_main.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
@ -46,13 +38,21 @@ typedef enum {
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ENABLE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DISABLE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DEV_ADD,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_PROV_DEV_WITH_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DEV_DEL,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_DEV_UUID_MATCH,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_PROV_DATA_INFO,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_STATIC_OOB_VAL,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_PRIMARY_ELEM_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_NODE_NAME,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_LOCAL_APP_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_APP_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_BIND_LOCAL_MOD_APP,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_UUID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_ADDR,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
|
||||
BTC_BLE_MESH_ACT_LPN_ENABLE,
|
||||
@ -121,6 +121,14 @@ typedef union {
|
||||
esp_ble_mesh_unprov_dev_add_t add_dev;
|
||||
esp_ble_mesh_dev_add_flag_t flags;
|
||||
} provisioner_dev_add;
|
||||
struct ble_mesh_provisioner_prov_dev_with_addr_args {
|
||||
uint8_t uuid[16];
|
||||
esp_ble_mesh_bd_addr_t addr;
|
||||
esp_ble_mesh_addr_type_t addr_type;
|
||||
esp_ble_mesh_prov_bearer_t bearer;
|
||||
uint16_t oob_info;
|
||||
uint16_t unicast_addr;
|
||||
} provisioner_prov_dev_with_addr;
|
||||
struct ble_mesh_provisioner_dev_del_args {
|
||||
esp_ble_mesh_device_delete_t del_dev;
|
||||
} provisioner_dev_del;
|
||||
@ -133,8 +141,15 @@ typedef union {
|
||||
struct ble_mesh_provisioner_set_prov_net_idx_args {
|
||||
esp_ble_mesh_prov_data_info_t prov_data;
|
||||
} set_prov_data_info;
|
||||
struct ble_mesh_provisioner_set_static_oob_val_args {
|
||||
uint8_t value[16];
|
||||
uint8_t length;
|
||||
} set_static_oob_val;
|
||||
struct ble_mesh_provisioner_set_primary_elem_addr_args {
|
||||
uint16_t addr;
|
||||
} set_primary_elem_addr;
|
||||
struct ble_mesh_provisioner_set_node_name_args {
|
||||
int index;
|
||||
uint16_t index;
|
||||
char name[ESP_BLE_MESH_NODE_NAME_MAX_LEN];
|
||||
} set_node_name;
|
||||
struct ble_mesh_provisioner_add_local_app_key_args {
|
||||
@ -142,6 +157,11 @@ typedef union {
|
||||
uint16_t net_idx;
|
||||
uint16_t app_idx;
|
||||
} add_local_app_key;
|
||||
struct ble_mesh_provisioner_update_local_app_key_args {
|
||||
uint8_t app_key[16];
|
||||
uint16_t net_idx;
|
||||
uint16_t app_idx;
|
||||
} update_local_app_key;
|
||||
struct ble_mesh_provisioner_bind_local_mod_app_args {
|
||||
uint16_t elem_addr;
|
||||
uint16_t model_id;
|
||||
@ -152,6 +172,21 @@ typedef union {
|
||||
uint8_t net_key[16];
|
||||
uint16_t net_idx;
|
||||
} add_local_net_key;
|
||||
struct ble_mesh_provisioner_update_local_net_key_args {
|
||||
uint8_t net_key[16];
|
||||
uint16_t net_idx;
|
||||
} update_local_net_key;
|
||||
struct ble_mesh_provisioner_store_node_comp_data_args {
|
||||
uint16_t unicast_addr;
|
||||
uint16_t length;
|
||||
uint8_t *data;
|
||||
} store_node_comp_data;
|
||||
struct ble_mesh_provisioner_delete_node_with_uuid_args {
|
||||
uint8_t uuid[16];
|
||||
} delete_node_with_uuid;
|
||||
struct ble_mesh_provisioner_delete_node_with_addr_args {
|
||||
uint16_t unicast_addr;
|
||||
} delete_node_with_addr;
|
||||
struct ble_mesh_set_fast_prov_info_args {
|
||||
uint16_t unicast_min;
|
||||
uint16_t unicast_max;
|
||||
@ -227,8 +262,16 @@ 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);
|
||||
|
||||
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
|
||||
|
||||
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
|
||||
|
||||
int btc_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param);
|
||||
|
||||
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
|
||||
|
||||
int btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
|
||||
|
||||
int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod);
|
||||
|
||||
uint16_t btc_ble_mesh_get_primary_addr(void);
|
||||
@ -247,6 +290,8 @@ esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem,
|
||||
|
||||
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
|
||||
|
||||
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
|
||||
|
||||
|
@ -15,8 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_SENSOR_MODEL_H_
|
||||
#define _BTC_BLE_MESH_SENSOR_MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -15,8 +15,7 @@
|
||||
#ifndef _BTC_BLE_MESH_TIME_SCENE_MODEL_H_
|
||||
#define _BTC_BLE_MESH_TIME_SCENE_MODEL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
|
@ -11,12 +11,7 @@
|
||||
#ifndef _BLE_MESH_BUF_H_
|
||||
#define _BLE_MESH_BUF_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "sys/cdefs.h"
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_slist.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -16,16 +16,30 @@
|
||||
* @brief Bluetooth Mesh Model Common APIs.
|
||||
*/
|
||||
|
||||
#ifndef _MESH_COMMON_H_
|
||||
#define _MESH_COMMON_H_
|
||||
#ifndef _BLE_MESH_COMMON_H_
|
||||
#define _BLE_MESH_COMMON_H_
|
||||
|
||||
#include "osi/allocator.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_access.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST
|
||||
#define bt_mesh_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#define bt_mesh_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#else
|
||||
#define bt_mesh_malloc(size) malloc((size))
|
||||
#define bt_mesh_calloc(size) calloc(1, (size))
|
||||
#endif /* CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST */
|
||||
#define bt_mesh_free(p) free((p))
|
||||
|
||||
/**
|
||||
* @brief This function allocates memory to store outgoing message.
|
||||
*
|
||||
@ -58,4 +72,19 @@ void bt_mesh_free_buf(struct net_buf_simple *buf);
|
||||
*/
|
||||
u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send);
|
||||
|
||||
#endif /* _MESH_COMMON_H_ */
|
||||
typedef struct {
|
||||
SemaphoreHandle_t mutex;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
StaticQueue_t *buffer;
|
||||
#endif
|
||||
} bt_mesh_mutex_t;
|
||||
|
||||
void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex);
|
||||
|
||||
void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex);
|
||||
|
||||
void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex);
|
||||
|
||||
void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex);
|
||||
|
||||
#endif /* _BLE_MESH_COMMON_H_ */
|
@ -8,11 +8,9 @@
|
||||
#ifndef _BLE_MESH_KERNEL_H_
|
||||
#define _BLE_MESH_KERNEL_H_
|
||||
|
||||
#include "osi/mutex.h"
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_slist.h"
|
||||
#include "mesh_atomic.h"
|
||||
#include "mesh_dlist.h"
|
||||
|
||||
/* number of nsec per usec */
|
||||
#define NSEC_PER_USEC 1000
|
||||
@ -47,8 +45,6 @@ struct k_work;
|
||||
*/
|
||||
typedef void (*k_work_handler_t)(struct k_work *work);
|
||||
|
||||
typedef sys_dlist_t _wait_q_t;
|
||||
|
||||
struct k_work {
|
||||
void *_reserved;
|
||||
k_work_handler_t handler;
|
||||
@ -278,6 +274,7 @@ void bt_mesh_atomic_lock(void);
|
||||
void bt_mesh_atomic_unlock(void);
|
||||
|
||||
void bt_mesh_k_init(void);
|
||||
void bt_mesh_k_deinit(void);
|
||||
|
||||
#endif /* _BLE_MESH_KERNEL_H_ */
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define _BLE_MESH_TRACE_H_
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* Define common tracing for all */
|
||||
#ifndef LOG_LEVEL_ERROR
|
||||
@ -47,12 +46,6 @@
|
||||
|
||||
#define MESH_TRACE_TAG "BLE_MESH"
|
||||
|
||||
#define LOG_ERROR(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) esp_log_write(ESP_LOG_ERROR, "BT_LOG", LOG_FORMAT(E, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_WARN(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) esp_log_write(ESP_LOG_WARN, "BT_LOG", LOG_FORMAT(W, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_INFO(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) esp_log_write(ESP_LOG_INFO, "BT_LOG", LOG_FORMAT(I, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_DEBUG(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) esp_log_write(ESP_LOG_DEBUG, "BT_LOG", LOG_FORMAT(D, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_VERBOSE(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) esp_log_write(ESP_LOG_VERBOSE, "BT_LOG", LOG_FORMAT(V, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
|
||||
#if (LOG_LOCAL_LEVEL >= 4)
|
||||
#define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL + 1)
|
||||
#else
|
||||
|
@ -15,9 +15,9 @@
|
||||
#define _BLE_MESH_UTIL_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "soc/soc.h"
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "soc/soc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -30,9 +30,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "mesh_aes_encrypt.h"
|
||||
#include "mesh_util.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
|
||||
/* max number of calls until change the key (2^48).*/
|
||||
const static uint64_t MAX_CALLS = ((uint64_t)1 << 48);
|
||||
@ -162,7 +161,7 @@ static inline void mult_row_column(uint8_t *out, const uint8_t *in)
|
||||
|
||||
static inline void mix_columns(uint8_t *s)
|
||||
{
|
||||
uint8_t t[Nb * Nk];
|
||||
uint8_t t[Nb * Nk] = {0};
|
||||
|
||||
mult_row_column(t, s);
|
||||
mult_row_column(&t[Nb], s + Nb);
|
||||
@ -177,7 +176,7 @@ static inline void mix_columns(uint8_t *s)
|
||||
*/
|
||||
static inline void shift_rows(uint8_t *s)
|
||||
{
|
||||
uint8_t t[Nb * Nk];
|
||||
uint8_t t[Nb * Nk] = {0};
|
||||
|
||||
t[0] = s[0]; t[1] = s[5]; t[2] = s[10]; t[3] = s[15];
|
||||
t[4] = s[4]; t[5] = s[9]; t[6] = s[14]; t[7] = s[3];
|
||||
@ -188,7 +187,7 @@ static inline void shift_rows(uint8_t *s)
|
||||
|
||||
int tc_aes_encrypt(uint8_t *out, const uint8_t *in, const TCAesKeySched_t s)
|
||||
{
|
||||
uint8_t state[Nk * Nb];
|
||||
uint8_t state[Nk * Nb] = {0};
|
||||
unsigned int i;
|
||||
|
||||
if (out == (uint8_t *) 0) {
|
||||
@ -364,7 +363,7 @@ int tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t data_length)
|
||||
|
||||
int tc_cmac_final(uint8_t *tag, TCCmacState_t s)
|
||||
{
|
||||
uint8_t *k;
|
||||
uint8_t *k = NULL;
|
||||
unsigned int i;
|
||||
|
||||
/* input sanity check: */
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "mesh_atomic.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifndef CONFIG_ATOMIC_OPERATIONS_BUILTIN
|
||||
|
||||
@ -55,7 +54,7 @@ bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target)
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
|
||||
{
|
||||
bt_mesh_atomic_val_t ret;
|
||||
bt_mesh_atomic_val_t ret = 0;
|
||||
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
@ -82,7 +81,7 @@ bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
|
||||
{
|
||||
bt_mesh_atomic_val_t ret;
|
||||
bt_mesh_atomic_val_t ret = 0;
|
||||
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
@ -109,7 +108,7 @@ bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
|
||||
{
|
||||
bt_mesh_atomic_val_t ret;
|
||||
bt_mesh_atomic_val_t ret = 0;
|
||||
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
@ -134,7 +133,7 @@ bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target)
|
||||
{
|
||||
bt_mesh_atomic_val_t ret;
|
||||
bt_mesh_atomic_val_t ret = 0;
|
||||
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
@ -159,7 +158,7 @@ bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target)
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target)
|
||||
{
|
||||
bt_mesh_atomic_val_t ret;
|
||||
bt_mesh_atomic_val_t ret = 0;
|
||||
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
|
@ -7,10 +7,9 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
int net_buf_id(struct net_buf *buf)
|
||||
{
|
||||
@ -22,7 +21,7 @@ int net_buf_id(struct net_buf *buf)
|
||||
static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool,
|
||||
u16_t uninit_count)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
buf = &pool->__bufs[pool->buf_count - uninit_count];
|
||||
|
||||
@ -59,7 +58,7 @@ void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
|
||||
|
||||
u8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, u8_t val)
|
||||
{
|
||||
u8_t *u8;
|
||||
u8_t *u8 = NULL;
|
||||
|
||||
NET_BUF_SIMPLE_DBG("buf %p val 0x%02x", buf, val);
|
||||
|
||||
@ -161,7 +160,7 @@ void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len)
|
||||
|
||||
u8_t net_buf_simple_pull_u8(struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t val;
|
||||
u8_t val = 0U;
|
||||
|
||||
val = buf->data[0];
|
||||
net_buf_simple_pull(buf, 1);
|
||||
@ -171,7 +170,7 @@ u8_t net_buf_simple_pull_u8(struct net_buf_simple *buf)
|
||||
|
||||
u16_t net_buf_simple_pull_le16(struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t val;
|
||||
u16_t val = 0U;
|
||||
|
||||
val = UNALIGNED_GET((u16_t *)buf->data);
|
||||
net_buf_simple_pull(buf, sizeof(val));
|
||||
@ -181,7 +180,7 @@ u16_t net_buf_simple_pull_le16(struct net_buf_simple *buf)
|
||||
|
||||
u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t val;
|
||||
u16_t val = 0U;
|
||||
|
||||
val = UNALIGNED_GET((u16_t *)buf->data);
|
||||
net_buf_simple_pull(buf, sizeof(val));
|
||||
@ -191,7 +190,7 @@ u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf)
|
||||
|
||||
u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
|
||||
{
|
||||
u32_t val;
|
||||
u32_t val = 0U;
|
||||
|
||||
val = UNALIGNED_GET((u32_t *)buf->data);
|
||||
net_buf_simple_pull(buf, sizeof(val));
|
||||
@ -201,7 +200,7 @@ u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
|
||||
|
||||
u32_t net_buf_simple_pull_be32(struct net_buf_simple *buf)
|
||||
{
|
||||
u32_t val;
|
||||
u32_t val = 0U;
|
||||
|
||||
val = UNALIGNED_GET((u32_t *)buf->data);
|
||||
net_buf_simple_pull(buf, sizeof(val));
|
||||
@ -238,7 +237,7 @@ void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve)
|
||||
|
||||
void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf)
|
||||
{
|
||||
struct net_buf *tail;
|
||||
struct net_buf *tail = NULL;
|
||||
|
||||
NET_BUF_ASSERT(list);
|
||||
NET_BUF_ASSERT(buf);
|
||||
@ -254,7 +253,7 @@ void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf)
|
||||
|
||||
struct net_buf *net_buf_slist_get(sys_slist_t *list)
|
||||
{
|
||||
struct net_buf *buf, *frag;
|
||||
struct net_buf *buf = NULL, *frag = NULL;
|
||||
|
||||
NET_BUF_ASSERT(list);
|
||||
|
||||
@ -304,7 +303,7 @@ void net_buf_unref(struct net_buf *buf)
|
||||
|
||||
while (buf) {
|
||||
struct net_buf *frags = buf->frags;
|
||||
struct net_buf_pool *pool;
|
||||
struct net_buf_pool *pool = NULL;
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
|
||||
if (!buf->ref) {
|
||||
@ -499,7 +498,7 @@ struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
|
||||
struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
|
||||
#endif
|
||||
{
|
||||
struct net_buf *next_frag;
|
||||
struct net_buf *next_frag = NULL;
|
||||
|
||||
NET_BUF_ASSERT(frag);
|
||||
|
||||
@ -525,9 +524,9 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
|
||||
size_t net_buf_linearize(void *dst, size_t dst_len, struct net_buf *src,
|
||||
size_t offset, size_t len)
|
||||
{
|
||||
struct net_buf *frag;
|
||||
size_t to_copy;
|
||||
size_t copied;
|
||||
struct net_buf *frag = NULL;
|
||||
size_t to_copy = 0U;
|
||||
size_t copied = 0U;
|
||||
|
||||
len = MIN(len, dst_len);
|
||||
|
||||
@ -567,7 +566,7 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
|
||||
net_buf_allocator_cb allocate_cb, void *user_data)
|
||||
{
|
||||
struct net_buf *frag = net_buf_frag_last(buf);
|
||||
size_t added_len = 0;
|
||||
size_t added_len = 0U;
|
||||
const u8_t *value8 = value;
|
||||
|
||||
do {
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mesh_main.h"
|
||||
#include "client_common.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
@ -23,7 +24,7 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size)
|
||||
struct net_buf_simple *buf = NULL;
|
||||
u8_t *data = NULL;
|
||||
|
||||
buf = (struct net_buf_simple *)osi_calloc(sizeof(struct net_buf_simple) + size);
|
||||
buf = (struct net_buf_simple *)bt_mesh_calloc(sizeof(struct net_buf_simple) + size);
|
||||
if (!buf) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return NULL;
|
||||
@ -42,7 +43,7 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size)
|
||||
void bt_mesh_free_buf(struct net_buf_simple *buf)
|
||||
{
|
||||
if (buf) {
|
||||
osi_free(buf);
|
||||
bt_mesh_free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,3 +65,62 @@ u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send)
|
||||
|
||||
return client->msg_role;
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
mutex->buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
__ASSERT(mutex->buffer, "%s, Failed to create queue buffer", __func__);
|
||||
mutex->mutex = xSemaphoreCreateMutexStatic(mutex->buffer);
|
||||
__ASSERT(mutex->mutex, "%s, Failed to create static mutex", __func__);
|
||||
#else
|
||||
mutex->mutex = xSemaphoreCreateMutex();
|
||||
__ASSERT(mutex->mutex, "%s, Failed to create mutex", __func__);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutex->mutex) {
|
||||
vSemaphoreDelete(mutex->mutex);
|
||||
mutex->mutex = NULL;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
heap_caps_free(mutex->buffer);
|
||||
mutex->buffer = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutex->mutex) {
|
||||
xSemaphoreTake(mutex->mutex, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex)
|
||||
{
|
||||
if (!mutex) {
|
||||
BT_ERR("%s, Invalid mutex", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mutex->mutex) {
|
||||
xSemaphoreGive(mutex->mutex);
|
||||
}
|
||||
}
|
||||
|
@ -8,25 +8,17 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "osi/hash_map.h"
|
||||
#include "osi/alarm.h"
|
||||
#include "osi/hash_functions.h"
|
||||
|
||||
#include "bt_common.h"
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_trace.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "provisioner_prov.h"
|
||||
|
||||
static osi_mutex_t bm_alarm_lock;
|
||||
static osi_mutex_t bm_list_lock;
|
||||
static osi_mutex_t bm_buf_lock;
|
||||
static osi_mutex_t bm_atomic_lock;
|
||||
static bt_mesh_mutex_t bm_alarm_lock;
|
||||
static bt_mesh_mutex_t bm_list_lock;
|
||||
static bt_mesh_mutex_t bm_buf_lock;
|
||||
static bt_mesh_mutex_t bm_atomic_lock;
|
||||
static hash_map_t *bm_alarm_hash_map;
|
||||
static const size_t BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BLE_MESH_PBA_SAME_TIME + \
|
||||
CONFIG_BLE_MESH_PBG_SAME_TIME;
|
||||
@ -39,34 +31,92 @@ typedef struct alarm_t {
|
||||
int64_t deadline_us;
|
||||
} osi_alarm_t;
|
||||
|
||||
static void bt_mesh_alarm_mutex_new(void)
|
||||
{
|
||||
if (!bm_alarm_lock.mutex) {
|
||||
bt_mesh_mutex_create(&bm_alarm_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_alarm_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&bm_alarm_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_alarm_lock(void)
|
||||
{
|
||||
bt_mesh_mutex_lock(&bm_alarm_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_alarm_unlock(void)
|
||||
{
|
||||
bt_mesh_mutex_unlock(&bm_alarm_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_list_mutex_new(void)
|
||||
{
|
||||
if (!bm_list_lock.mutex) {
|
||||
bt_mesh_mutex_create(&bm_list_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_list_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&bm_list_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_list_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&bm_list_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&bm_list_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_list_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&bm_list_lock);
|
||||
bt_mesh_mutex_unlock(&bm_list_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_buf_mutex_new(void)
|
||||
{
|
||||
if (!bm_buf_lock.mutex) {
|
||||
bt_mesh_mutex_create(&bm_buf_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_buf_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&bm_buf_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_buf_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&bm_buf_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&bm_buf_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_buf_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&bm_buf_lock);
|
||||
bt_mesh_mutex_unlock(&bm_buf_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_atomic_mutex_new(void)
|
||||
{
|
||||
if (!bm_atomic_lock.mutex) {
|
||||
bt_mesh_mutex_create(&bm_atomic_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_atomic_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&bm_atomic_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_atomic_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&bm_atomic_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&bm_atomic_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_atomic_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&bm_atomic_lock);
|
||||
bt_mesh_mutex_unlock(&bm_atomic_lock);
|
||||
}
|
||||
|
||||
s64_t k_uptime_get(void)
|
||||
@ -93,37 +143,52 @@ void k_sleep(s32_t duration)
|
||||
|
||||
void bt_mesh_k_init(void)
|
||||
{
|
||||
osi_mutex_new(&bm_alarm_lock);
|
||||
osi_mutex_new(&bm_list_lock);
|
||||
osi_mutex_new(&bm_buf_lock);
|
||||
osi_mutex_new(&bm_atomic_lock);
|
||||
bt_mesh_alarm_mutex_new();
|
||||
bt_mesh_list_mutex_new();
|
||||
bt_mesh_buf_mutex_new();
|
||||
bt_mesh_atomic_mutex_new();
|
||||
bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE,
|
||||
hash_function_pointer, NULL,
|
||||
(data_free_fn)osi_alarm_free, NULL);
|
||||
assert(bm_alarm_hash_map != NULL);
|
||||
__ASSERT(bm_alarm_hash_map, "%s, Failed to create hash map", __func__);
|
||||
}
|
||||
|
||||
void bt_mesh_k_deinit(void)
|
||||
{
|
||||
bt_mesh_alarm_mutex_free();
|
||||
bt_mesh_list_mutex_free();
|
||||
bt_mesh_buf_mutex_free();
|
||||
bt_mesh_atomic_mutex_free();
|
||||
if (bm_alarm_hash_map) {
|
||||
hash_map_free(bm_alarm_hash_map);
|
||||
bm_alarm_hash_map = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
|
||||
{
|
||||
osi_alarm_t *alarm = NULL;
|
||||
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
if (!work || !bm_alarm_hash_map) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
k_work_init(&work->work, handler);
|
||||
|
||||
osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_alarm_lock();
|
||||
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
|
||||
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
|
||||
if (alarm == NULL) {
|
||||
BT_ERR("%s, Unable to create alarm", __func__);
|
||||
osi_mutex_unlock(&bm_alarm_lock);
|
||||
bt_mesh_alarm_unlock();
|
||||
return;
|
||||
}
|
||||
if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) {
|
||||
BT_ERR("%s Unable to add the timer to hash map.", __func__);
|
||||
}
|
||||
}
|
||||
osi_mutex_unlock(&bm_alarm_lock);
|
||||
bt_mesh_alarm_unlock();
|
||||
|
||||
alarm = hash_map_get(bm_alarm_hash_map, work);
|
||||
if (alarm == NULL) {
|
||||
@ -138,7 +203,10 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
|
||||
|
||||
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
if (!work || !bm_alarm_hash_map) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
|
||||
if (alarm == NULL) {
|
||||
@ -154,7 +222,10 @@ 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)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
if (!work || !bm_alarm_hash_map) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
|
||||
if (alarm == NULL) {
|
||||
@ -171,7 +242,10 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period)
|
||||
|
||||
int k_delayed_work_cancel(struct k_delayed_work *work)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
if (!work || !bm_alarm_hash_map) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
|
||||
if (alarm == NULL) {
|
||||
@ -186,7 +260,10 @@ int k_delayed_work_cancel(struct k_delayed_work *work)
|
||||
|
||||
int k_delayed_work_free(struct k_delayed_work *work)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
if (!work || !bm_alarm_hash_map) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work);
|
||||
if (alarm == NULL) {
|
||||
@ -201,7 +278,10 @@ int k_delayed_work_free(struct k_delayed_work *work)
|
||||
|
||||
s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
if (!work || !bm_alarm_hash_map) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
|
||||
if (alarm == NULL) {
|
||||
|
@ -7,9 +7,9 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
|
||||
#define MASK_TWENTY_SEVEN 0x1b
|
||||
|
@ -10,23 +10,14 @@
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_ACCESS)
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_main.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "adv.h"
|
||||
#include "net.h"
|
||||
#include "lpn.h"
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_common.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
@ -49,64 +40,64 @@ static const struct {
|
||||
const u16_t id;
|
||||
int (*const init)(struct bt_mesh_model *model, bool primary);
|
||||
} model_init[] = {
|
||||
{ BLE_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_init },
|
||||
#if defined(CONFIG_BLE_MESH_CFG_CLI)
|
||||
{ BLE_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_HEALTH_CLI)
|
||||
{ BLE_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, bt_mesh_gen_onoff_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, bt_mesh_gen_onoff_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_LEVEL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, bt_mesh_gen_level_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, bt_mesh_gen_level_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, bt_mesh_gen_def_trans_time_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, bt_mesh_gen_def_trans_time_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_POWER_ONOFF_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, bt_mesh_gen_pwr_onoff_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, bt_mesh_gen_pwr_onoff_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_POWER_LEVEL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, bt_mesh_gen_pwr_level_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, bt_mesh_gen_pwr_level_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_BATTERY_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, bt_mesh_gen_battery_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, bt_mesh_gen_battery_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_LOCATION_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, bt_mesh_gen_location_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, bt_mesh_gen_location_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_PROPERTY_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_PROP_CLI, bt_mesh_gen_property_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_PROP_CLI, bt_mesh_gen_property_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_SENSOR_CLI)
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_TIME_CLI)
|
||||
{ BLE_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_SCENE_CLI)
|
||||
{ BLE_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_SCHEDULER_CLI)
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_LIGHTNESS_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, bt_mesh_light_lightness_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, bt_mesh_light_lightness_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_CTL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, bt_mesh_light_ctl_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, bt_mesh_light_ctl_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_HSL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, bt_mesh_light_hsl_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, bt_mesh_light_hsl_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_XYL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, bt_mesh_light_xyl_cli_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, bt_mesh_light_xyl_cli_init },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_init },
|
||||
{ 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 },
|
||||
@ -145,6 +136,106 @@ static const struct {
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, bt_mesh_sensor_setup_srv_init },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const u16_t id;
|
||||
int (*const deinit)(struct bt_mesh_model *model, bool primary);
|
||||
} model_deinit[] = {
|
||||
{ BLE_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_deinit },
|
||||
#if defined(CONFIG_BLE_MESH_CFG_CLI)
|
||||
{ BLE_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_HEALTH_CLI)
|
||||
{ BLE_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, bt_mesh_gen_onoff_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_LEVEL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, bt_mesh_gen_level_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, bt_mesh_gen_def_trans_time_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_POWER_ONOFF_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, bt_mesh_gen_pwr_onoff_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_POWER_LEVEL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, bt_mesh_gen_pwr_level_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_BATTERY_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, bt_mesh_gen_battery_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_LOCATION_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, bt_mesh_gen_location_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_GENERIC_PROPERTY_CLI)
|
||||
{ BLE_MESH_MODEL_ID_GEN_PROP_CLI, bt_mesh_gen_property_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_SENSOR_CLI)
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_TIME_CLI)
|
||||
{ BLE_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_SCENE_CLI)
|
||||
{ BLE_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_SCHEDULER_CLI)
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_LIGHTNESS_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, bt_mesh_light_lightness_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_CTL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, bt_mesh_light_ctl_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_HSL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, bt_mesh_light_hsl_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_XYL_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, bt_mesh_light_xyl_cli_deinit },
|
||||
#endif
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_deinit },
|
||||
#endif
|
||||
{ BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, bt_mesh_gen_onoff_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, bt_mesh_gen_level_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, bt_mesh_gen_def_trans_time_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, bt_mesh_gen_power_onoff_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, bt_mesh_gen_power_onoff_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, bt_mesh_gen_power_level_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, bt_mesh_gen_power_level_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, bt_mesh_gen_battery_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, bt_mesh_gen_location_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, bt_mesh_gen_location_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, bt_mesh_gen_user_prop_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, bt_mesh_gen_admin_prop_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, bt_mesh_gen_manu_prop_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, bt_mesh_gen_client_prop_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, bt_mesh_light_lightness_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV, bt_mesh_light_lightness_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_SRV, bt_mesh_light_ctl_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV, bt_mesh_light_ctl_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV, bt_mesh_light_ctl_temp_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SRV, bt_mesh_light_hsl_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV, bt_mesh_light_hsl_hue_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV, bt_mesh_light_hsl_sat_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV, bt_mesh_light_hsl_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_SRV, bt_mesh_light_xyl_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV, bt_mesh_light_xyl_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_SRV, bt_mesh_light_lc_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV, bt_mesh_light_lc_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_TIME_SRV, bt_mesh_time_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_TIME_SETUP_SRV, bt_mesh_time_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_SCENE_SRV, bt_mesh_scene_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, bt_mesh_scene_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_SRV, bt_mesh_scheduler_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, bt_mesh_scheduler_setup_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_SRV, bt_mesh_sensor_srv_deinit },
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, bt_mesh_sensor_setup_srv_deinit },
|
||||
};
|
||||
|
||||
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
|
||||
struct bt_mesh_elem *elem,
|
||||
bool vnd, bool primary,
|
||||
@ -211,7 +302,7 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod)
|
||||
static s32_t next_period(struct bt_mesh_model *mod)
|
||||
{
|
||||
struct bt_mesh_model_pub *pub = mod->pub;
|
||||
u32_t elapsed, period;
|
||||
u32_t elapsed = 0U, period = 0U;
|
||||
|
||||
if (!pub) {
|
||||
BT_ERR("%s, Model has no publication support", __func__);
|
||||
@ -225,7 +316,7 @@ static s32_t next_period(struct bt_mesh_model *mod)
|
||||
|
||||
elapsed = k_uptime_get_32() - pub->period_start;
|
||||
|
||||
BT_DBG("Publishing took %ums", elapsed);
|
||||
BT_INFO("Publishing took %ums", elapsed);
|
||||
|
||||
if (elapsed >= period) {
|
||||
BT_WARN("Publication sending took longer than the period");
|
||||
@ -239,7 +330,7 @@ static s32_t next_period(struct bt_mesh_model *mod)
|
||||
static void publish_sent(int err, void *user_data)
|
||||
{
|
||||
struct bt_mesh_model *mod = user_data;
|
||||
s32_t delay;
|
||||
s32_t delay = 0;
|
||||
|
||||
BT_DBG("err %d", err);
|
||||
|
||||
@ -255,7 +346,7 @@ static void publish_sent(int err, void *user_data)
|
||||
}
|
||||
|
||||
if (delay) {
|
||||
BT_DBG("Publishing next time in %dms", delay);
|
||||
BT_INFO("Publishing next time in %dms", delay);
|
||||
k_delayed_work_submit(&mod->pub->timer, delay);
|
||||
}
|
||||
}
|
||||
@ -303,7 +394,7 @@ static int publish_retransmit(struct bt_mesh_model *mod)
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
.friend_cred = pub->cred,
|
||||
};
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
key = bt_mesh_app_key_find(pub->key);
|
||||
if (!key) {
|
||||
@ -337,13 +428,13 @@ static void mod_publish(struct k_work *work)
|
||||
struct bt_mesh_model_pub *pub = CONTAINER_OF(work,
|
||||
struct bt_mesh_model_pub,
|
||||
timer.work);
|
||||
s32_t period_ms;
|
||||
int err;
|
||||
s32_t period_ms = 0;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
period_ms = bt_mesh_model_pub_period_get(pub->mod);
|
||||
BT_DBG("period %u ms", period_ms);
|
||||
BT_INFO("period %u ms", period_ms);
|
||||
|
||||
if (pub->count) {
|
||||
err = publish_retransmit(pub->mod);
|
||||
@ -390,7 +481,7 @@ struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)
|
||||
|
||||
struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx)
|
||||
{
|
||||
struct bt_mesh_elem *elem;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
|
||||
if (!dev_comp) {
|
||||
BT_ERR("%s, dev_comp is not initialized", __func__);
|
||||
@ -456,6 +547,37 @@ static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
}
|
||||
}
|
||||
|
||||
static void mod_deinit(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
bool vnd, bool primary, void *user_data)
|
||||
{
|
||||
int i;
|
||||
|
||||
mod->elem = NULL;
|
||||
|
||||
if (mod->pub) {
|
||||
mod->pub->mod = NULL;
|
||||
k_delayed_work_free(&mod->pub->timer);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mod->keys); i++) {
|
||||
mod->keys[i] = BLE_MESH_KEY_UNUSED;
|
||||
}
|
||||
|
||||
mod->flags = 0U;
|
||||
mod->elem_idx = 0U;
|
||||
mod->model_idx = 0U;
|
||||
|
||||
if (vnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(model_deinit); i++) {
|
||||
if (model_deinit[i].id == mod->id) {
|
||||
model_deinit[i].deinit(mod, primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int bt_mesh_comp_register(const struct bt_mesh_comp *comp)
|
||||
{
|
||||
/* There must be at least one element */
|
||||
@ -470,13 +592,27 @@ int bt_mesh_comp_register(const struct bt_mesh_comp *comp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_comp_deregister(void)
|
||||
{
|
||||
if (dev_comp == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bt_mesh_model_foreach(mod_deinit, NULL);
|
||||
|
||||
dev_primary_addr = BLE_MESH_ADDR_UNASSIGNED;
|
||||
dev_comp = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_mesh_comp_provision(u16_t addr)
|
||||
{
|
||||
int i;
|
||||
|
||||
dev_primary_addr = addr;
|
||||
|
||||
BT_DBG("addr 0x%04x elem_count %u", addr, dev_comp->elem_count);
|
||||
BT_INFO("addr 0x%04x elem_count %u", addr, dev_comp->elem_count);
|
||||
|
||||
for (i = 0; i < dev_comp->elem_count; i++) {
|
||||
struct bt_mesh_elem *elem = &dev_comp->elem[i];
|
||||
@ -518,8 +654,8 @@ u16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, u16_t addr)
|
||||
static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem,
|
||||
u16_t group_addr)
|
||||
{
|
||||
struct bt_mesh_model *model;
|
||||
u16_t *match;
|
||||
struct bt_mesh_model *model = NULL;
|
||||
u16_t *match = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < elem->model_count; i++) {
|
||||
@ -545,7 +681,7 @@ static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem,
|
||||
|
||||
struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr)
|
||||
{
|
||||
u16_t index;
|
||||
u16_t index = 0U;
|
||||
|
||||
if (BLE_MESH_ADDR_IS_UNICAST(addr)) {
|
||||
index = (addr - dev_comp->elem[0].addr);
|
||||
@ -590,9 +726,9 @@ static const struct bt_mesh_model_op *find_op(struct bt_mesh_model *models,
|
||||
u16_t app_idx, u32_t opcode,
|
||||
struct bt_mesh_model **model)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < model_count; i++) {
|
||||
for (i = 0; i < model_count; i++) {
|
||||
const struct bt_mesh_model_op *op;
|
||||
|
||||
*model = &models[i];
|
||||
@ -672,22 +808,22 @@ bool bt_mesh_fixed_group_match(u16_t addr)
|
||||
|
||||
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_model *models, *model;
|
||||
const struct bt_mesh_model_op *op;
|
||||
u32_t opcode;
|
||||
u8_t count;
|
||||
struct bt_mesh_model *models = NULL, *model = NULL;
|
||||
const struct bt_mesh_model_op *op = NULL;
|
||||
u32_t opcode = 0U;
|
||||
u8_t count = 0U;
|
||||
int i;
|
||||
|
||||
BT_DBG("app_idx 0x%04x src 0x%04x dst 0x%04x", rx->ctx.app_idx,
|
||||
BT_INFO("app_idx 0x%04x src 0x%04x dst 0x%04x", rx->ctx.app_idx,
|
||||
rx->ctx.addr, rx->ctx.recv_dst);
|
||||
BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
BT_INFO("len %u: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
if (get_opcode(buf, &opcode) < 0) {
|
||||
BT_WARN("%s, Unable to decode OpCode", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_DBG("OpCode 0x%08x", opcode);
|
||||
BT_INFO("OpCode 0x%08x", opcode);
|
||||
|
||||
for (i = 0; i < dev_comp->elem_count; i++) {
|
||||
struct bt_mesh_elem *elem = &dev_comp->elem[i];
|
||||
@ -780,48 +916,17 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode)
|
||||
|
||||
static bool ready_to_send(u8_t role, u16_t dst)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
BT_ERR("%s, Local node is not yet provisioned", __func__);
|
||||
return false;
|
||||
}
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (!provisioner_check_msg_dst_addr(dst)) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
|
||||
return true;
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
|
||||
if (!bt_mesh_provisioner_check_msg_dst(dst)) {
|
||||
BT_ERR("%s, Failed to find DST 0x%04x", __func__, dst);
|
||||
return false;
|
||||
}
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (!provisioner_check_msg_dst_addr(dst)) {
|
||||
BT_ERR("%s, Failed to check DST", __func__);
|
||||
return false;
|
||||
}
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
BT_ERR("%s, Local node is not yet provisioned", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -831,7 +936,7 @@ static int model_send(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
u8_t role;
|
||||
u8_t role = 0U;
|
||||
|
||||
role = bt_mesh_get_device_role(model, tx->ctx->srv_send);
|
||||
if (role == ROLE_NVAL) {
|
||||
@ -839,9 +944,9 @@ static int model_send(struct bt_mesh_model *model,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->ctx->net_idx,
|
||||
BT_INFO("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->ctx->net_idx,
|
||||
tx->ctx->app_idx, tx->ctx->addr);
|
||||
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
|
||||
BT_INFO("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
|
||||
|
||||
if (!ready_to_send(role, tx->ctx->addr)) {
|
||||
BT_ERR("%s, fail", __func__);
|
||||
@ -872,7 +977,7 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u8_t role;
|
||||
u8_t role = 0U;
|
||||
|
||||
role = bt_mesh_get_device_role(model, ctx->srv_send);
|
||||
if (role == ROLE_NVAL) {
|
||||
@ -911,7 +1016,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
.src = bt_mesh_model_elem(model)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -925,7 +1030,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
return -EADDRNOTAVAIL;
|
||||
}
|
||||
|
||||
key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key, BLE_MESH_KEY_ANY);
|
||||
key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key);
|
||||
if (!key) {
|
||||
BT_ERR("%s, Failed to get AppKey", __func__);
|
||||
return -EADDRNOTAVAIL;
|
||||
@ -957,7 +1062,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
|
||||
pub->count = BLE_MESH_PUB_TRANSMIT_COUNT(pub->retransmit);
|
||||
|
||||
BT_DBG("Publish Retransmit Count %u Interval %ums", pub->count,
|
||||
BT_INFO("Publish Retransmit Count %u Interval %ums", pub->count,
|
||||
BLE_MESH_PUB_TRANSMIT_INT(pub->retransmit));
|
||||
|
||||
sdu = bt_mesh_alloc_buf(pub->msg->len + 4);
|
||||
@ -983,9 +1088,9 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem,
|
||||
u16_t company, u16_t id)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < elem->vnd_model_count; i++) {
|
||||
for (i = 0; i < elem->vnd_model_count; i++) {
|
||||
if (elem->vnd_models[i].vnd.company == company &&
|
||||
elem->vnd_models[i].vnd.id == id) {
|
||||
return &elem->vnd_models[i];
|
||||
@ -998,9 +1103,9 @@ struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem,
|
||||
struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem,
|
||||
u16_t id)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < elem->model_count; i++) {
|
||||
for (i = 0; i < elem->model_count; i++) {
|
||||
if (elem->models[i].id == id) {
|
||||
return &elem->models[i];
|
||||
}
|
||||
@ -1019,37 +1124,13 @@ struct bt_mesh_subnet *bt_mesh_tx_netkey_get(u8_t role, u16_t net_idx)
|
||||
{
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
sub = bt_mesh_subnet_get(net_idx);
|
||||
}
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
|
||||
sub = bt_mesh_subnet_get(net_idx);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
|
||||
sub = bt_mesh_provisioner_subnet_get(net_idx);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
|
||||
sub = bt_mesh_fast_prov_subnet_get(net_idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
sub = bt_mesh_subnet_get(net_idx);
|
||||
}
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(net_idx);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
sub = fast_prov_subnet_get(net_idx);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return sub;
|
||||
}
|
||||
@ -1058,76 +1139,28 @@ const u8_t *bt_mesh_tx_devkey_get(u8_t role, u16_t dst)
|
||||
{
|
||||
const u8_t *key = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh.dev_key;
|
||||
}
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
|
||||
key = bt_mesh.dev_key;
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
|
||||
key = bt_mesh_provisioner_dev_key_get(dst);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
|
||||
key = bt_mesh_fast_prov_dev_key_get(dst);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_dev_key_get(dst);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh.dev_key;
|
||||
}
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_dev_key_get(dst);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
key = fast_prov_dev_key_get(dst);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t net_idx)
|
||||
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx)
|
||||
{
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh_app_key_find(app_idx);
|
||||
}
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
|
||||
key = bt_mesh_app_key_find(app_idx);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
|
||||
key = bt_mesh_provisioner_app_key_find(app_idx);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
|
||||
key = bt_mesh_fast_prov_app_key_find(app_idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_app_key_find(app_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh_app_key_find(app_idx);
|
||||
}
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_app_key_find(app_idx);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
key = fast_prov_app_key_find(net_idx, app_idx);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return key;
|
||||
}
|
||||
@ -1135,7 +1168,7 @@ struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t ne
|
||||
/* APIs used by messages decryption in network layer & upper transport layer */
|
||||
size_t bt_mesh_rx_netkey_size(void)
|
||||
{
|
||||
size_t size = 0;
|
||||
size_t size = 0U;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
@ -1188,10 +1221,10 @@ struct bt_mesh_subnet *bt_mesh_rx_netkey_get(size_t index)
|
||||
|
||||
size_t bt_mesh_rx_devkey_size(void)
|
||||
{
|
||||
size_t size = 0;
|
||||
size_t size = 0U;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
size = 1;
|
||||
}
|
||||
#endif
|
||||
@ -1224,7 +1257,7 @@ const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src)
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_dev_key_get(src);
|
||||
key = bt_mesh_provisioner_dev_key_get(src);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1232,7 +1265,7 @@ const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src)
|
||||
if (index < 1) {
|
||||
key = bt_mesh.dev_key;
|
||||
} else {
|
||||
key = provisioner_dev_key_get(src);
|
||||
key = bt_mesh_provisioner_dev_key_get(src);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1241,7 +1274,7 @@ const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src)
|
||||
|
||||
size_t bt_mesh_rx_appkey_size(void)
|
||||
{
|
||||
size_t size = 0;
|
||||
size_t size = 0U;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
|
@ -9,8 +9,6 @@
|
||||
#ifndef _ACCESS_H_
|
||||
#define _ACCESS_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "net.h"
|
||||
|
||||
/* bt_mesh_model.flags */
|
||||
@ -56,12 +54,13 @@ struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx);
|
||||
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
|
||||
|
||||
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
|
||||
int bt_mesh_comp_deregister(void);
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(u8_t role, u16_t net_idx);
|
||||
|
||||
const u8_t *bt_mesh_tx_devkey_get(u8_t role, u16_t dst);
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t net_idx);
|
||||
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx);
|
||||
|
||||
size_t bt_mesh_rx_netkey_size(void);
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@ -15,26 +16,19 @@
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "osi/thread.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_ADV)
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_hci.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "mesh_hci.h"
|
||||
#include "adv.h"
|
||||
#include "net.h"
|
||||
#include "foundation.h"
|
||||
#include "beacon.h"
|
||||
#include "prov.h"
|
||||
#include "foundation.h"
|
||||
#include "proxy_server.h"
|
||||
|
||||
#include "provisioner_prov.h"
|
||||
#include "proxy_client.h"
|
||||
#include "provisioner_beacon.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
/* Convert from ms to 0.625ms units */
|
||||
#define ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5)
|
||||
@ -64,13 +58,22 @@ static const u8_t adv_type[] = {
|
||||
[BLE_MESH_ADV_URI] = BLE_MESH_DATA_URI,
|
||||
};
|
||||
|
||||
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME,
|
||||
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT,
|
||||
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
|
||||
|
||||
static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME];
|
||||
static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT];
|
||||
|
||||
static QueueHandle_t xBleMeshQueue;
|
||||
#define BLE_MESH_QUEUE_SIZE 150
|
||||
struct bt_mesh_queue {
|
||||
QueueHandle_t queue;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
StaticQueue_t *buffer;
|
||||
u8_t *storage;
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct bt_mesh_queue xBleMeshQueue;
|
||||
/* We reserve one queue for bt_mesh_adv_update() */
|
||||
#define BLE_MESH_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + 1)
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
|
||||
@ -78,8 +81,8 @@ NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
|
||||
|
||||
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 struct bt_mesh_queue xBleMeshRelayQueue;
|
||||
#define BLE_MESH_RELAY_QUEUE_SIZE CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT
|
||||
|
||||
static QueueSetHandle_t xBleMeshQueueSet;
|
||||
#define BLE_MESH_QUEUE_SET_SIZE (BLE_MESH_QUEUE_SIZE + BLE_MESH_RELAY_QUEUE_SIZE)
|
||||
@ -90,6 +93,16 @@ static QueueSetHandle_t xBleMeshQueueSet;
|
||||
static bool ignore_relay_packet(u32_t timestamp);
|
||||
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
struct bt_mesh_adv_task {
|
||||
TaskHandle_t handle;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
StaticTask_t *task;
|
||||
StackType_t *stack;
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct bt_mesh_adv_task adv_task;
|
||||
|
||||
static struct bt_mesh_adv *adv_alloc(int id)
|
||||
{
|
||||
return &adv_pool[id];
|
||||
@ -119,9 +132,9 @@ static inline int adv_send(struct net_buf *buf)
|
||||
const struct bt_mesh_send_cb *cb = BLE_MESH_ADV(buf)->cb;
|
||||
void *cb_data = BLE_MESH_ADV(buf)->cb_data;
|
||||
struct bt_mesh_adv_param param = {0};
|
||||
u16_t duration, adv_int;
|
||||
u16_t duration = 0U, adv_int = 0U;
|
||||
struct bt_mesh_adv_data ad = {0};
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
adv_int = MAX(adv_int_min,
|
||||
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
|
||||
@ -142,7 +155,7 @@ static inline int adv_send(struct net_buf *buf)
|
||||
param.interval_min = ADV_SCAN_UNIT(adv_int);
|
||||
param.interval_max = param.interval_min;
|
||||
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 4U, BLE_MESH_BUF_REF_SMALL);
|
||||
|
||||
err = bt_le_adv_start(¶m, &ad, 1, NULL, 0);
|
||||
net_buf_unref(buf);
|
||||
@ -170,10 +183,10 @@ static inline int adv_send(struct net_buf *buf)
|
||||
static void adv_thread(void *p)
|
||||
{
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
QueueSetMemberHandle_t handle;
|
||||
QueueSetMemberHandle_t handle = NULL;
|
||||
#endif
|
||||
bt_mesh_msg_t msg = {0};
|
||||
struct net_buf **buf;
|
||||
struct net_buf **buf = NULL;
|
||||
|
||||
buf = (struct net_buf **)(&msg.arg);
|
||||
|
||||
@ -182,72 +195,59 @@ static void adv_thread(void *p)
|
||||
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);
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT);
|
||||
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);
|
||||
xQueueReceive(xBleMeshQueue.queue, &msg, timeout);
|
||||
BT_DBG("Mesh Proxy Advertising stop");
|
||||
bt_mesh_proxy_adv_stop();
|
||||
}
|
||||
#else
|
||||
xQueueReceive(xBleMeshQueue.queue, &msg, portMAX_DELAY);
|
||||
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT);
|
||||
if (handle) {
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) {
|
||||
xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT);
|
||||
}
|
||||
} else {
|
||||
while (!(*buf)) {
|
||||
s32_t timeout;
|
||||
s32_t timeout = 0;
|
||||
BT_DBG("Mesh Proxy Advertising start");
|
||||
timeout = bt_mesh_proxy_adv_start();
|
||||
BT_DBG("Mesh Proxy Advertising up to %d ms", timeout);
|
||||
xQueueReceive(xBleMeshQueue, &msg, timeout);
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, timeout);
|
||||
BT_DBG("Mesh Proxy Advertising stop");
|
||||
bt_mesh_proxy_adv_stop();
|
||||
}
|
||||
} else {
|
||||
xQueueReceive(xBleMeshQueue, &msg, portMAX_DELAY);
|
||||
}
|
||||
#else
|
||||
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);
|
||||
}
|
||||
if (handle) {
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) {
|
||||
xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue.queue, &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);
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) {
|
||||
xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||
#endif /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
if (*buf == NULL) {
|
||||
@ -266,7 +266,7 @@ static void adv_thread(void *p)
|
||||
/* 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__);
|
||||
BT_INFO("%s, Ignore relay packet", __func__);
|
||||
net_buf_unref(*buf);
|
||||
} else {
|
||||
if (adv_send(*buf)) {
|
||||
@ -289,8 +289,8 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
||||
enum bt_mesh_adv_type type,
|
||||
u8_t xmit, s32_t timeout)
|
||||
{
|
||||
struct bt_mesh_adv *adv;
|
||||
struct net_buf *buf;
|
||||
struct bt_mesh_adv *adv = NULL;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_SUSPENDED)) {
|
||||
BT_WARN("Refusing to allocate buffer while suspended");
|
||||
@ -316,6 +316,24 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
||||
return buf;
|
||||
}
|
||||
|
||||
void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (pool == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < pool->buf_count; i++) {
|
||||
struct net_buf *buf = &pool->__bufs[i];
|
||||
if (buf->ref > 1U) {
|
||||
buf->ref = 1U;
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
|
||||
s32_t timeout)
|
||||
{
|
||||
@ -349,7 +367,7 @@ void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
|
||||
|
||||
static void bt_mesh_unref_buf(bt_mesh_msg_t *msg)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
if (msg->arg) {
|
||||
buf = (struct net_buf *)msg->arg;
|
||||
@ -363,7 +381,13 @@ static void bt_mesh_unref_buf(bt_mesh_msg_t *msg)
|
||||
static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
{
|
||||
BT_DBG("%s", __func__);
|
||||
if (xQueueSend(xBleMeshQueue, msg, timeout) != pdTRUE) {
|
||||
|
||||
if (xBleMeshQueue.queue == NULL) {
|
||||
BT_ERR("%s, Invalid queue", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (xQueueSend(xBleMeshQueue.queue, msg, timeout) != pdTRUE) {
|
||||
BT_ERR("%s, Failed to send item to queue", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
}
|
||||
@ -405,12 +429,10 @@ void bt_mesh_adv_update(void)
|
||||
static bool ignore_relay_packet(u32_t timestamp)
|
||||
{
|
||||
u32_t now = k_uptime_get_32();
|
||||
u32_t interval;
|
||||
u32_t interval = 0U;
|
||||
|
||||
if (now > timestamp) {
|
||||
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;
|
||||
}
|
||||
@ -432,12 +454,17 @@ struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
|
||||
|
||||
static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
{
|
||||
QueueSetMemberHandle_t handle;
|
||||
QueueSetMemberHandle_t handle = NULL;
|
||||
bt_mesh_msg_t old_msg = {0};
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
if (xQueueSend(xBleMeshRelayQueue, msg, timeout) == pdTRUE) {
|
||||
if (xBleMeshRelayQueue.queue == NULL) {
|
||||
BT_ERR("%s, Invalid relay queue", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (xQueueSend(xBleMeshRelayQueue.queue, msg, timeout) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -446,10 +473,10 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
* 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__);
|
||||
if (handle && uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) {
|
||||
BT_INFO("%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) {
|
||||
if (xQueueReceive(xBleMeshRelayQueue.queue, &old_msg, K_NO_WAIT) != pdTRUE) {
|
||||
BT_ERR("%s, Failed to remove item from queue", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
return;
|
||||
@ -457,7 +484,7 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
/* 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) {
|
||||
if (xQueueSend(xBleMeshRelayQueue.queue, msg, K_NO_WAIT) != pdTRUE) {
|
||||
BT_ERR("%s, Failed to send item to relay queue", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
return;
|
||||
@ -492,7 +519,7 @@ void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *c
|
||||
|
||||
u16_t bt_mesh_get_stored_relay_count(void)
|
||||
{
|
||||
return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue);
|
||||
return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue.queue);
|
||||
}
|
||||
#endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
@ -505,7 +532,7 @@ const bt_mesh_addr_t *bt_mesh_pba_get_addr(void)
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
static bool bt_mesh_is_adv_flags_valid(struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t flags;
|
||||
u8_t flags = 0U;
|
||||
|
||||
if (buf->len != 1U) {
|
||||
BT_DBG("%s, Unexpected flags length", __func__);
|
||||
@ -517,6 +544,7 @@ static bool bt_mesh_is_adv_flags_valid(struct net_buf_simple *buf)
|
||||
BT_DBG("Received adv pkt with flags: 0x%02x", flags);
|
||||
|
||||
/* Flags context will not be checked curently */
|
||||
((void) flags);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -554,9 +582,9 @@ static bool bt_mesh_is_adv_srv_uuid_valid(struct net_buf_simple *buf, u16_t *uui
|
||||
#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)
|
||||
static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid, s8_t rssi)
|
||||
{
|
||||
u16_t type;
|
||||
u16_t type = 0U;
|
||||
|
||||
if (!buf || !addr) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -579,7 +607,7 @@ static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_
|
||||
}
|
||||
|
||||
BT_DBG("Start to handle Mesh Prov Service Data");
|
||||
provisioner_prov_adv_ind_recv(buf, addr);
|
||||
bt_mesh_provisioner_prov_adv_ind_recv(buf, addr, rssi);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@ -592,7 +620,7 @@ static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_
|
||||
}
|
||||
|
||||
BT_DBG("Start to handle Mesh Proxy Service Data");
|
||||
proxy_client_adv_ind_recv(buf, addr);
|
||||
bt_mesh_proxy_client_adv_ind_recv(buf, addr, rssi);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -606,7 +634,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
{
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
u16_t uuid = 0x0;
|
||||
u16_t uuid = 0U;
|
||||
#endif
|
||||
|
||||
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
|
||||
@ -654,29 +682,16 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
break;
|
||||
#if CONFIG_BLE_MESH_PB_ADV
|
||||
case BLE_MESH_DATA_MESH_PROV:
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node()) {
|
||||
bt_mesh_pb_adv_recv(buf);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
provisioner_pb_adv_recv(buf);
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
bt_mesh_provisioner_pb_adv_recv(buf);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_PB_ADV */
|
||||
case BLE_MESH_DATA_MESH_BEACON:
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
bt_mesh_beacon_recv(buf);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
provisioner_beacon_recv(buf);
|
||||
}
|
||||
#endif
|
||||
bt_mesh_beacon_recv(buf, rssi);
|
||||
break;
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
@ -693,7 +708,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
}
|
||||
break;
|
||||
case BLE_MESH_DATA_SVC_DATA16:
|
||||
bt_mesh_adv_srv_data_recv(buf, addr, uuid);
|
||||
bt_mesh_adv_srv_data_recv(buf, addr, uuid, rssi);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -709,24 +724,109 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
|
||||
void bt_mesh_adv_init(void)
|
||||
{
|
||||
xBleMeshQueue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
|
||||
configASSERT(xBleMeshQueue);
|
||||
#if !CONFIG_SPIRAM_USE_MALLOC
|
||||
xBleMeshQueue.queue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
|
||||
__ASSERT(xBleMeshQueue.queue, "%s, Failed to create queue", __func__);
|
||||
#else
|
||||
xBleMeshQueue.buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
__ASSERT(xBleMeshQueue.buffer, "%s, Failed to create queue buffer", __func__);
|
||||
xBleMeshQueue.storage = heap_caps_calloc(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
__ASSERT(xBleMeshQueue.storage, "%s, Failed to create queue storage", __func__);
|
||||
xBleMeshQueue.queue = xQueueCreateStatic(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshQueue.storage, xBleMeshQueue.buffer);
|
||||
__ASSERT(xBleMeshQueue.queue, "%s, Failed to create static queue", __func__);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
xBleMeshRelayQueue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
|
||||
configASSERT(xBleMeshRelayQueue);
|
||||
#if !CONFIG_SPIRAM_USE_MALLOC
|
||||
xBleMeshRelayQueue.queue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
|
||||
__ASSERT(xBleMeshRelayQueue.queue, "%s, Failed to create relay queue", __func__);
|
||||
#else
|
||||
xBleMeshRelayQueue.buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
__ASSERT(xBleMeshRelayQueue.buffer, "%s, Failed to create relay queue buffer", __func__);
|
||||
xBleMeshRelayQueue.storage = heap_caps_calloc(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
__ASSERT(xBleMeshRelayQueue.storage, "%s, Failed to create relay queue storage", __func__);
|
||||
xBleMeshRelayQueue.queue = xQueueCreateStatic(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshRelayQueue.storage, xBleMeshRelayQueue.buffer);
|
||||
__ASSERT(xBleMeshRelayQueue.queue, "%s, Failed to create static relay queue", __func__);
|
||||
#endif
|
||||
|
||||
xBleMeshQueueSet = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE);
|
||||
configASSERT(xBleMeshQueueSet);
|
||||
xQueueAddToSet(xBleMeshQueue, xBleMeshQueueSet);
|
||||
xQueueAddToSet(xBleMeshRelayQueue, xBleMeshQueueSet);
|
||||
__ASSERT(xBleMeshQueueSet, "%s, Failed to create queue set", __func__);
|
||||
xQueueAddToSet(xBleMeshQueue.queue, xBleMeshQueueSet);
|
||||
xQueueAddToSet(xBleMeshRelayQueue.queue, 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);
|
||||
configASSERT(ret == pdTRUE);
|
||||
|
||||
#if !CONFIG_SPIRAM_USE_MALLOC
|
||||
int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL,
|
||||
configMAX_PRIORITIES - 5, &adv_task.handle, BLE_MESH_ADV_TASK_CORE);
|
||||
__ASSERT(ret == pdTRUE, "%s, Failed to create adv thread", __func__);
|
||||
#else
|
||||
adv_task.task = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
||||
__ASSERT(adv_task.task, "%s, Failed to create adv thread task", __func__);
|
||||
#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
|
||||
adv_task.stack = heap_caps_calloc(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
|
||||
#else
|
||||
adv_task.stack = heap_caps_calloc(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
||||
#endif
|
||||
__ASSERT(adv_task.stack, "%s, Failed to create adv thread stack", __func__);
|
||||
adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL,
|
||||
configMAX_PRIORITIES - 5, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE);
|
||||
__ASSERT(adv_task.stack, "%s, Failed to create static adv thread stack", __func__);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_adv_deinit(void)
|
||||
{
|
||||
if (xBleMeshQueue.queue == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
xQueueRemoveFromSet(xBleMeshQueue.queue, xBleMeshQueueSet);
|
||||
xQueueRemoveFromSet(xBleMeshRelayQueue.queue, xBleMeshQueueSet);
|
||||
|
||||
vQueueDelete(xBleMeshRelayQueue.queue);
|
||||
xBleMeshRelayQueue.queue = NULL;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
heap_caps_free(xBleMeshRelayQueue.buffer);
|
||||
xBleMeshRelayQueue.buffer = NULL;
|
||||
heap_caps_free(xBleMeshRelayQueue.storage);
|
||||
xBleMeshRelayQueue.storage = NULL;
|
||||
#endif
|
||||
|
||||
bt_mesh_unref_buf_from_pool(&relay_adv_buf_pool);
|
||||
memset(relay_adv_pool, 0, sizeof(relay_adv_pool));
|
||||
|
||||
vQueueDelete(xBleMeshQueueSet);
|
||||
xBleMeshQueueSet = NULL;
|
||||
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
vQueueDelete(xBleMeshQueue.queue);
|
||||
xBleMeshQueue.queue = NULL;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
heap_caps_free(xBleMeshQueue.buffer);
|
||||
xBleMeshQueue.buffer = NULL;
|
||||
heap_caps_free(xBleMeshQueue.storage);
|
||||
xBleMeshQueue.storage = NULL;
|
||||
#endif
|
||||
|
||||
bt_mesh_unref_buf_from_pool(&adv_buf_pool);
|
||||
memset(adv_pool, 0, sizeof(adv_pool));
|
||||
|
||||
vTaskDelete(adv_task.handle);
|
||||
adv_task.handle = NULL;
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
heap_caps_free(adv_task.stack);
|
||||
adv_task.stack = NULL;
|
||||
/* Delay certain period for free adv_task.task */
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
heap_caps_free(adv_task.task);
|
||||
adv_task.task = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int bt_mesh_scan_enable(void)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
struct bt_mesh_scan_param scan_param = {
|
||||
.type = BLE_MESH_SCAN_PASSIVE,
|
||||
@ -752,7 +852,7 @@ int bt_mesh_scan_enable(void)
|
||||
|
||||
int bt_mesh_scan_disable(void)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#ifndef _ADV_H_
|
||||
#define _ADV_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
/* Maximum advertising data payload for a single data type */
|
||||
@ -72,6 +73,8 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
||||
enum bt_mesh_adv_type type,
|
||||
u8_t xmit, s32_t timeout);
|
||||
|
||||
void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool);
|
||||
|
||||
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data);
|
||||
|
||||
@ -88,6 +91,7 @@ u16_t bt_mesh_get_stored_relay_count(void);
|
||||
void bt_mesh_adv_update(void);
|
||||
|
||||
void bt_mesh_adv_init(void);
|
||||
void bt_mesh_adv_deinit(void);
|
||||
|
||||
int bt_mesh_scan_enable(void);
|
||||
|
||||
|
@ -10,24 +10,19 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_BEACON)
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_trace.h"
|
||||
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "prov.h"
|
||||
#include "crypto.h"
|
||||
#include "beacon.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "proxy_client.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
#include "mesh_main.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_FAST_PROV)
|
||||
#define UNPROVISIONED_INTERVAL K_SECONDS(3)
|
||||
@ -49,12 +44,15 @@ static struct k_delayed_work beacon_timer;
|
||||
|
||||
static struct bt_mesh_subnet *cache_check(u8_t data[21])
|
||||
{
|
||||
int i;
|
||||
size_t subnet_size = 0U;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
|
||||
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
|
||||
subnet_size = bt_mesh_rx_netkey_size();
|
||||
|
||||
if (sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
for (i = 0; i < subnet_size; i++) {
|
||||
struct bt_mesh_subnet *sub = bt_mesh_rx_netkey_get(i);
|
||||
|
||||
if (sub == NULL || sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -84,7 +82,7 @@ void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t flags = bt_mesh_net_flags(sub);
|
||||
struct bt_mesh_subnet_keys *keys;
|
||||
struct bt_mesh_subnet_keys *keys = NULL;
|
||||
|
||||
net_buf_simple_add_u8(buf, BEACON_TYPE_SECURE);
|
||||
|
||||
@ -104,9 +102,9 @@ void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
|
||||
|
||||
net_buf_simple_add_mem(buf, sub->auth, 8);
|
||||
|
||||
BT_DBG("net_idx 0x%04x flags 0x%02x NetID %s", sub->net_idx,
|
||||
BT_INFO("net_idx 0x%04x flags 0x%02x NetID %s", sub->net_idx,
|
||||
flags, bt_hex(keys->net_id, 8));
|
||||
BT_DBG("IV Index 0x%08x Auth %s", bt_mesh.iv_index,
|
||||
BT_INFO("IV Index 0x%08x Auth %s", bt_mesh.iv_index,
|
||||
bt_hex(sub->auth, 8));
|
||||
}
|
||||
|
||||
@ -120,16 +118,19 @@ static int secure_beacon_send(void)
|
||||
.end = beacon_complete,
|
||||
};
|
||||
u32_t now = k_uptime_get_32();
|
||||
int i;
|
||||
size_t subnet_size = 0U;
|
||||
int i = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
|
||||
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
|
||||
subnet_size = bt_mesh_rx_netkey_size();
|
||||
|
||||
for (i = 0; i < subnet_size; i++) {
|
||||
struct bt_mesh_subnet *sub = bt_mesh_rx_netkey_get(i);
|
||||
struct net_buf *buf;
|
||||
u32_t time_diff;
|
||||
|
||||
if (sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
if (sub == NULL || sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -167,13 +168,14 @@ static int secure_beacon_send(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NODE)
|
||||
static int unprovisioned_beacon_send(void)
|
||||
{
|
||||
#if defined(CONFIG_BLE_MESH_PB_ADV)
|
||||
const struct bt_mesh_prov *prov;
|
||||
const struct bt_mesh_prov *prov = NULL;
|
||||
u8_t uri_hash[16] = { 0 };
|
||||
struct net_buf *buf;
|
||||
u16_t oob_info;
|
||||
struct net_buf *buf = NULL;
|
||||
u16_t oob_info = 0U;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -224,11 +226,18 @@ static int unprovisioned_beacon_send(void)
|
||||
#endif /* CONFIG_BLE_MESH_PB_ADV */
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_NODE */
|
||||
static int unprovisioned_beacon_send(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
static void update_beacon_observation(void)
|
||||
{
|
||||
static bool first_half;
|
||||
int i;
|
||||
size_t subnet_size = 0U;
|
||||
int i = 0;
|
||||
|
||||
/* Observation period is 20 seconds, whereas the beacon timer
|
||||
* runs every 10 seconds. We process what's happened during the
|
||||
@ -239,10 +248,12 @@ static void update_beacon_observation(void)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
|
||||
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
|
||||
subnet_size = bt_mesh_rx_netkey_size();
|
||||
|
||||
if (sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
for (i = 0; i < subnet_size; i++) {
|
||||
struct bt_mesh_subnet *sub = bt_mesh_rx_netkey_get(i);
|
||||
|
||||
if (sub == NULL || sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -251,17 +262,33 @@ static void update_beacon_observation(void)
|
||||
}
|
||||
}
|
||||
|
||||
static bool ready_to_send(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
if (bt_mesh_provisioner_get_all_node_count()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void beacon_send(struct k_work *work)
|
||||
{
|
||||
/* Don't send anything if we have an active provisioning link */
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROV) && bt_prov_active()) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
||||
IS_ENABLED(CONFIG_BLE_MESH_PROV) && bt_prov_active()) {
|
||||
k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
if (ready_to_send()) {
|
||||
update_beacon_observation();
|
||||
secure_beacon_send();
|
||||
|
||||
@ -272,19 +299,21 @@ static void beacon_send(struct k_work *work)
|
||||
PROVISIONED_INTERVAL);
|
||||
}
|
||||
} else {
|
||||
unprovisioned_beacon_send();
|
||||
k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL);
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node()) {
|
||||
unprovisioned_beacon_send();
|
||||
k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void secure_beacon_recv(struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t *data, *net_id, *auth;
|
||||
struct bt_mesh_subnet *sub;
|
||||
u32_t iv_index;
|
||||
bool new_key, kr_change, iv_change;
|
||||
u8_t flags;
|
||||
u8_t *data = NULL, *net_id = NULL, *auth = NULL;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u32_t iv_index = 0U;
|
||||
bool new_key = false, kr_change = false, iv_change = false;
|
||||
u8_t flags = 0U;
|
||||
|
||||
if (buf->len < 21) {
|
||||
BT_ERR("%s, Too short secure beacon (len %u)", __func__, buf->len);
|
||||
@ -322,13 +351,13 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
|
||||
cache_add(data, sub);
|
||||
|
||||
/* If we have NetKey0 accept initiation only from it */
|
||||
if (bt_mesh_subnet_get(BLE_MESH_KEY_PRIMARY) &&
|
||||
if (bt_mesh_primary_subnet_exist() &&
|
||||
sub->net_idx != BLE_MESH_KEY_PRIMARY) {
|
||||
BT_WARN("Ignoring secure beacon on non-primary subnet");
|
||||
goto update_stats;
|
||||
}
|
||||
|
||||
BT_DBG("net_idx 0x%04x iv_index 0x%08x, current iv_index 0x%08x",
|
||||
BT_INFO("net_idx 0x%04x iv_index 0x%08x, current iv_index 0x%08x",
|
||||
sub->net_idx, iv_index, bt_mesh.iv_index);
|
||||
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_INITIATOR) &&
|
||||
@ -359,9 +388,9 @@ update_stats:
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_beacon_recv(struct net_buf_simple *buf)
|
||||
void bt_mesh_beacon_recv(struct net_buf_simple *buf, s8_t rssi)
|
||||
{
|
||||
u8_t type;
|
||||
u8_t type = 0U;
|
||||
|
||||
BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
@ -373,7 +402,11 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf)
|
||||
type = net_buf_simple_pull_u8(buf);
|
||||
switch (type) {
|
||||
case BEACON_TYPE_UNPROVISIONED:
|
||||
BT_DBG("Ignoring unprovisioned device beacon");
|
||||
BT_DBG("Unprovisioned device beacon received");
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) &&
|
||||
bt_mesh_is_provisioner_en()) {
|
||||
bt_mesh_provisioner_unprov_beacon_recv(buf, rssi);
|
||||
}
|
||||
break;
|
||||
case BEACON_TYPE_SECURE:
|
||||
secure_beacon_recv(buf);
|
||||
@ -389,6 +422,11 @@ void bt_mesh_beacon_init(void)
|
||||
k_delayed_work_init(&beacon_timer, beacon_send);
|
||||
}
|
||||
|
||||
void bt_mesh_beacon_deinit(void)
|
||||
{
|
||||
k_delayed_work_free(&beacon_timer);
|
||||
}
|
||||
|
||||
void bt_mesh_beacon_ivu_initiator(bool enable)
|
||||
{
|
||||
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_INITIATOR, enable);
|
||||
@ -402,17 +440,21 @@ void bt_mesh_beacon_ivu_initiator(bool enable)
|
||||
|
||||
void bt_mesh_beacon_enable(void)
|
||||
{
|
||||
int i;
|
||||
size_t subnet_size = 0U;
|
||||
int i = 0;
|
||||
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
||||
!bt_mesh_is_provisioned()) {
|
||||
k_work_submit(&beacon_timer.work);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
|
||||
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
|
||||
subnet_size = bt_mesh_rx_netkey_size();
|
||||
|
||||
if (sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
for (i = 0; i < subnet_size; i++) {
|
||||
struct bt_mesh_subnet *sub = bt_mesh_rx_netkey_get(i);
|
||||
|
||||
if (sub == NULL || sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -431,5 +473,3 @@ void bt_mesh_beacon_disable(void)
|
||||
k_delayed_work_cancel(&beacon_timer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
@ -9,16 +9,19 @@
|
||||
#ifndef _BEACON_H_
|
||||
#define _BEACON_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
void bt_mesh_beacon_enable(void);
|
||||
void bt_mesh_beacon_disable(void);
|
||||
|
||||
void bt_mesh_beacon_ivu_initiator(bool enable);
|
||||
|
||||
void bt_mesh_beacon_recv(struct net_buf_simple *buf);
|
||||
void bt_mesh_beacon_recv(struct net_buf_simple *buf, s8_t rssi);
|
||||
|
||||
void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_beacon_init(void);
|
||||
void bt_mesh_beacon_deinit(void);
|
||||
|
||||
#endif /* _BEACON_H_ */
|
||||
|
@ -6,20 +6,16 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "bta/bta_api.h"
|
||||
#include "bta/bta_gatt_api.h"
|
||||
#include "bta/bta_gatt_common.h"
|
||||
#include "bta_gattc_int.h"
|
||||
#include "stack/btm_ble_api.h"
|
||||
#include "p_256_ecc_pp.h"
|
||||
#include "stack/hcimsgs.h"
|
||||
#include "osi/future.h"
|
||||
#include "osi/allocator.h"
|
||||
#include "bt_common.h"
|
||||
#include "device/controller.h"
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
@ -27,12 +23,8 @@
|
||||
#include "mesh_hci.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_atomic.h"
|
||||
|
||||
#include "provisioner_prov.h"
|
||||
#include "mesh_common.h"
|
||||
#include "provisioner_prov.h"
|
||||
|
||||
struct bt_mesh_dev bt_mesh_dev;
|
||||
|
||||
@ -65,7 +57,10 @@ static BT_OCTET32 bt_mesh_private_key = {
|
||||
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
|
||||
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data);
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
/* Using UUID with a fixed pattern 0x96 for BLE Mesh GATT Proxy Server */
|
||||
#define BLE_MESH_GATTS_APP_UUID_BYTE 0x96
|
||||
/* the gatt database list to save the attribute table */
|
||||
static sys_slist_t bt_mesh_gatts_db;
|
||||
|
||||
@ -79,10 +74,11 @@ static future_t *future_mesh;
|
||||
|
||||
/* Static Functions */
|
||||
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 */
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
/* Using UUID with a fixed pattern 0x97 for 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 */
|
||||
@ -101,9 +97,14 @@ static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
|
||||
static tBTA_GATTC_IF bt_mesh_gattc_if;
|
||||
#endif
|
||||
|
||||
esp_err_t bt_mesh_host_init(void)
|
||||
int bt_mesh_host_init(void)
|
||||
{
|
||||
return ESP_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_host_deinit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_mesh_hci_init(void)
|
||||
@ -138,8 +139,8 @@ 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)
|
||||
{
|
||||
tBTM_INQ_INFO *p_inq_info;
|
||||
tBTA_DM_SEARCH result;
|
||||
tBTM_INQ_INFO *p_inq_info = NULL;
|
||||
tBTA_DM_SEARCH result = {0};
|
||||
|
||||
bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr);
|
||||
result.inq_res.rssi = p_inq->rssi;
|
||||
@ -292,8 +293,8 @@ static int start_le_scan(u8_t scan_type, u16_t interval, u16_t window, u8_t filt
|
||||
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
|
||||
{
|
||||
bt_mesh_addr_t addr = {0};
|
||||
UINT8 adv_type;
|
||||
UINT8 rssi;
|
||||
u8_t adv_type = 0U;
|
||||
s8_t rssi = 0;
|
||||
|
||||
BT_DBG("%s, event = %d", __func__, event);
|
||||
|
||||
@ -315,7 +316,7 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC
|
||||
if (bt_mesh_scan_dev_found_cb != NULL) {
|
||||
bt_mesh_scan_dev_found_cb(&addr, rssi, adv_type, buf);
|
||||
}
|
||||
osi_free(buf);
|
||||
bt_mesh_free(buf);
|
||||
} else if (event == BTA_DM_INQ_CMPL_EVT) {
|
||||
BT_INFO("%s, Scan completed, number of scan response %d", __func__, p_data->inq_cmpl.num_resps);
|
||||
} else {
|
||||
@ -328,13 +329,13 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
const struct bt_mesh_adv_data *sd, size_t sd_len)
|
||||
{
|
||||
tBTA_START_ADV_CMPL_CBACK *p_start_adv_cb;
|
||||
tBTM_BLE_ADV_CHNL_MAP channel_map;
|
||||
tBLE_ADDR_TYPE addr_type_own;
|
||||
tBTA_START_ADV_CMPL_CBACK *p_start_adv_cb = NULL;
|
||||
tBTM_BLE_ADV_CHNL_MAP channel_map = 0U;
|
||||
tBLE_ADDR_TYPE addr_type_own = 0U;
|
||||
tBLE_BD_ADDR p_dir_bda = {0};
|
||||
tBTM_BLE_AFP adv_fil_pol;
|
||||
UINT8 adv_type;
|
||||
int err;
|
||||
tBTM_BLE_AFP adv_fil_pol = 0U;
|
||||
u8_t adv_type = 0U;
|
||||
int err = 0;
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
|
||||
@ -420,7 +421,7 @@ int bt_le_adv_stop(void)
|
||||
|
||||
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
|
||||
@ -468,7 +469,8 @@ int bt_le_scan_stop(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
{
|
||||
switch (event) {
|
||||
@ -480,7 +482,7 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
case BTA_GATTS_READ_EVT: {
|
||||
struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(p_data->req_data.p_data->read_req.handle);
|
||||
u8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->req_data.conn_id);
|
||||
tBTA_GATTS_RSP rsp;
|
||||
tBTA_GATTS_RSP rsp = {0};
|
||||
u8_t buf[100] = {0};
|
||||
u16_t len = 0;
|
||||
|
||||
@ -606,6 +608,11 @@ void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb)
|
||||
bt_mesh_gatts_conn_cb = cb;
|
||||
}
|
||||
|
||||
void bt_mesh_gatts_conn_cb_deregister(void)
|
||||
{
|
||||
bt_mesh_gatts_conn_cb = NULL;
|
||||
}
|
||||
|
||||
static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle)
|
||||
{
|
||||
struct bt_mesh_gatt_service *svc = NULL;
|
||||
@ -672,7 +679,7 @@ ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, const struct bt_mesh_
|
||||
void *buf, u16_t buf_len, u16_t offset,
|
||||
const void *value, u16_t value_len)
|
||||
{
|
||||
u16_t len;
|
||||
u16_t len = 0U;
|
||||
|
||||
if (offset > value_len) {
|
||||
return BLE_MESH_GATT_ERR(BLE_MESH_ATT_ERR_INVALID_OFFSET);
|
||||
@ -700,7 +707,7 @@ ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
|
||||
struct bt_mesh_gatt_attr *incl = attr->user_data;
|
||||
struct bt_mesh_uuid *uuid = incl->user_data;
|
||||
struct gatts_incl pdu = {0};
|
||||
u8_t value_len;
|
||||
u8_t value_len = 0U;
|
||||
|
||||
/* First attr points to the start handle */
|
||||
pdu.start_handle = sys_cpu_to_le16(incl->handle);
|
||||
@ -750,7 +757,7 @@ ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn,
|
||||
struct bt_mesh_gatt_char *chrc = attr->user_data;
|
||||
const struct bt_mesh_gatt_attr *next = NULL;
|
||||
struct gatts_chrc pdu = {0};
|
||||
u8_t value_len;
|
||||
u8_t value_len = 0U;
|
||||
|
||||
pdu.properties = chrc->properties;
|
||||
/* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part G] page 534:
|
||||
@ -802,8 +809,8 @@ static void bta_uuid_to_bt_mesh_uuid(tBT_UUID *bta_uuid, const struct bt_mesh_uu
|
||||
|
||||
static int gatts_register(struct bt_mesh_gatt_service *svc)
|
||||
{
|
||||
struct bt_mesh_gatt_service *last;
|
||||
u16_t handle;
|
||||
struct bt_mesh_gatt_service *last = NULL;
|
||||
u16_t handle = 0U;
|
||||
|
||||
if (sys_slist_is_empty(&bt_mesh_gatts_db)) {
|
||||
handle = 0;
|
||||
@ -814,11 +821,23 @@ static int gatts_register(struct bt_mesh_gatt_service *svc)
|
||||
handle = last->attrs[last->attr_count - 1].handle;
|
||||
BT_DBG("%s, handle = %d", __func__, handle);
|
||||
|
||||
((void) handle);
|
||||
|
||||
populate:
|
||||
sys_slist_append(&bt_mesh_gatts_db, &svc->node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gatts_deregister(struct bt_mesh_gatt_service *svc)
|
||||
{
|
||||
if (sys_slist_is_empty(&bt_mesh_gatts_db)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sys_slist_find_and_remove(&bt_mesh_gatts_db, &svc->node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static tBTA_GATT_PERM bt_mesh_perm_to_bta_perm(u8_t perm)
|
||||
{
|
||||
tBTA_GATT_PERM bta_perm = 0;
|
||||
@ -939,6 +958,17 @@ int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_gatts_service_deregister(struct bt_mesh_gatt_service *svc)
|
||||
{
|
||||
assert(svc != NULL);
|
||||
|
||||
gatts_deregister(svc);
|
||||
|
||||
BTA_GATTS_DeleteService(svc->attrs[0].handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_gatts_disconnect(struct bt_mesh_conn *conn, u8_t reason)
|
||||
{
|
||||
UNUSED(reason);
|
||||
@ -1019,7 +1049,7 @@ int bt_mesh_gatts_set_local_device_name(const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
|
||||
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
@ -1028,12 +1058,17 @@ void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb)
|
||||
bt_mesh_gattc_conn_cb = cb;
|
||||
}
|
||||
|
||||
void bt_mesh_gattc_conn_cb_deregister(void)
|
||||
{
|
||||
bt_mesh_gattc_conn_cb = NULL;
|
||||
}
|
||||
|
||||
u8_t bt_mesh_gattc_get_free_conn_count(void)
|
||||
{
|
||||
u8_t count = 0;
|
||||
u8_t i;
|
||||
u8_t count = 0U;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
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) {
|
||||
++count;
|
||||
@ -1045,9 +1080,9 @@ u8_t bt_mesh_gattc_get_free_conn_count(void)
|
||||
|
||||
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (conn == &bt_mesh_gattc_info[i].conn) {
|
||||
return bt_mesh_gattc_info[i].service_uuid;
|
||||
}
|
||||
@ -1139,7 +1174,7 @@ void bt_mesh_gattc_exchange_mtu(u8_t index)
|
||||
* ATT_MTU >= 69 for Mesh GATT Prov Service
|
||||
* ATT_NTU >= 33 for Mesh GATT Proxy Service
|
||||
*/
|
||||
u16_t conn_id;
|
||||
u16_t conn_id = 0U;
|
||||
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[index].conn.handle);
|
||||
|
||||
@ -1162,7 +1197,7 @@ u16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn)
|
||||
int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr,
|
||||
const void *data, u16_t len)
|
||||
{
|
||||
u16_t conn_id;
|
||||
u16_t conn_id = 0U;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
@ -1189,7 +1224,7 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
|
||||
* when proxy_disconnected callback comes, the proxy server
|
||||
* information and prov_link information should be cleared.
|
||||
*/
|
||||
u16_t conn_id;
|
||||
u16_t conn_id = 0U;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
@ -1214,7 +1249,7 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
|
||||
static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
{
|
||||
struct bt_mesh_conn *conn = NULL;
|
||||
u16_t handle = 0;
|
||||
u16_t handle = 0U;
|
||||
ssize_t len = 0;
|
||||
int i = 0;
|
||||
|
||||
@ -1299,9 +1334,9 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
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;
|
||||
u16_t count = 0;
|
||||
tBTA_GATT_STATUS status = 0U;
|
||||
tBTA_GATT_UNFMT write = {0};
|
||||
u16_t count = 0U;
|
||||
u16_t num = 0;
|
||||
|
||||
/* Get the characteristic num within Mesh Provisioning/Proxy Service */
|
||||
@ -1334,28 +1369,28 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
}
|
||||
|
||||
if (num != 1) {
|
||||
osi_free(result);
|
||||
bt_mesh_free(result);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!j) {
|
||||
if (!(result[0].properties & BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP)) {
|
||||
osi_free(result);
|
||||
bt_mesh_free(result);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
}
|
||||
bt_mesh_gattc_info[i].data_in_handle = result[0].attribute_handle;
|
||||
} else {
|
||||
if (!(result[0].properties & BLE_MESH_GATT_CHRC_NOTIFY)) {
|
||||
osi_free(result);
|
||||
bt_mesh_free(result);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
}
|
||||
bt_mesh_gattc_info[i].data_out_handle = result[0].attribute_handle;
|
||||
}
|
||||
|
||||
osi_free(result);
|
||||
bt_mesh_free(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
@ -1389,7 +1424,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
}
|
||||
|
||||
if (num != 1) {
|
||||
osi_free(result);
|
||||
bt_mesh_free(result);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
}
|
||||
@ -1404,7 +1439,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
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);
|
||||
bt_mesh_free(result);
|
||||
result = NULL;
|
||||
}
|
||||
break;
|
||||
@ -1587,7 +1622,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
*/
|
||||
#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);
|
||||
bt_mesh_provisioner_clear_link_info(bt_mesh_gattc_info[i].addr.val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1598,14 +1633,14 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
*/
|
||||
#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);
|
||||
bt_mesh_provisioner_clear_link_info(bt_mesh_gattc_info[i].addr.val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#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();
|
||||
bt_mesh_provisioner_pbg_count_dec();
|
||||
}
|
||||
#endif
|
||||
/* Reset corresponding gattc info */
|
||||
@ -1647,25 +1682,55 @@ void bt_mesh_conn_unref(struct bt_mesh_conn *conn)
|
||||
|
||||
void bt_mesh_gatt_init(void)
|
||||
{
|
||||
tBT_UUID app_uuid = {LEN_UUID_128, {0}};
|
||||
|
||||
BTA_GATT_SetLocalMTU(GATT_DEF_BLE_MTU_SIZE);
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
/* Fill our internal UUID with a fixed pattern 0x96 for the ble mesh */
|
||||
memset(&app_uuid.uu.uuid128, 0x96, LEN_UUID_128);
|
||||
BTA_GATTS_AppRegister(&app_uuid, bt_mesh_bta_gatts_cb);
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
tBT_UUID gatts_app_uuid = {LEN_UUID_128, {0}};
|
||||
memset(&gatts_app_uuid.uu.uuid128, BLE_MESH_GATTS_APP_UUID_BYTE, LEN_UUID_128);
|
||||
BTA_GATTS_AppRegister(&gatts_app_uuid, bt_mesh_bta_gatts_cb);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
tBT_UUID gattc_app_uuid = {LEN_UUID_128, {0}};
|
||||
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 */
|
||||
bt_mesh_gattc_info[i].wr_desc_done = false;
|
||||
}
|
||||
memset(&app_uuid.uu.uuid128, BLE_MESH_GATTC_APP_UUID_BYTE, LEN_UUID_128);
|
||||
BTA_GATTC_AppRegister(&app_uuid, bt_mesh_bta_gattc_cb);
|
||||
memset(&gattc_app_uuid.uu.uuid128, BLE_MESH_GATTC_APP_UUID_BYTE, LEN_UUID_128);
|
||||
BTA_GATTC_AppRegister(&gattc_app_uuid, bt_mesh_bta_gattc_cb);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_gatt_deinit(void)
|
||||
{
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
BTA_GATTS_AppDeregister(bt_mesh_gatts_if);
|
||||
memset(bt_mesh_gatts_addr, 0, BLE_MESH_ADDR_LEN);
|
||||
bt_mesh_gatts_if = 0U;
|
||||
svc_handle = 0U;
|
||||
char_handle = 0U;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
BTA_GATTC_AppDeregister(bt_mesh_gattc_if);
|
||||
bt_mesh_gattc_if = 0U;
|
||||
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
|
||||
memset(&bt_mesh_gattc_info[i].addr, 0, sizeof(bt_mesh_addr_t));
|
||||
bt_mesh_gattc_info[i].service_uuid = 0U;
|
||||
bt_mesh_gattc_info[i].mtu = GATT_DEF_BLE_MTU_SIZE; /* Default MTU_SIZE 23 */
|
||||
bt_mesh_gattc_info[i].wr_desc_done = false;
|
||||
bt_mesh_gattc_info[i].start_handle = 0U;
|
||||
bt_mesh_gattc_info[i].end_handle = 0U;
|
||||
bt_mesh_gattc_info[i].data_in_handle = 0U;
|
||||
bt_mesh_gattc_info[i].data_out_handle = 0U;
|
||||
bt_mesh_gattc_info[i].ccc_handle = 0U;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1778,7 +1843,7 @@ int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u
|
||||
static void ecb_encrypt(u8_t const *const key_le, u8_t const *const clear_text_le,
|
||||
u8_t *const cipher_text_le, u8_t *const cipher_text_be)
|
||||
{
|
||||
struct bt_mesh_ecb_param ecb;
|
||||
struct bt_mesh_ecb_param ecb = {0};
|
||||
mbedtls_aes_context aes_ctx = {0};
|
||||
|
||||
aes_ctx.key_bytes = 16;
|
||||
@ -1800,7 +1865,7 @@ static void ecb_encrypt(u8_t const *const key_le, u8_t const *const clear_text_l
|
||||
static void ecb_encrypt_be(u8_t const *const key_be, u8_t const *const clear_text_be,
|
||||
u8_t *const cipher_text_be)
|
||||
{
|
||||
struct bt_mesh_ecb_param ecb;
|
||||
struct bt_mesh_ecb_param ecb = {0};
|
||||
mbedtls_aes_context aes_ctx = {0};
|
||||
|
||||
aes_ctx.key_bytes = 16;
|
||||
@ -1823,8 +1888,8 @@ int bt_mesh_encrypt_le(const u8_t key[16], const u8_t plaintext[16],
|
||||
BT_DBG("enc_data %s", bt_hex(enc_data, 16));
|
||||
return 0;
|
||||
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
||||
struct tc_aes_key_sched_struct s;
|
||||
u8_t tmp[16];
|
||||
struct tc_aes_key_sched_struct s = {0};
|
||||
u8_t tmp[16] = {0};
|
||||
|
||||
BT_DBG("key %s plaintext %s", bt_hex(key, 16), bt_hex(plaintext, 16));
|
||||
|
||||
@ -1860,7 +1925,7 @@ int bt_mesh_encrypt_be(const u8_t key[16], const u8_t plaintext[16],
|
||||
|
||||
return 0;
|
||||
#else /* CONFIG_MBEDTLS_HARDWARE_AES */
|
||||
struct tc_aes_key_sched_struct s;
|
||||
struct tc_aes_key_sched_struct s = {0};
|
||||
|
||||
BT_DBG("key %s plaintext %s", bt_hex(key, 16), bt_hex(plaintext, 16));
|
||||
|
||||
|
@ -11,20 +11,13 @@
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "osi/allocator.h"
|
||||
#include "osi/mutex.h"
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "cfg_cli.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_common.h"
|
||||
#include "cfg_cli.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
|
||||
#define CID_NVAL 0xffff
|
||||
@ -86,32 +79,36 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = {
|
||||
{ OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS },
|
||||
};
|
||||
|
||||
static osi_mutex_t cfg_client_mutex;
|
||||
static bt_mesh_mutex_t cfg_client_lock;
|
||||
|
||||
static void bt_mesh_cfg_client_mutex_new(void)
|
||||
{
|
||||
static bool init;
|
||||
|
||||
if (!init) {
|
||||
osi_mutex_new(&cfg_client_mutex);
|
||||
init = true;
|
||||
if (!cfg_client_lock.mutex) {
|
||||
bt_mesh_mutex_create(&cfg_client_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_cfg_client_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&cfg_client_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_cfg_client_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&cfg_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&cfg_client_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_cfg_client_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&cfg_client_mutex);
|
||||
bt_mesh_mutex_unlock(&cfg_client_lock);
|
||||
}
|
||||
|
||||
static void timeout_handler(struct k_work *work)
|
||||
{
|
||||
struct k_delayed_work *timer = NULL;
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
u32_t opcode = 0U;
|
||||
|
||||
BT_WARN("Receive configuration status message timeout");
|
||||
|
||||
@ -122,10 +119,11 @@ static void timeout_handler(struct k_work *work)
|
||||
if (timer && !k_delayed_work_free(timer)) {
|
||||
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);
|
||||
// Don't forget to release the node at the end.
|
||||
memcpy(&ctx, &node->ctx, sizeof(ctx));
|
||||
opcode = node->opcode;
|
||||
bt_mesh_client_free_node(node);
|
||||
bt_mesh_config_client_cb_evt_to_btc(
|
||||
opcode, BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, ctx.model, &ctx, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,10 +212,10 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
|
||||
}
|
||||
|
||||
if (!k_delayed_work_free(&node->timer)) {
|
||||
bt_mesh_config_client_cb_evt_to_btc(
|
||||
node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
|
||||
// Don't forget to release the node at the end.
|
||||
u32_t opcode = node->opcode;
|
||||
bt_mesh_client_free_node(node);
|
||||
bt_mesh_config_client_cb_evt_to_btc(
|
||||
opcode, evt_type, model, ctx, (const u8_t *)status, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,7 +281,7 @@ static void state_status_u8(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t status = 0;
|
||||
u8_t status = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -343,7 +341,7 @@ static void net_key_status(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_cfg_netkey_status status = {0};
|
||||
u16_t app_idx;
|
||||
u16_t app_idx = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -689,7 +687,7 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
|
||||
int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_DEV_COMP_DATA_GET, 1);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -711,7 +709,7 @@ int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page)
|
||||
static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
|
||||
@ -727,7 +725,7 @@ static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op)
|
||||
static int set_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op, u8_t new_val)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 1);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
net_buf_simple_add_u8(&msg, new_val);
|
||||
@ -808,7 +806,7 @@ int bt_mesh_cfg_gatt_proxy_set(struct bt_mesh_msg_ctx *ctx, u8_t val)
|
||||
int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_GET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -830,7 +828,7 @@ int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay,
|
||||
u8_t new_transmit)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_SET, 2);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -854,7 +852,7 @@ int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx,
|
||||
const u8_t net_key[16])
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_ADD, 18);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !net_key) {
|
||||
return -EINVAL;
|
||||
@ -878,7 +876,7 @@ int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx,
|
||||
u16_t key_app_idx, const u8_t app_key[16])
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !app_key) {
|
||||
return -EINVAL;
|
||||
@ -902,7 +900,7 @@ int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
u16_t mod_app_idx, u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_BIND, 8);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -930,7 +928,7 @@ static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
u16_t sub_addr, u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 8);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
net_buf_simple_add_le16(&msg, elem_addr);
|
||||
@ -980,7 +978,7 @@ static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
const u8_t label[16], u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 22);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x label %s",
|
||||
ctx->net_idx, ctx->addr, elem_addr, label);
|
||||
@ -1034,7 +1032,7 @@ int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_GET, 6);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1062,7 +1060,7 @@ int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
struct bt_mesh_cfg_mod_pub *pub)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_SET, 13);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !pub) {
|
||||
return -EINVAL;
|
||||
@ -1094,7 +1092,7 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx,
|
||||
struct bt_mesh_cfg_hb_sub *sub)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_SET, 5);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !sub) {
|
||||
return -EINVAL;
|
||||
@ -1118,7 +1116,7 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx,
|
||||
int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_GET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1140,7 +1138,7 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx,
|
||||
const struct bt_mesh_cfg_hb_pub *pub)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_SET, 9);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !pub) {
|
||||
return -EINVAL;
|
||||
@ -1167,7 +1165,7 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx,
|
||||
int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_GET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1188,7 +1186,7 @@ int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx)
|
||||
int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_RESET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1211,7 +1209,7 @@ int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
struct bt_mesh_cfg_mod_pub *pub)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_VA_SET, 27);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !label || !pub) {
|
||||
return -EINVAL;
|
||||
@ -1243,7 +1241,7 @@ int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_DEL_ALL, 6);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1270,7 +1268,7 @@ static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t elem_addr, u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
net_buf_simple_add_le16(&msg, elem_addr);
|
||||
@ -1309,7 +1307,7 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx,
|
||||
const u8_t net_key[16])
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_UPDATE, 18);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !net_key) {
|
||||
return -EINVAL;
|
||||
@ -1332,7 +1330,7 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx,
|
||||
int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_DEL, 2);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1354,7 +1352,7 @@ int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx)
|
||||
int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_GET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1376,7 +1374,7 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx,
|
||||
u16_t app_idx, const u8_t app_key[16])
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_UPDATE, 19);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr || !app_key) {
|
||||
return -EINVAL;
|
||||
@ -1399,7 +1397,7 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx,
|
||||
int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t app_idx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_DEL, 3);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1421,7 +1419,7 @@ int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t
|
||||
int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_GET, 2);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1444,7 +1442,7 @@ static int node_identity_op(u32_t op, struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t net_idx, u8_t identity)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 3);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
net_buf_simple_add_le16(&msg, net_idx);
|
||||
@ -1481,7 +1479,7 @@ int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr,
|
||||
u16_t app_idx, u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_UNBIND, 8);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1509,7 +1507,7 @@ static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t elem_addr, u16_t mod_id, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
net_buf_simple_add_le16(&msg, elem_addr);
|
||||
@ -1548,7 +1546,7 @@ static int kr_phase_op(u32_t op, struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t net_idx, u8_t transition)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 3);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, op);
|
||||
net_buf_simple_add_le16(&msg, net_idx);
|
||||
@ -1584,7 +1582,7 @@ int bt_mesh_cfg_kr_phase_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t tr
|
||||
int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_GET, 2);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -1653,7 +1651,7 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
}
|
||||
|
||||
if (!client->internal_data) {
|
||||
internal = osi_calloc(sizeof(config_internal_data_t));
|
||||
internal = bt_mesh_calloc(sizeof(config_internal_data_t));
|
||||
if (!internal) {
|
||||
BT_ERR("Allocate memory for Configuration Client internal data fail");
|
||||
return -ENOMEM;
|
||||
@ -1678,3 +1676,39 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
bt_mesh_config_client_t *client = NULL;
|
||||
|
||||
if (!primary) {
|
||||
BT_ERR("Configuration Client only allowed in primary element");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!model) {
|
||||
BT_ERR("Configuration Client model is NULL");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
client = (bt_mesh_config_client_t *)model->user_data;
|
||||
if (!client) {
|
||||
BT_ERR("No Configuration Client context provided");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (client->internal_data) {
|
||||
/* Remove items from the list */
|
||||
bt_mesh_client_clear_list(client->internal_data);
|
||||
|
||||
/* Free the allocated internal data */
|
||||
bt_mesh_free(client->internal_data);
|
||||
cli->internal_data = NULL;
|
||||
}
|
||||
|
||||
client = NULL;
|
||||
|
||||
bt_mesh_cfg_client_mutex_free();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,30 +11,23 @@
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "cfg_srv.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "adv.h"
|
||||
#include "net.h"
|
||||
#include "lpn.h"
|
||||
#include "transport.h"
|
||||
#include "crypto.h"
|
||||
#include "access.h"
|
||||
#include "beacon.h"
|
||||
#include "proxy_server.h"
|
||||
#include "foundation.h"
|
||||
#include "friend.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "cfg_srv.h"
|
||||
#include "proxy_server.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
|
||||
#define DEFAULT_TTL 7
|
||||
@ -52,7 +45,7 @@ static struct label labels[CONFIG_BLE_MESH_LABEL_COUNT];
|
||||
static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
|
||||
bool primary)
|
||||
{
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
int i;
|
||||
|
||||
if (net_buf_simple_tailroom(buf) <
|
||||
@ -83,7 +76,7 @@ static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
|
||||
static int comp_get_page_0(struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t feat = 0U;
|
||||
const struct bt_mesh_comp *comp;
|
||||
const struct bt_mesh_comp *comp = NULL;
|
||||
int i;
|
||||
|
||||
comp = bt_mesh_comp_get();
|
||||
@ -127,7 +120,7 @@ static void dev_comp_data_get(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct net_buf_simple *sdu = NULL;
|
||||
u8_t page;
|
||||
u8_t page = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -166,7 +159,7 @@ static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem,
|
||||
struct net_buf_simple *buf, bool *vnd)
|
||||
{
|
||||
if (buf->len < 4) {
|
||||
u16_t id;
|
||||
u16_t id = 0U;
|
||||
|
||||
id = net_buf_simple_pull_le16(buf);
|
||||
|
||||
@ -176,7 +169,7 @@ static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem,
|
||||
|
||||
return bt_mesh_model_find(elem, id);
|
||||
} else {
|
||||
u16_t company, id;
|
||||
u16_t company = 0U, id = 0U;
|
||||
|
||||
company = net_buf_simple_pull_le16(buf);
|
||||
id = net_buf_simple_pull_le16(buf);
|
||||
@ -357,9 +350,9 @@ struct bt_mesh_app_key *bt_mesh_app_key_alloc(u16_t app_idx)
|
||||
static u8_t app_key_set(u16_t net_idx, u16_t app_idx, const u8_t val[16],
|
||||
bool update)
|
||||
{
|
||||
struct bt_mesh_app_keys *keys;
|
||||
struct bt_mesh_app_key *key;
|
||||
struct bt_mesh_subnet *sub;
|
||||
struct bt_mesh_app_keys *keys = NULL;
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx %04x update %u val %s",
|
||||
net_idx, app_idx, update, bt_hex(val, 16));
|
||||
@ -448,8 +441,8 @@ static void app_key_add(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4);
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
u8_t status;
|
||||
u16_t key_net_idx = 0U, key_app_idx = 0U;
|
||||
u8_t status = 0U;
|
||||
|
||||
key_idx_unpack(buf, &key_net_idx, &key_app_idx);
|
||||
|
||||
@ -483,8 +476,8 @@ static void app_key_update(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4);
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
u8_t status;
|
||||
u16_t key_net_idx = 0U, key_app_idx = 0U;
|
||||
u8_t status = 0U;
|
||||
|
||||
key_idx_unpack(buf, &key_net_idx, &key_app_idx);
|
||||
|
||||
@ -546,9 +539,9 @@ static void app_key_del(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_STATUS, 4);
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
struct bt_mesh_app_key *key;
|
||||
u8_t status;
|
||||
u16_t key_net_idx = 0U, key_app_idx = 0U;
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
u8_t status = 0U;
|
||||
|
||||
key_idx_unpack(buf, &key_net_idx, &key_app_idx);
|
||||
|
||||
@ -605,8 +598,8 @@ static void app_key_get(struct bt_mesh_model *model,
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_LIST,
|
||||
3 + IDX_LEN(CONFIG_BLE_MESH_APP_KEY_COUNT));
|
||||
u16_t get_idx, i, prev;
|
||||
u8_t status;
|
||||
u16_t get_idx = 0U, i = 0U, prev = 0U;
|
||||
u8_t status = 0U;
|
||||
|
||||
get_idx = net_buf_simple_pull_le16(buf);
|
||||
if (get_idx > 0xfff) {
|
||||
@ -697,13 +690,11 @@ static void beacon_set(struct bt_mesh_model *model,
|
||||
bt_mesh_store_cfg();
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (cfg->beacon) {
|
||||
bt_mesh_beacon_enable();
|
||||
} else {
|
||||
bt_mesh_beacon_disable();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
BT_WARN("Invalid Config Beacon value 0x%02x", buf->data[0]);
|
||||
@ -831,7 +822,6 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
|
||||
bt_mesh_store_cfg();
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (cfg->gatt_proxy == BLE_MESH_GATT_PROXY_DISABLED) {
|
||||
int i;
|
||||
|
||||
@ -855,7 +845,6 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
|
||||
}
|
||||
|
||||
bt_mesh_adv_update();
|
||||
#endif
|
||||
|
||||
if (cfg->hb_pub.feat & BLE_MESH_FEAT_PROXY) {
|
||||
bt_mesh_heartbeat_send();
|
||||
@ -1028,11 +1017,11 @@ static void mod_pub_get(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, pub_addr = 0U;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id, status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, pub_addr = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL, status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1075,12 +1064,12 @@ static void mod_pub_set(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t retransmit, status, pub_ttl, pub_period, cred_flag;
|
||||
u16_t elem_addr, pub_addr, pub_app_idx;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id;
|
||||
bool vnd;
|
||||
u8_t retransmit = 0U, status = 0U, pub_ttl = 0U, pub_period = 0U, cred_flag = 0U;
|
||||
u16_t elem_addr = 0U, pub_addr = 0U, pub_app_idx = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1194,7 +1183,7 @@ static struct label *va_find(const u8_t *label_uuid,
|
||||
|
||||
static u8_t va_add(u8_t *label_uuid, u16_t *addr)
|
||||
{
|
||||
struct label *update, *free_slot = NULL;
|
||||
struct label *update = NULL, *free_slot = NULL;
|
||||
|
||||
update = va_find(label_uuid, &free_slot);
|
||||
if (update) {
|
||||
@ -1221,7 +1210,7 @@ static u8_t va_add(u8_t *label_uuid, u16_t *addr)
|
||||
|
||||
static u8_t va_del(u8_t *label_uuid, u16_t *addr)
|
||||
{
|
||||
struct label *update;
|
||||
struct label *update = NULL;
|
||||
|
||||
update = va_find(label_uuid, NULL);
|
||||
if (update) {
|
||||
@ -1244,8 +1233,8 @@ static u8_t va_del(u8_t *label_uuid, u16_t *addr)
|
||||
|
||||
static size_t mod_sub_list_clear(struct bt_mesh_model *mod)
|
||||
{
|
||||
u8_t *label_uuid;
|
||||
size_t clear_count;
|
||||
u8_t *label_uuid = NULL;
|
||||
size_t clear_count = 0U;
|
||||
int i;
|
||||
|
||||
/* Unref stored labels related to this model */
|
||||
@ -1278,13 +1267,13 @@ static void mod_pub_va_set(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t retransmit, status, pub_ttl, pub_period, cred_flag;
|
||||
u16_t elem_addr, pub_addr, pub_app_idx;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *label_uuid;
|
||||
u8_t *mod_id;
|
||||
bool vnd;
|
||||
u8_t retransmit = 0U, status = 0U, pub_ttl = 0U, pub_period = 0U, cred_flag = 0U;
|
||||
u16_t elem_addr = 0U, pub_addr = 0U, pub_app_idx = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *label_uuid = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1342,7 +1331,7 @@ send_status:
|
||||
#else
|
||||
static size_t mod_sub_list_clear(struct bt_mesh_model *mod)
|
||||
{
|
||||
size_t clear_count;
|
||||
size_t clear_count = 0U;
|
||||
int i;
|
||||
|
||||
/* Unref stored labels related to this model */
|
||||
@ -1360,11 +1349,11 @@ static void mod_pub_va_set(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t *mod_id, status;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t elem_addr, pub_addr = 0U;
|
||||
bool vnd;
|
||||
u8_t *mod_id = NULL, status = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t elem_addr = 0U, pub_addr = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1436,12 +1425,12 @@ static void mod_sub_add(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, sub_addr;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, sub_addr = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
int i;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
@ -1522,13 +1511,13 @@ static void mod_sub_del(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, sub_addr;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id;
|
||||
u16_t *match;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, sub_addr = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
u16_t *match = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1598,12 +1587,12 @@ static void mod_sub_overwrite(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, sub_addr;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, sub_addr = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1667,12 +1656,12 @@ static void mod_sub_del_all(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t elem_addr;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t elem_addr = 0U;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1721,9 +1710,9 @@ static void mod_sub_get(struct bt_mesh_model *model,
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_LIST,
|
||||
5 + CONFIG_BLE_MESH_MODEL_GROUP_COUNT * 2);
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t addr, id;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t addr = 0U, id = 0U;
|
||||
int i;
|
||||
|
||||
addr = net_buf_simple_pull_le16(buf);
|
||||
@ -1777,9 +1766,9 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model,
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_LIST_VND,
|
||||
7 + CONFIG_BLE_MESH_MODEL_GROUP_COUNT * 2);
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t company, addr, id;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t company = 0U, addr = 0U, id = 0U;
|
||||
int i;
|
||||
|
||||
addr = net_buf_simple_pull_le16(buf);
|
||||
@ -1836,13 +1825,13 @@ static void mod_sub_va_add(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, sub_addr;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *label_uuid;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, sub_addr = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *label_uuid = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
int i;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
@ -1913,14 +1902,14 @@ static void mod_sub_va_del(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, sub_addr;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *label_uuid;
|
||||
u8_t *mod_id;
|
||||
u16_t *match;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, sub_addr = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *label_uuid = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
u16_t *match = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -1981,13 +1970,13 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u16_t elem_addr, sub_addr = BLE_MESH_ADDR_UNASSIGNED;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *label_uuid;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, sub_addr = BLE_MESH_ADDR_UNASSIGNED;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *label_uuid = NULL;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2047,12 +2036,12 @@ static void mod_sub_va_add(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t elem_addr;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t elem_addr = 0U;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2089,11 +2078,11 @@ static void mod_sub_va_del(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t elem_addr;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t elem_addr = 0U;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2128,11 +2117,11 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_elem *elem;
|
||||
u16_t elem_addr;
|
||||
u8_t *mod_id;
|
||||
u8_t status;
|
||||
bool vnd;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u16_t elem_addr = 0U;
|
||||
u8_t *mod_id = NULL;
|
||||
u8_t status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2184,9 +2173,9 @@ static void net_key_add(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t idx;
|
||||
int err;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u16_t idx = 0U;
|
||||
int err = 0;
|
||||
|
||||
idx = net_buf_simple_pull_le16(buf);
|
||||
if (idx > 0xfff) {
|
||||
@ -2216,7 +2205,7 @@ static void net_key_add(struct bt_mesh_model *model,
|
||||
|
||||
/* Check for already existing subnet */
|
||||
if (sub->net_idx == idx) {
|
||||
u8_t status;
|
||||
u8_t status = 0U;
|
||||
|
||||
if (memcmp(buf->data, sub->keys[0].net, 16)) {
|
||||
status = STATUS_IDX_ALREADY_STORED;
|
||||
@ -2246,10 +2235,8 @@ static void net_key_add(struct bt_mesh_model *model,
|
||||
|
||||
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);
|
||||
bt_mesh_adv_update();
|
||||
#endif
|
||||
} else {
|
||||
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
|
||||
}
|
||||
@ -2267,9 +2254,9 @@ static void net_key_update(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t idx;
|
||||
int err;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u16_t idx = 0U;
|
||||
int err = 0;
|
||||
|
||||
idx = net_buf_simple_pull_le16(buf);
|
||||
if (idx > 0xfff) {
|
||||
@ -2354,9 +2341,9 @@ static void net_key_del(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t del_idx;
|
||||
u8_t status;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u16_t del_idx = 0U;
|
||||
u8_t status = 0U;
|
||||
|
||||
del_idx = net_buf_simple_pull_le16(buf);
|
||||
if (del_idx > 0xfff) {
|
||||
@ -2403,7 +2390,7 @@ static void net_key_get(struct bt_mesh_model *model,
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_LIST,
|
||||
IDX_LEN(CONFIG_BLE_MESH_SUBNET_COUNT));
|
||||
u16_t prev, i;
|
||||
u16_t prev = 0U, i = 0U;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, OP_NET_KEY_LIST);
|
||||
|
||||
@ -2438,9 +2425,9 @@ static void node_identity_get(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_STATUS, 4);
|
||||
struct bt_mesh_subnet *sub;
|
||||
u8_t node_id;
|
||||
u16_t idx;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u8_t node_id = 0U;
|
||||
u16_t idx = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -2476,9 +2463,9 @@ static void node_identity_set(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_STATUS, 4);
|
||||
struct bt_mesh_subnet *sub;
|
||||
u8_t node_id;
|
||||
u16_t idx;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u8_t node_id = 0U;
|
||||
u16_t idx = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -2506,7 +2493,6 @@ static void node_identity_set(struct bt_mesh_model *model,
|
||||
} else {
|
||||
net_buf_simple_add_u8(&msg, STATUS_SUCCESS);
|
||||
net_buf_simple_add_le16(&msg, idx);
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
/* Section 4.2.11.1: "When the GATT Proxy state is set to
|
||||
* 0x00, the Node Identity state for all subnets shall be set
|
||||
* to 0x00 and shall not be changed."
|
||||
@ -2520,7 +2506,6 @@ static void node_identity_set(struct bt_mesh_model *model,
|
||||
}
|
||||
bt_mesh_adv_update();
|
||||
}
|
||||
#endif
|
||||
net_buf_simple_add_u8(&msg, sub->node_id);
|
||||
}
|
||||
|
||||
@ -2552,11 +2537,11 @@ static void mod_app_bind(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_STATUS, 9);
|
||||
u16_t elem_addr, key_app_idx;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id, status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, key_app_idx = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL, status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2615,11 +2600,11 @@ static void mod_app_unbind(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_STATUS, 9);
|
||||
u16_t elem_addr, key_app_idx;
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id, status;
|
||||
bool vnd;
|
||||
u16_t elem_addr = 0U, key_app_idx = 0U;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL, status = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2677,11 +2662,11 @@ static void mod_app_get(struct bt_mesh_model *model,
|
||||
9 + KEY_LIST_LEN),
|
||||
BLE_MESH_MODEL_BUF_LEN(OP_SIG_MOD_APP_LIST,
|
||||
9 + KEY_LIST_LEN)));
|
||||
struct bt_mesh_model *mod;
|
||||
struct bt_mesh_elem *elem;
|
||||
u8_t *mod_id, status;
|
||||
u16_t elem_addr;
|
||||
bool vnd;
|
||||
struct bt_mesh_model *mod = NULL;
|
||||
struct bt_mesh_elem *elem = NULL;
|
||||
u8_t *mod_id = NULL, status = 0U;
|
||||
u16_t elem_addr = 0U;
|
||||
bool vnd = false;
|
||||
|
||||
elem_addr = net_buf_simple_pull_le16(buf);
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) {
|
||||
@ -2760,9 +2745,9 @@ static void node_reset(struct bt_mesh_model *model,
|
||||
BT_ERR("%s, Unable to send Config Node Reset Status", __func__);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
bt_mesh_reset();
|
||||
#endif
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) {
|
||||
bt_mesh_reset();
|
||||
}
|
||||
}
|
||||
|
||||
static void send_friend_status(struct bt_mesh_model *model,
|
||||
@ -2841,9 +2826,9 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_STATUS, 5);
|
||||
struct bt_mesh_friend *frnd;
|
||||
u16_t lpn_addr;
|
||||
s32_t timeout;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
u16_t lpn_addr = 0U;
|
||||
s32_t timeout = 0;
|
||||
|
||||
lpn_addr = net_buf_simple_pull_le16(buf);
|
||||
|
||||
@ -2901,8 +2886,8 @@ static void send_krp_status(struct bt_mesh_model *model,
|
||||
static void krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t idx;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u16_t idx = 0U;
|
||||
|
||||
idx = net_buf_simple_pull_le16(buf);
|
||||
if (idx > 0xfff) {
|
||||
@ -2924,9 +2909,9 @@ static void krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
||||
static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_subnet *sub;
|
||||
u8_t phase;
|
||||
u16_t idx;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u8_t phase = 0U;
|
||||
u16_t idx = 0U;
|
||||
|
||||
idx = net_buf_simple_pull_le16(buf);
|
||||
phase = net_buf_simple_pull_u8(buf);
|
||||
@ -3071,8 +3056,8 @@ static void heartbeat_pub_set(struct bt_mesh_model *model,
|
||||
{
|
||||
struct hb_pub_param *param = (void *)buf->data;
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
u16_t dst, feat, idx;
|
||||
u8_t status;
|
||||
u16_t dst = 0U, feat = 0U, idx = 0U;
|
||||
u8_t status = 0U;
|
||||
|
||||
BT_DBG("src 0x%04x", ctx->addr);
|
||||
|
||||
@ -3168,8 +3153,8 @@ static void hb_sub_send_status(struct bt_mesh_model *model,
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_STATUS, 9);
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
u16_t period;
|
||||
s64_t uptime;
|
||||
u16_t period = 0U;
|
||||
s64_t uptime = 0;
|
||||
|
||||
BT_DBG("src 0x%04x status 0x%02x", ctx->addr, status);
|
||||
|
||||
@ -3209,9 +3194,9 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
u16_t sub_src, sub_dst;
|
||||
u8_t sub_period;
|
||||
s32_t period_ms;
|
||||
u16_t sub_src = 0U, sub_dst = 0U;
|
||||
u8_t sub_period = 0U;
|
||||
s32_t period_ms = 0;
|
||||
|
||||
BT_DBG("src 0x%04x", ctx->addr);
|
||||
|
||||
@ -3343,8 +3328,8 @@ static void hb_publish(struct k_work *work)
|
||||
struct bt_mesh_cfg_srv *cfg = CONTAINER_OF(work,
|
||||
struct bt_mesh_cfg_srv,
|
||||
hb_pub.timer.work);
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t period_ms;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u16_t period_ms = 0U;
|
||||
|
||||
BT_DBG("hb_pub.count: %u", cfg->hb_pub.count);
|
||||
|
||||
@ -3429,10 +3414,29 @@ int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_srv_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
|
||||
if (!cfg) {
|
||||
BT_ERR("%s, No Configuration Server context provided", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bt_mesh_cfg_reset();
|
||||
|
||||
k_delayed_work_free(&cfg->hb_pub.timer);
|
||||
cfg->hb_pub.dst = BLE_MESH_ADDR_UNASSIGNED;
|
||||
|
||||
conf = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mod_reset(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
bool vnd, bool primary, void *user_data)
|
||||
{
|
||||
size_t clear_count;
|
||||
size_t clear_count = 0U;
|
||||
|
||||
/* Clear model state that isn't otherwise cleared. E.g. AppKey
|
||||
* binding and model publication is cleared as a consequence
|
||||
|
@ -11,18 +11,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_CRYPTO)
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "crypto.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#define NET_MIC_LEN(pdu) (((pdu)[1] & 0x80) ? 8 : 4)
|
||||
#define APP_MIC_LEN(aszmic) ((aszmic) ? 8 : 4)
|
||||
@ -30,8 +23,8 @@
|
||||
int bt_mesh_aes_cmac(const u8_t key[16], struct bt_mesh_sg *sg,
|
||||
size_t sg_len, u8_t mac[16])
|
||||
{
|
||||
struct tc_aes_key_sched_struct sched;
|
||||
struct tc_cmac_struct state;
|
||||
struct tc_aes_key_sched_struct sched = {0};
|
||||
struct tc_cmac_struct state = {0};
|
||||
|
||||
if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) {
|
||||
return -EIO;
|
||||
@ -54,7 +47,7 @@ int bt_mesh_aes_cmac(const u8_t key[16], struct bt_mesh_sg *sg,
|
||||
int bt_mesh_k1(const u8_t *ikm, size_t ikm_len, const u8_t salt[16],
|
||||
const char *info, u8_t okm[16])
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_aes_cmac_one(salt, ikm, ikm_len, okm);
|
||||
if (err < 0) {
|
||||
@ -67,12 +60,12 @@ int bt_mesh_k1(const u8_t *ikm, size_t ikm_len, const u8_t salt[16],
|
||||
int bt_mesh_k2(const u8_t n[16], const u8_t *p, size_t p_len,
|
||||
u8_t net_id[1], u8_t enc_key[16], u8_t priv_key[16])
|
||||
{
|
||||
struct bt_mesh_sg sg[3];
|
||||
u8_t salt[16];
|
||||
u8_t out[16];
|
||||
u8_t t[16];
|
||||
u8_t pad;
|
||||
int err;
|
||||
struct bt_mesh_sg sg[3] = {0};
|
||||
u8_t salt[16] = {0};
|
||||
u8_t out[16] = {0};
|
||||
u8_t t[16] = {0};
|
||||
u8_t pad = 0U;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("n %s", bt_hex(n, 16));
|
||||
BT_DBG("p %s", bt_hex(p, p_len));
|
||||
@ -132,9 +125,9 @@ int bt_mesh_k2(const u8_t n[16], const u8_t *p, size_t p_len,
|
||||
int bt_mesh_k3(const u8_t n[16], u8_t out[8])
|
||||
{
|
||||
u8_t id64[] = { 'i', 'd', '6', '4', 0x01 };
|
||||
u8_t tmp[16];
|
||||
u8_t t[16];
|
||||
int err;
|
||||
u8_t tmp[16] = {0};
|
||||
u8_t t[16] = {0};
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_s1("smk3", tmp);
|
||||
if (err) {
|
||||
@ -159,9 +152,9 @@ int bt_mesh_k3(const u8_t n[16], u8_t out[8])
|
||||
int bt_mesh_k4(const u8_t n[16], u8_t out[1])
|
||||
{
|
||||
u8_t id6[] = { 'i', 'd', '6', 0x01 };
|
||||
u8_t tmp[16];
|
||||
u8_t t[16];
|
||||
int err;
|
||||
u8_t tmp[16] = {0};
|
||||
u8_t t[16] = {0};
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_s1("smk4", tmp);
|
||||
if (err) {
|
||||
@ -186,8 +179,8 @@ int bt_mesh_k4(const u8_t n[16], u8_t out[1])
|
||||
int bt_mesh_id128(const u8_t n[16], const char *s, u8_t out[16])
|
||||
{
|
||||
const char *id128 = "id128\x01";
|
||||
u8_t salt[16];
|
||||
int err;
|
||||
u8_t salt[16] = {0};
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_s1(s, salt);
|
||||
if (err) {
|
||||
@ -202,10 +195,11 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13],
|
||||
const u8_t *aad, size_t aad_len,
|
||||
u8_t *out_msg, size_t mic_size)
|
||||
{
|
||||
u8_t msg[16], pmsg[16], cmic[16], cmsg[16], Xn[16], mic[16];
|
||||
u16_t last_blk, blk_cnt;
|
||||
size_t i, j;
|
||||
int err;
|
||||
u8_t msg[16] = {0}, pmsg[16] = {0}, cmic[16] = {0},
|
||||
cmsg[16] = {0}, Xn[16] = {0}, mic[16] = {0};
|
||||
u16_t last_blk = 0U, blk_cnt = 0U;
|
||||
size_t i = 0U, j = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (msg_len < 1 || aad_len >= 0xff00) {
|
||||
return -EINVAL;
|
||||
@ -360,10 +354,11 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13],
|
||||
const u8_t *aad, size_t aad_len,
|
||||
u8_t *out_msg, size_t mic_size)
|
||||
{
|
||||
u8_t pmsg[16], cmic[16], cmsg[16], mic[16], Xn[16];
|
||||
u16_t blk_cnt, last_blk;
|
||||
size_t i, j;
|
||||
int err;
|
||||
u8_t pmsg[16] = {0}, cmic[16] = {0}, cmsg[16] = {0},
|
||||
mic[16] = {0}, Xn[16] = {0};
|
||||
u16_t blk_cnt = 0U, last_blk = 0U;
|
||||
size_t i = 0U, j = 0U;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("key %s", bt_hex(key, 16));
|
||||
BT_DBG("nonce %s", bt_hex(nonce, 13));
|
||||
@ -573,8 +568,8 @@ int bt_mesh_net_obfuscate(u8_t *pdu, u32_t iv_index,
|
||||
const u8_t privacy_key[16])
|
||||
{
|
||||
u8_t priv_rand[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, };
|
||||
u8_t tmp[16];
|
||||
int err, i;
|
||||
u8_t tmp[16] = {0};
|
||||
int err = 0, i;
|
||||
|
||||
BT_DBG("IVIndex %u, PrivacyKey %s", iv_index, bt_hex(privacy_key, 16));
|
||||
|
||||
@ -599,8 +594,8 @@ int bt_mesh_net_encrypt(const u8_t key[16], struct net_buf_simple *buf,
|
||||
u32_t iv_index, bool proxy)
|
||||
{
|
||||
u8_t mic_len = NET_MIC_LEN(buf->data);
|
||||
u8_t nonce[13];
|
||||
int err;
|
||||
u8_t nonce[13] = {0};
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("IVIndex %u EncKey %s mic_len %u", iv_index, bt_hex(key, 16),
|
||||
mic_len);
|
||||
@ -631,7 +626,7 @@ int bt_mesh_net_decrypt(const u8_t key[16], struct net_buf_simple *buf,
|
||||
u32_t iv_index, bool proxy)
|
||||
{
|
||||
u8_t mic_len = NET_MIC_LEN(buf->data);
|
||||
u8_t nonce[13];
|
||||
u8_t nonce[13] = {0};
|
||||
|
||||
BT_DBG("PDU (%u bytes) %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
BT_DBG("iv_index %u, key %s mic_len %u", iv_index, bt_hex(key, 16),
|
||||
@ -677,8 +672,8 @@ int bt_mesh_app_encrypt(const u8_t key[16], bool dev_key, u8_t aszmic,
|
||||
struct net_buf_simple *buf, const u8_t *ad,
|
||||
u16_t src, u16_t dst, u32_t seq_num, u32_t iv_index)
|
||||
{
|
||||
u8_t nonce[13];
|
||||
int err;
|
||||
u8_t nonce[13] = {0};
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("AppKey %s", bt_hex(key, 16));
|
||||
BT_DBG("dev_key %u src 0x%04x dst 0x%04x", dev_key, src, dst);
|
||||
@ -704,8 +699,8 @@ int bt_mesh_app_decrypt(const u8_t key[16], bool dev_key, u8_t aszmic,
|
||||
const u8_t *ad, u16_t src, u16_t dst, u32_t seq_num,
|
||||
u32_t iv_index)
|
||||
{
|
||||
u8_t nonce[13];
|
||||
int err;
|
||||
u8_t nonce[13] = {0};
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("EncData (len %u) %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
@ -794,9 +789,9 @@ bool bt_mesh_fcs_check(struct net_buf_simple *buf, u8_t received_fcs)
|
||||
|
||||
int bt_mesh_virtual_addr(const u8_t virtual_label[16], u16_t *addr)
|
||||
{
|
||||
u8_t salt[16];
|
||||
u8_t tmp[16];
|
||||
int err;
|
||||
u8_t salt[16] = {0};
|
||||
u8_t tmp[16] = {0};
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_s1("vtad", salt);
|
||||
if (err) {
|
||||
@ -856,8 +851,8 @@ int bt_mesh_beacon_auth(const u8_t beacon_key[16], u8_t flags,
|
||||
const u8_t net_id[8], u32_t iv_index,
|
||||
u8_t auth[8])
|
||||
{
|
||||
u8_t msg[13], tmp[16];
|
||||
int err;
|
||||
u8_t msg[13] = {0}, tmp[16] = {0};
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("BeaconKey %s", bt_hex(beacon_key, 16));
|
||||
BT_DBG("NetId %s", bt_hex(net_id, 8));
|
||||
|
@ -10,8 +10,8 @@
|
||||
#ifndef _CRYPTO_H_
|
||||
#define _CRYPTO_H_
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include <string.h>
|
||||
#include "mesh_buf.h"
|
||||
|
||||
struct bt_mesh_sg {
|
||||
const void *data;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#ifndef _FOUNDATION_H_
|
||||
#define _FOUNDATION_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "net.h"
|
||||
|
||||
#define OP_APP_KEY_ADD BLE_MESH_MODEL_OP_1(0x00)
|
||||
@ -131,9 +130,15 @@ struct label {
|
||||
int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary);
|
||||
int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
int bt_mesh_cfg_srv_deinit(struct bt_mesh_model *model, bool primary);
|
||||
int bt_mesh_health_srv_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
void bt_mesh_cfg_reset(void);
|
||||
|
||||
void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat);
|
||||
|
@ -10,23 +10,16 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_FRIEND)
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_trace.h"
|
||||
|
||||
#include "crypto.h"
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "friend.h"
|
||||
#include "client_common.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_main.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
#ifdef CONFIG_BLE_MESH_FRIEND
|
||||
@ -81,7 +74,7 @@ static struct bt_mesh_subnet *friend_subnet_get(u16_t net_idx)
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
|
||||
sub = bt_mesh_subnet_get(net_idx);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(net_idx);
|
||||
sub = bt_mesh_provisioner_subnet_get(net_idx);
|
||||
}
|
||||
|
||||
return sub;
|
||||
@ -135,7 +128,7 @@ struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr,
|
||||
static void purge_buffers(sys_slist_t *list)
|
||||
{
|
||||
while (!sys_slist_is_empty(list)) {
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
buf = (void *)sys_slist_get_not_empty(list);
|
||||
|
||||
@ -248,15 +241,15 @@ void bt_mesh_friend_sec_update(u16_t net_idx)
|
||||
int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_clear *msg = (void *)buf->data;
|
||||
struct bt_mesh_friend *frnd;
|
||||
u16_t lpn_addr, lpn_counter;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
u16_t lpn_addr = 0U, lpn_counter = 0U;
|
||||
struct bt_mesh_net_tx tx = {
|
||||
.sub = rx->sub,
|
||||
.ctx = &rx->ctx,
|
||||
.src = bt_mesh_primary_addr(),
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
struct bt_mesh_ctl_friend_clear_confirm cfm;
|
||||
struct bt_mesh_ctl_friend_clear_confirm cfm = {0};
|
||||
|
||||
if (buf->len < sizeof(*msg)) {
|
||||
BT_WARN("%s, Too short Friend Clear", __func__);
|
||||
@ -329,7 +322,7 @@ static struct net_buf *create_friend_pdu(struct bt_mesh_friend *frnd,
|
||||
struct friend_pdu_info *info,
|
||||
struct net_buf_simple *sdu)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
buf = bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_alloc,
|
||||
BLE_MESH_ADV_DATA,
|
||||
@ -370,8 +363,8 @@ static int unseg_app_sdu_unpack(struct bt_mesh_friend *frnd,
|
||||
struct unseg_app_sdu_meta *meta)
|
||||
{
|
||||
u16_t app_idx = FRIEND_ADV(buf)->app_idx;
|
||||
u8_t role;
|
||||
int err;
|
||||
u8_t role = 0U;
|
||||
int err = 0;
|
||||
|
||||
meta->subnet = friend_subnet_get(frnd->net_idx);
|
||||
if (!meta->subnet) {
|
||||
@ -408,7 +401,7 @@ static int unseg_app_sdu_decrypt(struct bt_mesh_friend *frnd,
|
||||
struct net_buf *buf,
|
||||
const struct unseg_app_sdu_meta *meta)
|
||||
{
|
||||
struct net_buf_simple sdu;
|
||||
struct net_buf_simple sdu = {0};
|
||||
|
||||
net_buf_simple_clone(&buf->b, &sdu);
|
||||
net_buf_simple_pull(&sdu, 10);
|
||||
@ -424,7 +417,7 @@ static int unseg_app_sdu_encrypt(struct bt_mesh_friend *frnd,
|
||||
struct net_buf *buf,
|
||||
const struct unseg_app_sdu_meta *meta)
|
||||
{
|
||||
struct net_buf_simple sdu;
|
||||
struct net_buf_simple sdu = {0};
|
||||
|
||||
net_buf_simple_clone(&buf->b, &sdu);
|
||||
net_buf_simple_pull(&sdu, 10);
|
||||
@ -439,8 +432,8 @@ static int unseg_app_sdu_encrypt(struct bt_mesh_friend *frnd,
|
||||
static int unseg_app_sdu_prepare(struct bt_mesh_friend *frnd,
|
||||
struct net_buf *buf)
|
||||
{
|
||||
struct unseg_app_sdu_meta meta;
|
||||
int err;
|
||||
struct unseg_app_sdu_meta meta = {0};
|
||||
int err = 0;
|
||||
|
||||
if (FRIEND_ADV(buf)->app_idx == BLE_MESH_KEY_UNUSED) {
|
||||
return 0;
|
||||
@ -476,11 +469,11 @@ static int encrypt_friend_pdu(struct bt_mesh_friend *frnd, struct net_buf *buf,
|
||||
bool master_cred)
|
||||
{
|
||||
struct bt_mesh_subnet *sub = friend_subnet_get(frnd->net_idx);
|
||||
const u8_t *enc, *priv;
|
||||
u32_t iv_index;
|
||||
u16_t src;
|
||||
u8_t nid;
|
||||
int err;
|
||||
const u8_t *enc = NULL, *priv = NULL;
|
||||
u32_t iv_index = 0U;
|
||||
u16_t src = 0U;
|
||||
u8_t nid = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (!sub) {
|
||||
BT_ERR("Invalid subnet to encrypt friend pdu");
|
||||
@ -540,7 +533,7 @@ static struct net_buf *encode_friend_ctl(struct bt_mesh_friend *frnd,
|
||||
u8_t ctl_op,
|
||||
struct net_buf_simple *sdu)
|
||||
{
|
||||
struct friend_pdu_info info;
|
||||
struct friend_pdu_info info = {0};
|
||||
|
||||
BT_DBG("LPN 0x%04x", frnd->lpn);
|
||||
|
||||
@ -561,7 +554,7 @@ static struct net_buf *encode_friend_ctl(struct bt_mesh_friend *frnd,
|
||||
|
||||
static struct net_buf *encode_update(struct bt_mesh_friend *frnd, u8_t md)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_update *upd;
|
||||
struct bt_mesh_ctl_friend_update *upd = NULL;
|
||||
NET_BUF_SIMPLE_DEFINE(sdu, 1 + sizeof(*upd));
|
||||
struct bt_mesh_subnet *sub = friend_subnet_get(frnd->net_idx);
|
||||
|
||||
@ -581,9 +574,9 @@ static struct net_buf *encode_update(struct bt_mesh_friend *frnd, u8_t md)
|
||||
|
||||
static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_sub_confirm *cfm;
|
||||
struct bt_mesh_ctl_friend_sub_confirm *cfm = NULL;
|
||||
NET_BUF_SIMPLE_DEFINE(sdu, 1 + sizeof(*cfm));
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("lpn 0x%04x xact 0x%02x", frnd->lpn, xact);
|
||||
|
||||
@ -615,14 +608,14 @@ static void friend_recv_delay(struct bt_mesh_friend *frnd)
|
||||
{
|
||||
frnd->pending_req = 1U;
|
||||
k_delayed_work_submit(&frnd->timer, recv_delay(frnd));
|
||||
BT_DBG("Waiting RecvDelay of %d ms", recv_delay(frnd));
|
||||
BT_INFO("Waiting RecvDelay of %d ms", recv_delay(frnd));
|
||||
}
|
||||
|
||||
int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_friend *frnd;
|
||||
u8_t xact;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
u8_t xact = 0U;
|
||||
|
||||
if (buf->len < BLE_MESH_FRIEND_SUB_MIN_LEN) {
|
||||
BT_WARN("%s, Too short Friend Subscription Add", __func__);
|
||||
@ -656,8 +649,8 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
|
||||
int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_friend *frnd;
|
||||
u8_t xact;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
u8_t xact = 0U;
|
||||
|
||||
if (buf->len < BLE_MESH_FRIEND_SUB_MIN_LEN) {
|
||||
BT_WARN("%s, Too short Friend Subscription Remove", __func__);
|
||||
@ -696,7 +689,7 @@ static void enqueue_buf(struct bt_mesh_friend *frnd, struct net_buf *buf)
|
||||
|
||||
static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
buf = encode_update(frnd, md);
|
||||
if (!buf) {
|
||||
@ -711,7 +704,7 @@ static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md)
|
||||
int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_poll *msg = (void *)buf->data;
|
||||
struct bt_mesh_friend *frnd;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
|
||||
if (buf->len < sizeof(*msg)) {
|
||||
BT_WARN("%s, Too short Friend Poll", __func__);
|
||||
@ -739,7 +732,7 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
friend_recv_delay(frnd);
|
||||
|
||||
if (!frnd->established) {
|
||||
BT_DBG("Friendship established with 0x%04x", frnd->lpn);
|
||||
BT_INFO("Friendship established with 0x%04x", frnd->lpn);
|
||||
frnd->established = 1U;
|
||||
if (friend_cb) {
|
||||
friend_cb(true, frnd->lpn, 0);
|
||||
@ -828,7 +821,7 @@ static void clear_timeout(struct k_work *work)
|
||||
{
|
||||
struct bt_mesh_friend *frnd = CONTAINER_OF(work, struct bt_mesh_friend,
|
||||
clear.timer.work);
|
||||
u32_t duration;
|
||||
u32_t duration = 0U;
|
||||
|
||||
BT_DBG("LPN 0x%04x (old) Friend 0x%04x", frnd->lpn, frnd->clear.frnd);
|
||||
|
||||
@ -856,8 +849,8 @@ int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_clear_confirm *msg = (void *)buf->data;
|
||||
struct bt_mesh_friend *frnd;
|
||||
u16_t lpn_addr, lpn_counter;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
u16_t lpn_addr = 0U, lpn_counter = 0U;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -894,9 +887,9 @@ int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx,
|
||||
|
||||
static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_offer *off;
|
||||
struct bt_mesh_ctl_friend_offer *off = NULL;
|
||||
NET_BUF_SIMPLE_DEFINE(sdu, 1 + sizeof(*off));
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -942,9 +935,9 @@ static s32_t offer_delay(struct bt_mesh_friend *frnd, s8_t rssi, u8_t crit)
|
||||
* want to avoid floating-point arithmetic.
|
||||
*/
|
||||
static const u8_t fact[] = { 10, 15, 20, 25 };
|
||||
s32_t delay;
|
||||
s32_t delay = 0;
|
||||
|
||||
BT_DBG("ReceiveWindowFactor %u ReceiveWindow %u RSSIFactor %u RSSI %d",
|
||||
BT_INFO("ReceiveWindowFactor %u ReceiveWindow %u RSSIFactor %u RSSI %d",
|
||||
fact[RECV_WIN_FACT(crit)], RECV_WIN,
|
||||
fact[RSSI_FACT(crit)], rssi);
|
||||
|
||||
@ -966,7 +959,7 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_ctl_friend_req *msg = (void *)buf->data;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
u32_t poll_to;
|
||||
u32_t poll_to = 0U;
|
||||
int i;
|
||||
|
||||
if (buf->len < sizeof(*msg)) {
|
||||
@ -1039,7 +1032,7 @@ init_friend:
|
||||
frnd->lpn_counter = sys_be16_to_cpu(msg->lpn_counter);
|
||||
frnd->clear.frnd = sys_be16_to_cpu(msg->prev_addr);
|
||||
|
||||
BT_DBG("LPN 0x%04x rssi %d recv_delay %u poll_to %ums",
|
||||
BT_INFO("LPN 0x%04x rssi %d recv_delay %u poll_to %ums",
|
||||
frnd->lpn, rx->ctx.recv_rssi, frnd->recv_delay, frnd->poll_to);
|
||||
|
||||
/**
|
||||
@ -1069,9 +1062,9 @@ init_friend:
|
||||
static bool is_seg(struct bt_mesh_friend_seg *seg, u16_t src, u16_t seq_zero)
|
||||
{
|
||||
struct net_buf *buf = (void *)sys_slist_peek_head(&seg->queue);
|
||||
struct net_buf_simple_state state;
|
||||
u16_t buf_seq_zero;
|
||||
u16_t buf_src;
|
||||
struct net_buf_simple_state state = {0};
|
||||
u16_t buf_seq_zero = 0U;
|
||||
u16_t buf_src = 0U;
|
||||
|
||||
if (!buf) {
|
||||
return false;
|
||||
@ -1118,7 +1111,7 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd,
|
||||
u16_t src, u8_t seg_count,
|
||||
struct net_buf *buf)
|
||||
{
|
||||
struct bt_mesh_friend_seg *seg;
|
||||
struct bt_mesh_friend_seg *seg = NULL;
|
||||
|
||||
BT_DBG("type %u", type);
|
||||
|
||||
@ -1272,9 +1265,30 @@ int bt_mesh_friend_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_friend_deinit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
|
||||
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
|
||||
|
||||
frnd->net_idx = BLE_MESH_KEY_UNUSED;
|
||||
|
||||
k_delayed_work_free(&frnd->timer);
|
||||
k_delayed_work_free(&frnd->clear.timer);
|
||||
}
|
||||
|
||||
bt_mesh_unref_buf_from_pool(&friend_buf_pool);
|
||||
memset(adv_pool, 0, sizeof(adv_pool));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool is_segack(struct net_buf *buf, u64_t *seqauth, u16_t src)
|
||||
{
|
||||
struct net_buf_simple_state state;
|
||||
struct net_buf_simple_state state = {0};
|
||||
bool found = false;
|
||||
|
||||
if (buf->len != 16) {
|
||||
@ -1311,7 +1325,7 @@ end:
|
||||
static void friend_purge_old_ack(struct bt_mesh_friend *frnd, u64_t *seq_auth,
|
||||
u16_t src)
|
||||
{
|
||||
sys_snode_t *cur, *prev = NULL;
|
||||
sys_snode_t *cur = NULL, *prev = NULL;
|
||||
|
||||
BT_DBG("SeqAuth %llx src 0x%04x", *seq_auth, src);
|
||||
|
||||
@ -1339,8 +1353,8 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
|
||||
u64_t *seq_auth, u8_t seg_count,
|
||||
struct net_buf_simple *sbuf)
|
||||
{
|
||||
struct friend_pdu_info info;
|
||||
struct net_buf *buf;
|
||||
struct friend_pdu_info info = {0};
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
/* Because of network loopback, tx packets will also be passed into
|
||||
* this rx function. These packets have already been added to the
|
||||
@ -1391,8 +1405,8 @@ static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd,
|
||||
u64_t *seq_auth, u8_t seg_count,
|
||||
struct net_buf_simple *sbuf)
|
||||
{
|
||||
struct friend_pdu_info info;
|
||||
struct net_buf *buf;
|
||||
struct friend_pdu_info info = {0};
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("LPN 0x%04x", frnd->lpn);
|
||||
|
||||
@ -1545,8 +1559,8 @@ bool bt_mesh_friend_queue_has_space(u16_t net_idx, u16_t src, u16_t dst,
|
||||
static bool friend_queue_prepare_space(struct bt_mesh_friend *frnd, u16_t addr,
|
||||
u64_t *seq_auth, u8_t seg_count)
|
||||
{
|
||||
bool pending_segments;
|
||||
u8_t avail_space;
|
||||
bool pending_segments = false;
|
||||
u8_t avail_space = 0U;
|
||||
|
||||
if (!friend_queue_has_space(frnd, addr, seq_auth, seg_count)) {
|
||||
return false;
|
||||
@ -1683,7 +1697,7 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src,
|
||||
|
||||
void bt_mesh_friend_remove_lpn(u16_t lpn_addr)
|
||||
{
|
||||
struct bt_mesh_friend *frnd;
|
||||
struct bt_mesh_friend *frnd = NULL;
|
||||
|
||||
frnd = bt_mesh_friend_find(BLE_MESH_KEY_ANY, lpn_addr, false, false);
|
||||
if (frnd) {
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef _FRIEND_H_
|
||||
#define _FRIEND_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
enum bt_mesh_friend_pdu_type {
|
||||
BLE_MESH_FRIEND_PDU_SINGLE,
|
||||
BLE_MESH_FRIEND_PDU_PARTIAL,
|
||||
@ -50,6 +52,7 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
int bt_mesh_friend_init(void);
|
||||
int bt_mesh_friend_deinit(void);
|
||||
|
||||
void bt_mesh_friend_remove_lpn(u16_t lpn_addr);
|
||||
|
||||
|
@ -9,20 +9,13 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "osi/allocator.h"
|
||||
#include "osi/mutex.h"
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "health_cli.h"
|
||||
|
||||
#include "foundation.h"
|
||||
#include "mesh_common.h"
|
||||
#include "health_cli.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
|
||||
s32_t health_msg_timeout;
|
||||
@ -39,32 +32,36 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = {
|
||||
{ OP_ATTENTION_SET, OP_ATTENTION_STATUS },
|
||||
};
|
||||
|
||||
static osi_mutex_t health_client_mutex;
|
||||
static bt_mesh_mutex_t health_client_lock;
|
||||
|
||||
static void bt_mesh_health_client_mutex_new(void)
|
||||
{
|
||||
static bool init;
|
||||
|
||||
if (!init) {
|
||||
osi_mutex_new(&health_client_mutex);
|
||||
init = true;
|
||||
if (!health_client_lock.mutex) {
|
||||
bt_mesh_mutex_create(&health_client_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_health_client_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&health_client_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_health_client_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&health_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&health_client_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_health_client_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&health_client_mutex);
|
||||
bt_mesh_mutex_unlock(&health_client_lock);
|
||||
}
|
||||
|
||||
static void timeout_handler(struct k_work *work)
|
||||
{
|
||||
struct k_delayed_work *timer = NULL;
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
u32_t opcode = 0U;
|
||||
|
||||
BT_WARN("Receive health status message timeout");
|
||||
|
||||
@ -75,10 +72,11 @@ static void timeout_handler(struct k_work *work)
|
||||
if (timer && !k_delayed_work_free(timer)) {
|
||||
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);
|
||||
// Don't forget to release the node at the end.
|
||||
memcpy(&ctx, &node->ctx, sizeof(ctx));
|
||||
opcode = node->opcode;
|
||||
bt_mesh_client_free_node(node);
|
||||
bt_mesh_health_client_cb_evt_to_btc(
|
||||
opcode, BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, ctx.model, &ctx, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,10 +125,10 @@ static void health_client_cancel(struct bt_mesh_model *model,
|
||||
}
|
||||
|
||||
if (!k_delayed_work_free(&node->timer)) {
|
||||
bt_mesh_health_client_cb_evt_to_btc(
|
||||
node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
|
||||
// Don't forget to release the node at the end.
|
||||
u32_t opcode = node->opcode;
|
||||
bt_mesh_client_free_node(node);
|
||||
bt_mesh_health_client_cb_evt_to_btc(
|
||||
opcode, evt_type, model, ctx, (const u8_t *)status, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,8 +174,8 @@ static void health_current_status(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
u8_t test_id;
|
||||
u16_t cid;
|
||||
u8_t test_id = 0U;
|
||||
u16_t cid = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -193,13 +191,16 @@ static void health_current_status(struct bt_mesh_model *model,
|
||||
|
||||
BT_DBG("Test ID 0x%02x Company ID 0x%04x Fault Count %u",
|
||||
test_id, cid, buf->len);
|
||||
|
||||
((void) test_id);
|
||||
((void) cid);
|
||||
}
|
||||
|
||||
static void health_period_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t status = 0;
|
||||
u8_t status = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -214,7 +215,7 @@ static void health_attention_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t status = 0;
|
||||
u8_t status = 0U;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -236,7 +237,7 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = {
|
||||
int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_GET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -258,8 +259,8 @@ int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx,
|
||||
u8_t attention, bool need_ack)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_SET, 1);
|
||||
u32_t opcode;
|
||||
int err;
|
||||
u32_t opcode = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -286,7 +287,7 @@ int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx,
|
||||
int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_GET, 0);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -308,8 +309,8 @@ int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx,
|
||||
u8_t divisor, bool need_ack)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_SET, 1);
|
||||
u32_t opcode;
|
||||
int err;
|
||||
u32_t opcode = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -337,8 +338,8 @@ int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t cid, u8_t test_id, bool need_ack)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_TEST, 3);
|
||||
u32_t opcode;
|
||||
int err;
|
||||
u32_t opcode = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -367,8 +368,8 @@ int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx,
|
||||
u16_t cid, bool need_ack)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_CLEAR, 2);
|
||||
u32_t opcode;
|
||||
int err;
|
||||
u32_t opcode = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -395,7 +396,7 @@ int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx,
|
||||
int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid)
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_GET, 2);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!ctx || !ctx->addr) {
|
||||
return -EINVAL;
|
||||
@ -455,7 +456,7 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
}
|
||||
|
||||
if (!client->internal_data) {
|
||||
internal = osi_calloc(sizeof(health_internal_data_t));
|
||||
internal = bt_mesh_calloc(sizeof(health_internal_data_t));
|
||||
if (!internal) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
@ -480,3 +481,36 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
bt_mesh_health_client_t *client = NULL;
|
||||
|
||||
if (!model) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
client = (bt_mesh_health_client_t *)model->user_data;
|
||||
if (!client) {
|
||||
BT_ERR("%s, No Health Client context provided", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (client->internal_data) {
|
||||
/* Remove items from the list */
|
||||
bt_mesh_client_clear_list(client->internal_data);
|
||||
|
||||
/* Free the allocated internal data */
|
||||
bt_mesh_free(client->internal_data);
|
||||
client->internal_data = NULL;
|
||||
}
|
||||
|
||||
bt_mesh_health_client_mutex_free();
|
||||
|
||||
if (health_cli) {
|
||||
health_cli = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,23 +9,13 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "health_srv.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "adv.h"
|
||||
#include "net.h"
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_common.h"
|
||||
#include "health_srv.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
|
||||
@ -49,8 +39,8 @@ struct bt_mesh_health_srv *health_srv;
|
||||
static u8_t health_get_curr_fault_count(struct bt_mesh_model *model)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
u8_t count = 0;
|
||||
size_t i;
|
||||
u8_t count = 0U;
|
||||
size_t i = 0U;
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(srv->test.curr_faults); i++) {
|
||||
if (srv->test.curr_faults[i] != HEALTH_NO_FAULT) {
|
||||
@ -66,8 +56,8 @@ static void health_get_fault_value(struct bt_mesh_model *model,
|
||||
bool current)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
size_t array_size;
|
||||
size_t i;
|
||||
size_t array_size = 0U;
|
||||
size_t i = 0U;
|
||||
|
||||
array_size = current ? ARRAY_SIZE(srv->test.curr_faults) : ARRAY_SIZE(srv->test.reg_faults);
|
||||
|
||||
@ -86,9 +76,9 @@ static void health_get_fault_value(struct bt_mesh_model *model,
|
||||
static bool health_is_test_id_exist(struct bt_mesh_model *model, u8_t test_id)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < srv->test.id_count; i++) {
|
||||
for (i = 0; i < srv->test.id_count; i++) {
|
||||
if (srv->test.test_ids[i] == test_id) {
|
||||
return true;
|
||||
}
|
||||
@ -102,7 +92,7 @@ static int health_send_fault_status(struct bt_mesh_model *model,
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
struct net_buf_simple *msg = NULL;
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
msg = bt_mesh_alloc_buf(4 + ARRAY_SIZE(srv->test.reg_faults) + 4);
|
||||
if (!msg) {
|
||||
@ -135,7 +125,7 @@ static void health_fault_get(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
u16_t company_id;
|
||||
u16_t company_id = 0U;
|
||||
|
||||
if (!srv) {
|
||||
BT_ERR("%s, No Health Server context provided", __func__);
|
||||
@ -158,7 +148,7 @@ static void health_fault_clear(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
u16_t company_id;
|
||||
u16_t company_id = 0U;
|
||||
|
||||
if (!srv) {
|
||||
BT_ERR("%s, No Health Server context provided", __func__);
|
||||
@ -189,8 +179,8 @@ static void health_fault_test(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
u16_t company_id;
|
||||
u8_t test_id;
|
||||
u16_t company_id = 0U;
|
||||
u8_t test_id = 0U;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -229,7 +219,7 @@ static void send_attention_status(struct bt_mesh_model *model,
|
||||
{
|
||||
BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_STATUS, 1);
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
u8_t time;
|
||||
u8_t time = 0U;
|
||||
|
||||
if (!srv) {
|
||||
BT_ERR("%s, No Health Server context provided", __func__);
|
||||
@ -260,7 +250,7 @@ static void health_set_attention(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t time;
|
||||
u8_t time = 0U;
|
||||
|
||||
time = net_buf_simple_pull_u8(buf);
|
||||
|
||||
@ -308,7 +298,7 @@ static void health_set_period(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t period;
|
||||
u8_t period = 0U;
|
||||
|
||||
period = net_buf_simple_pull_u8(buf);
|
||||
if (period > 15) {
|
||||
@ -375,7 +365,7 @@ static size_t health_get_current(struct bt_mesh_model *model,
|
||||
static int health_pub_update(struct bt_mesh_model *model)
|
||||
{
|
||||
struct bt_mesh_model_pub *pub = model->pub;
|
||||
size_t count;
|
||||
size_t count = 0U;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -396,7 +386,7 @@ static int health_pub_update(struct bt_mesh_model *model)
|
||||
|
||||
int bt_mesh_fault_update(struct bt_mesh_elem *elem)
|
||||
{
|
||||
struct bt_mesh_model *model;
|
||||
struct bt_mesh_model *model = NULL;
|
||||
|
||||
model = bt_mesh_model_find(elem, BLE_MESH_MODEL_ID_HEALTH_SRV);
|
||||
if (!model) {
|
||||
@ -484,9 +474,45 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_health_srv_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv = model->user_data;
|
||||
|
||||
if (!srv) {
|
||||
if (!primary) {
|
||||
/* If Health Server is in the secondary element with NULL user_data. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
BT_ERR("%s, No Health Server context provided", __func__);
|
||||
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;
|
||||
}
|
||||
|
||||
model->pub->addr = BLE_MESH_ADDR_UNASSIGNED;
|
||||
model->pub->update = NULL;
|
||||
|
||||
k_delayed_work_free(&srv->attn_timer);
|
||||
|
||||
if (primary) {
|
||||
health_srv = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_mesh_attention(struct bt_mesh_model *model, u8_t time)
|
||||
{
|
||||
struct bt_mesh_health_srv *srv;
|
||||
struct bt_mesh_health_srv *srv = NULL;
|
||||
|
||||
if (!model) {
|
||||
srv = health_srv;
|
||||
|
@ -11,8 +11,6 @@
|
||||
#ifndef _BLE_MESH_CFG_CLI_H_
|
||||
#define _BLE_MESH_CFG_CLI_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "client_common.h"
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define _BLE_MESH_CFG_SRV_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh
|
||||
|
@ -11,8 +11,6 @@
|
||||
#ifndef _BLE_MESH_HEALTH_CLI_H_
|
||||
#define _BLE_MESH_HEALTH_CLI_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "client_common.h"
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define _BLE_MESH_HEALTH_SRV_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Health Server Model
|
||||
|
@ -11,11 +11,10 @@
|
||||
#ifndef _BLE_MESH_ACCESS_H_
|
||||
#define _BLE_MESH_ACCESS_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Access Layer
|
||||
|
@ -9,31 +9,33 @@
|
||||
#ifndef _BLE_MESH_BEARER_ADRPT_H_
|
||||
#define _BLE_MESH_BEARER_ADRPT_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_uuid.h"
|
||||
#include "mesh_buf.h"
|
||||
|
||||
/* BLE Mesh Max Connection Count */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#define BLE_MESH_MAX_CONN \
|
||||
MIN(CONFIG_BT_ACL_CONNECTIONS, CONFIG_BTDM_CTRL_BLE_MAX_CONN)
|
||||
|
||||
#define ADV_TASK_CORE TASK_PINNED_TO_CORE
|
||||
#define BLE_MESH_ADV_TASK_CORE TASK_PINNED_TO_CORE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_PINNED_TO_CORE
|
||||
#define ADV_TASK_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
|
||||
#define BLE_MESH_ADV_TASK_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
|
||||
#else
|
||||
#define ADV_TASK_CORE (0)
|
||||
#define BLE_MESH_ADV_TASK_CORE (0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define BLE_MESH_ADV_TASK_STACK_SIZE 3072
|
||||
|
||||
#define BLE_MESH_GAP_ADV_MAX_LEN 31
|
||||
|
||||
#define BLE_MESH_GATT_DEF_MTU_SIZE 23
|
||||
@ -640,7 +642,8 @@ struct bt_mesh_gatt_attr {
|
||||
.attr_count = ARRAY_SIZE(_attrs), \
|
||||
}
|
||||
|
||||
esp_err_t bt_mesh_host_init(void);
|
||||
int bt_mesh_host_init(void);
|
||||
int bt_mesh_host_deinit(void);
|
||||
|
||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
@ -653,10 +656,12 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c
|
||||
int bt_le_scan_stop(void);
|
||||
|
||||
void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb);
|
||||
void bt_mesh_gatts_conn_cb_deregister(void);
|
||||
|
||||
int bt_mesh_gatts_disconnect(struct bt_mesh_conn *conn, u8_t reason);
|
||||
|
||||
int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc);
|
||||
int bt_mesh_gatts_service_deregister(struct bt_mesh_gatt_service *svc);
|
||||
|
||||
int bt_mesh_gatts_service_unregister(struct bt_mesh_gatt_service *svc);
|
||||
|
||||
@ -688,6 +693,7 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc);
|
||||
int bt_mesh_gatts_set_local_device_name(const char *name);
|
||||
|
||||
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb);
|
||||
void bt_mesh_gattc_conn_cb_deregister(void);
|
||||
|
||||
u8_t bt_mesh_gattc_get_free_conn_count(void);
|
||||
|
||||
@ -711,6 +717,7 @@ struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn);
|
||||
void bt_mesh_conn_unref(struct bt_mesh_conn *conn);
|
||||
|
||||
void bt_mesh_gatt_init(void);
|
||||
void bt_mesh_gatt_deinit(void);
|
||||
|
||||
void bt_mesh_adapt_init(void);
|
||||
|
||||
|
@ -7,9 +7,8 @@
|
||||
#ifndef _BLE_MESH_HCI_H_
|
||||
#define _BLE_MESH_HCI_H_
|
||||
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_atomic.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -11,7 +11,6 @@
|
||||
#ifndef _BLE_MESH_MAIN_H_
|
||||
#define _BLE_MESH_MAIN_H_
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_access.h"
|
||||
|
||||
/**
|
||||
@ -295,12 +294,19 @@ struct bt_mesh_prov {
|
||||
* @param element_num Provisioned device element number.
|
||||
* @param netkey_idx Provisioned device assigned netkey index.
|
||||
*/
|
||||
void (*prov_complete)(int node_idx, const u8_t device_uuid[16],
|
||||
void (*prov_complete)(u16_t node_idx, const u8_t device_uuid[16],
|
||||
u16_t unicast_addr, u8_t element_num,
|
||||
u16_t netkey_idx);
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
};
|
||||
|
||||
enum ble_mesh_role {
|
||||
NODE = 0,
|
||||
PROVISIONER,
|
||||
FAST_PROV,
|
||||
ROLE_NVAL,
|
||||
};
|
||||
|
||||
/* The following APIs are for BLE Mesh Node */
|
||||
|
||||
/** @brief Provide provisioning input OOB string.
|
||||
@ -345,12 +351,6 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers);
|
||||
*/
|
||||
int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers);
|
||||
|
||||
/** @brief Indicate whether provisioner is enabled
|
||||
*
|
||||
* @return true - enabled, false - disabled.
|
||||
*/
|
||||
bool bt_mesh_is_provisioner_en(void);
|
||||
|
||||
/* The following API is for BLE Mesh Fast Provisioning */
|
||||
|
||||
/** @brief Change the device action
|
||||
@ -386,6 +386,14 @@ int bt_mesh_prov_input_string(const char *str);
|
||||
*/
|
||||
int bt_mesh_prov_input_number(u32_t num);
|
||||
|
||||
/** @brief Enable Provisioner corresponding functionalities, e.g. scan, etc.
|
||||
*
|
||||
* @param bearers Bit-wise OR of provisioning bearers.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers);
|
||||
|
||||
/** @brief Enable specific provisioning bearers
|
||||
*
|
||||
* Enable one or more provisioning bearers.
|
||||
@ -463,6 +471,19 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers);
|
||||
int bt_mesh_init(const struct bt_mesh_prov *prov,
|
||||
const struct bt_mesh_comp *comp);
|
||||
|
||||
/* BLE Mesh deinit parameters */
|
||||
struct bt_mesh_deinit_param {
|
||||
bool erase; /* Indicate if erasing flash when deinit mesh stack */
|
||||
};
|
||||
|
||||
/** @brief De-initialize Mesh support
|
||||
*
|
||||
* @param param BLE Mesh deinit parameters.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_mesh_deinit(struct bt_mesh_deinit_param *param);
|
||||
|
||||
/** @brief Reset the state of the local Mesh node.
|
||||
*
|
||||
* Resets the state of the node, which means that it needs to be
|
||||
@ -515,6 +536,13 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
|
||||
u8_t flags, u32_t iv_index, u16_t addr,
|
||||
const u8_t dev_key[16]);
|
||||
|
||||
/** @brief Check if the device is an unprovisioned device
|
||||
* and will act as a node once provisioned.
|
||||
*
|
||||
* @return true - yes, false - no.
|
||||
*/
|
||||
bool bt_mesh_is_node(void);
|
||||
|
||||
/** @brief Check if the local node has been provisioned.
|
||||
*
|
||||
* This API can be used to check if the local node has been provisioned
|
||||
@ -526,6 +554,18 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
|
||||
*/
|
||||
bool bt_mesh_is_provisioned(void);
|
||||
|
||||
/** @brief Check if the device is a Provisioner.
|
||||
*
|
||||
* @return true - yes, false - no.
|
||||
*/
|
||||
bool bt_mesh_is_provisioner(void);
|
||||
|
||||
/** @brief Check if the Provisioner is enabled
|
||||
*
|
||||
* @return true - enabled, false - disabled.
|
||||
*/
|
||||
bool bt_mesh_is_provisioner_en(void);
|
||||
|
||||
/** @brief Toggle the IV Update test mode
|
||||
*
|
||||
* This API is only available if the IV Update test mode has been enabled
|
||||
|
@ -9,23 +9,17 @@
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_LOW_POWER)
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_main.h"
|
||||
|
||||
#include "crypto.h"
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "beacon.h"
|
||||
#include "foundation.h"
|
||||
#include "lpn.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_main.h"
|
||||
#include "cfg_srv.h"
|
||||
|
||||
#ifdef CONFIG_BLE_MESH_LOW_POWER
|
||||
@ -77,6 +71,7 @@
|
||||
|
||||
static void (*lpn_cb)(u16_t friend_addr, bool established);
|
||||
|
||||
#if !CONFIG_BLE_MESH_NO_LOG
|
||||
static const char *state2str(int state)
|
||||
{
|
||||
switch (state) {
|
||||
@ -104,6 +99,7 @@ static const char *state2str(int state)
|
||||
return "(unknown)";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void lpn_set_state(int state)
|
||||
{
|
||||
@ -394,7 +390,7 @@ static int send_friend_poll(void)
|
||||
};
|
||||
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
|
||||
u8_t fsn = lpn->fsn;
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("lpn->sent_req 0x%02x", lpn->sent_req);
|
||||
|
||||
@ -513,9 +509,9 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
|
||||
struct bt_mesh_ctl_friend_offer *msg = (void *)buf->data;
|
||||
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
|
||||
struct bt_mesh_subnet *sub = rx->sub;
|
||||
struct friend_cred *cred;
|
||||
u16_t frnd_counter;
|
||||
int err;
|
||||
struct friend_cred *cred = NULL;
|
||||
u16_t frnd_counter = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (buf->len < sizeof(*msg)) {
|
||||
BT_WARN("Too short Friend Offer");
|
||||
@ -534,7 +530,7 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
|
||||
|
||||
frnd_counter = sys_be16_to_cpu(msg->frnd_counter);
|
||||
|
||||
BT_DBG("recv_win %u queue_size %u sub_list_size %u rssi %d counter %u",
|
||||
BT_INFO("recv_win %u queue_size %u sub_list_size %u rssi %d counter %u",
|
||||
msg->recv_win, msg->queue_size, msg->sub_list_size, msg->rssi,
|
||||
frnd_counter);
|
||||
|
||||
@ -576,7 +572,7 @@ int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx,
|
||||
{
|
||||
struct bt_mesh_ctl_friend_clear_confirm *msg = (void *)buf->data;
|
||||
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
|
||||
u16_t addr, counter;
|
||||
u16_t addr = 0U, counter = 0U;
|
||||
|
||||
if (buf->len < sizeof(*msg)) {
|
||||
BT_WARN("Too short Friend Clear Confirm");
|
||||
@ -678,8 +674,8 @@ static bool sub_update(u8_t op)
|
||||
.xmit = POLL_XMIT,
|
||||
.friend_cred = true,
|
||||
};
|
||||
struct bt_mesh_ctl_friend_sub req;
|
||||
size_t i, g;
|
||||
struct bt_mesh_ctl_friend_sub req = {0};
|
||||
size_t i = 0U, g = 0U;
|
||||
|
||||
BT_DBG("op 0x%02x sent_req 0x%02x", op, lpn->sent_req);
|
||||
|
||||
@ -687,7 +683,7 @@ static bool sub_update(u8_t op)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0, g = 0; i < ARRAY_SIZE(lpn->groups); i++) {
|
||||
for (i = 0U, g = 0U; i < ARRAY_SIZE(lpn->groups); i++) {
|
||||
if (lpn->groups[i] == BLE_MESH_ADDR_UNASSIGNED) {
|
||||
continue;
|
||||
}
|
||||
@ -715,7 +711,7 @@ static bool sub_update(u8_t op)
|
||||
}
|
||||
}
|
||||
|
||||
if (g == 0) {
|
||||
if (g == 0U) {
|
||||
group_zero(lpn->pending);
|
||||
return false;
|
||||
}
|
||||
@ -963,7 +959,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
|
||||
struct bt_mesh_ctl_friend_update *msg = (void *)buf->data;
|
||||
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
|
||||
struct bt_mesh_subnet *sub = rx->sub;
|
||||
u32_t iv_index;
|
||||
u32_t iv_index = 0U;
|
||||
|
||||
if (buf->len < sizeof(*msg)) {
|
||||
BT_WARN("Too short Friend Update");
|
||||
@ -1020,7 +1016,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
|
||||
|
||||
iv_index = sys_be32_to_cpu(msg->iv_index);
|
||||
|
||||
BT_DBG("flags 0x%02x iv_index 0x%08x md %u", msg->flags, iv_index,
|
||||
BT_INFO("flags 0x%02x iv_index 0x%08x md %u", msg->flags, iv_index,
|
||||
msg->md);
|
||||
|
||||
if (bt_mesh_kr_update(sub, BLE_MESH_KEY_REFRESH(msg->flags),
|
||||
@ -1094,4 +1090,15 @@ int bt_mesh_lpn_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_lpn_deinit(void)
|
||||
{
|
||||
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
|
||||
|
||||
bt_mesh_lpn_disable(true);
|
||||
|
||||
k_delayed_work_free(&lpn->timer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_LOW_POWER */
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef _LPN_H_
|
||||
#define _LPN_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *buf);
|
||||
int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx,
|
||||
@ -63,5 +65,6 @@ void bt_mesh_lpn_group_del(u16_t *groups, size_t group_count);
|
||||
void bt_mesh_lpn_disable(bool force);
|
||||
|
||||
int bt_mesh_lpn_init(void);
|
||||
int bt_mesh_lpn_deinit(void);
|
||||
|
||||
#endif /* _LPN_H_ */
|
||||
|
@ -7,52 +7,43 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG)
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_hci.h"
|
||||
|
||||
#include "adv.h"
|
||||
#include "prov.h"
|
||||
#include "net.h"
|
||||
#include "beacon.h"
|
||||
#include "lpn.h"
|
||||
#include "friend.h"
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "proxy_server.h"
|
||||
#include "settings.h"
|
||||
#include "mesh.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "mesh_hci.h"
|
||||
#include "mesh_common.h"
|
||||
#include "proxy_client.h"
|
||||
#include "proxy_server.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
static volatile bool provisioner_en = false;
|
||||
|
||||
#define ACTION_ENTER 0x01
|
||||
#define ACTION_SUSPEND 0x02
|
||||
#define ACTION_EXIT 0x03
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
|
||||
int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
|
||||
u8_t flags, u32_t iv_index, u16_t addr,
|
||||
const u8_t dev_key[16])
|
||||
{
|
||||
bool pb_gatt_enabled;
|
||||
int err;
|
||||
bool pb_gatt_enabled = false;
|
||||
int err = 0;
|
||||
|
||||
BT_INFO("Primary Element: 0x%04x", addr);
|
||||
BT_DBG("net_idx 0x%04x flags 0x%02x iv_index 0x%04x",
|
||||
BT_INFO("net_idx 0x%04x flags 0x%02x iv_index 0x%04x",
|
||||
net_idx, flags, iv_index);
|
||||
BT_INFO("dev_key %s", bt_hex(dev_key, 16));
|
||||
|
||||
if (bt_mesh_atomic_test_and_set_bit(bt_mesh.flags, BLE_MESH_VALID)) {
|
||||
return -EALREADY;
|
||||
@ -142,14 +133,41 @@ void bt_mesh_reset(void)
|
||||
|
||||
bt_mesh_comp_unprovision();
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_role();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) {
|
||||
bt_mesh_prov_reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool bt_mesh_is_node(void)
|
||||
{
|
||||
return bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_NODE);
|
||||
}
|
||||
|
||||
bool bt_mesh_is_provisioned(void)
|
||||
{
|
||||
return bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID);
|
||||
if (bt_mesh_is_node()) {
|
||||
return bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool bt_mesh_is_provisioner(void)
|
||||
{
|
||||
return bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_PROVISIONER);
|
||||
}
|
||||
|
||||
bool bt_mesh_is_provisioner_en(void)
|
||||
{
|
||||
if (bt_mesh_is_provisioner()) {
|
||||
return bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID_PROV);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
|
||||
@ -158,6 +176,12 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_NODE);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_store_role();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
(bearers & BLE_MESH_PROV_ADV)) {
|
||||
/* Make sure we're scanning for provisioning inviations */
|
||||
@ -181,6 +205,12 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_NODE);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_role();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
(bearers & BLE_MESH_PROV_ADV)) {
|
||||
bt_mesh_beacon_disable();
|
||||
@ -195,8 +225,6 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
static void model_suspend(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
bool vnd, bool primary, void *user_data)
|
||||
{
|
||||
@ -208,7 +236,7 @@ static void model_suspend(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
|
||||
int bt_mesh_suspend(void)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID)) {
|
||||
return -EINVAL;
|
||||
@ -250,7 +278,7 @@ static void model_resume(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||
|
||||
int bt_mesh_resume(void)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID)) {
|
||||
return -EINVAL;
|
||||
@ -279,7 +307,7 @@ int bt_mesh_resume(void)
|
||||
int bt_mesh_init(const struct bt_mesh_prov *prov,
|
||||
const struct bt_mesh_comp *comp)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_k_init();
|
||||
|
||||
@ -292,101 +320,167 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
|
||||
return err;
|
||||
}
|
||||
|
||||
bt_mesh_gatt_init();
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
extern struct bt_mesh_gatt_service proxy_svc;
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
|
||||
bt_mesh_gatts_service_register(&proxy_svc);
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
|
||||
bt_mesh_gatt_init();
|
||||
}
|
||||
|
||||
extern struct bt_mesh_gatt_service prov_svc;
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
|
||||
bt_mesh_gatts_service_register(&prov_svc);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) {
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
err = bt_mesh_prov_init(prov);
|
||||
if (err) {
|
||||
return err;
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) {
|
||||
err = bt_mesh_prov_init(prov);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
err = provisioner_prov_init(prov);
|
||||
if (err) {
|
||||
return err;
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) {
|
||||
err = bt_mesh_provisioner_prov_init(prov);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bt_mesh_net_init();
|
||||
bt_mesh_trans_init();
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
/* Changed by Espressif, add random delay (0 ~ 3s) */
|
||||
#if defined(CONFIG_BLE_MESH_FAST_PROV)
|
||||
u32_t delay = 0;
|
||||
bt_mesh_rand(&delay, sizeof(u32_t));
|
||||
vTaskDelay((delay % 3000) / portTICK_PERIOD_MS);
|
||||
#endif
|
||||
/* Changed by Espressif, add a random delay (0 ~ 3s) */
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV)) {
|
||||
u32_t delay = 0;
|
||||
bt_mesh_rand(&delay, sizeof(u32_t));
|
||||
vTaskDelay((delay % 3000) / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
bt_mesh_beacon_init();
|
||||
#endif
|
||||
|
||||
bt_mesh_adv_init();
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
bt_mesh_proxy_init();
|
||||
#endif
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
bt_mesh_proxy_prov_client_init();
|
||||
#endif
|
||||
if ((IS_ENABLED(CONFIG_BLE_MESH_NODE) &&
|
||||
IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) ||
|
||||
IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
|
||||
bt_mesh_proxy_init();
|
||||
}
|
||||
if ((IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) &&
|
||||
IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) ||
|
||||
IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
|
||||
bt_mesh_proxy_prov_client_init();
|
||||
}
|
||||
}
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
/* If node & provisioner are both enabled and the
|
||||
* device starts as a node, it must finish provisioning */
|
||||
err = provisioner_upper_init();
|
||||
if (err) {
|
||||
return err;
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) {
|
||||
bt_mesh_provisioner_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_SETTINGS)
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_settings_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool bt_mesh_is_provisioner_en(void)
|
||||
int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
|
||||
{
|
||||
return provisioner_en;
|
||||
}
|
||||
int err = 0;
|
||||
|
||||
/* The following APIs are for fast provisioning */
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
BT_WARN("%s, Provisioner is already enabled", __func__);
|
||||
return -EALREADY;
|
||||
if (param == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = provisioner_upper_init();
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV)) {
|
||||
bt_mesh_beacon_disable();
|
||||
bt_mesh_scan_disable();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
|
||||
bt_mesh_proxy_prov_disable(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
|
||||
bt_mesh_provisioner_pb_gatt_disable();
|
||||
}
|
||||
|
||||
bt_mesh_scan_disable();
|
||||
bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_VALID_PROV);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) {
|
||||
err = bt_mesh_prov_deinit();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) {
|
||||
err = bt_mesh_provisioner_prov_deinit(param->erase);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bt_mesh_trans_deinit(param->erase);
|
||||
bt_mesh_net_deinit(param->erase);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) {
|
||||
bt_mesh_beacon_deinit();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) {
|
||||
bt_mesh_proxy_deinit();
|
||||
}
|
||||
}
|
||||
|
||||
if ((IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) &&
|
||||
IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) ||
|
||||
IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
|
||||
bt_mesh_proxy_prov_client_deinit();
|
||||
}
|
||||
|
||||
bt_mesh_gatt_deinit();
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) {
|
||||
err = bt_mesh_provisioner_deinit(param->erase);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
bt_mesh_friend_deinit();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) {
|
||||
bt_mesh_lpn_deinit();
|
||||
}
|
||||
|
||||
bt_mesh_adv_deinit();
|
||||
|
||||
err = bt_mesh_comp_deregister();
|
||||
if (err) {
|
||||
BT_ERR("%s, provisioner_upper_init fail", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
if (param->erase) {
|
||||
bt_mesh_clear_role();
|
||||
}
|
||||
bt_mesh_settings_deinit();
|
||||
}
|
||||
|
||||
bt_mesh_k_deinit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PROVISIONER)
|
||||
int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers)
|
||||
{
|
||||
bt_mesh_provisioner_set_prov_bearer(bearers, false);
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
(bearers & BLE_MESH_PROV_ADV)) {
|
||||
@ -410,42 +504,107 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
||||
(bearers & BLE_MESH_PROV_GATT)) {
|
||||
provisioner_pb_gatt_enable();
|
||||
bt_mesh_provisioner_pb_gatt_enable();
|
||||
}
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID_PROV);
|
||||
|
||||
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
|
||||
bt_mesh_beacon_enable();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
bt_mesh_friend_init();
|
||||
}
|
||||
|
||||
provisioner_en = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
BT_WARN("%s, Already", __func__);
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
err = bt_mesh_provisioner_set_prov_info();
|
||||
if (err) {
|
||||
BT_ERR("%s, Failed to set provisioning info", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = bt_mesh_provisioner_net_create();
|
||||
if (err) {
|
||||
BT_ERR("%s, Failed to create network", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_store_role();
|
||||
}
|
||||
|
||||
return bt_mesh_provisioner_net_start(bearers);
|
||||
}
|
||||
|
||||
int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
|
||||
{
|
||||
bt_mesh_prov_bearer_t enable = 0U;
|
||||
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
BT_WARN("%s, Provisioner is already disabled", __func__);
|
||||
BT_WARN("%s, Already", __func__);
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
enable = bt_mesh_provisioner_get_prov_bearer();
|
||||
if (!(enable & bearers)) {
|
||||
BT_ERR("%s, Bearers mismatch", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bt_mesh_provisioner_set_prov_bearer(bearers, true);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
||||
(enable & BLE_MESH_PROV_GATT) &&
|
||||
(bearers & BLE_MESH_PROV_GATT)) {
|
||||
provisioner_pb_gatt_disable();
|
||||
bt_mesh_provisioner_pb_gatt_disable();
|
||||
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
||||
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE,
|
||||
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
(bearers & BLE_MESH_PROV_ADV)) &&
|
||||
(IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
||||
(bearers & BLE_MESH_PROV_GATT))) {
|
||||
if (!(enable & (~bearers))) {
|
||||
/* Provisioner is disabled completely, disable scan here */
|
||||
bt_mesh_scan_disable();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY);
|
||||
}
|
||||
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
(enable & BLE_MESH_PROV_ADV)) {
|
||||
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE,
|
||||
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
provisioner_en = false;
|
||||
/* Clear corresponding flags */
|
||||
bt_mesh_atomic_and(bt_mesh.flags, ~(BIT(BLE_MESH_PROVISIONER) | BIT(BLE_MESH_VALID_PROV)));
|
||||
|
||||
/* When Provisioner is disabled, the device role indicated by bt_mesh.flags
|
||||
* will not be cleared, because when Provisioner is restarted after disabled,
|
||||
* its previous information can be recovered from flash properly.
|
||||
*/
|
||||
|
||||
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
|
||||
bt_mesh_beacon_disable();
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -460,9 +619,9 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action)
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
if ((!provisioner_en && (action == ACTION_SUSPEND || action == ACTION_EXIT)) ||
|
||||
(provisioner_en && (action == ACTION_ENTER))) {
|
||||
BT_WARN("%s, Action is already done", __func__);
|
||||
if ((!bt_mesh_is_provisioner_en() && (action == ACTION_SUSPEND || action == ACTION_EXIT)) ||
|
||||
(bt_mesh_is_provisioner_en() && (action == ACTION_ENTER))) {
|
||||
BT_WARN("%s, Already", __func__);
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
@ -481,13 +640,14 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action)
|
||||
bt_mesh_beacon_disable();
|
||||
}
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
|
||||
provisioner_pb_gatt_enable();
|
||||
bt_mesh_provisioner_pb_gatt_enable();
|
||||
}
|
||||
provisioner_set_fast_prov_flag(true);
|
||||
provisioner_en = true;
|
||||
bt_mesh_provisioner_set_prov_bearer(BLE_MESH_PROV_ADV, false);
|
||||
bt_mesh_provisioner_fast_prov_enable(true);
|
||||
bt_mesh_atomic_or(bt_mesh.flags, BIT(BLE_MESH_PROVISIONER) | BIT(BLE_MESH_VALID_PROV));
|
||||
} else {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
|
||||
provisioner_pb_gatt_disable();
|
||||
bt_mesh_provisioner_pb_gatt_disable();
|
||||
}
|
||||
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
|
||||
bt_mesh_beacon_enable();
|
||||
@ -500,11 +660,10 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action)
|
||||
bt_mesh_adv_update();
|
||||
}
|
||||
#endif
|
||||
provisioner_set_fast_prov_flag(false);
|
||||
provisioner_en = false;
|
||||
bt_mesh_atomic_and(bt_mesh.flags, ~(BIT(BLE_MESH_PROVISIONER) | BIT(BLE_MESH_VALID_PROV)));
|
||||
bt_mesh_provisioner_fast_prov_enable(false);
|
||||
if (action == ACTION_EXIT) {
|
||||
provisioner_upper_reset_all_nodes();
|
||||
provisioner_prov_reset_all_nodes();
|
||||
bt_mesh_provisioner_remove_node(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef _MESH_H_
|
||||
#define _MESH_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
#define BLE_MESH_KEY_PRIMARY 0x0000
|
||||
#define BLE_MESH_KEY_ANY 0xffff
|
||||
|
||||
|
@ -11,30 +11,22 @@
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_NET)
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh.h"
|
||||
|
||||
#include "crypto.h"
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "lpn.h"
|
||||
#include "friend.h"
|
||||
#include "proxy_server.h"
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "beacon.h"
|
||||
#include "settings.h"
|
||||
#include "prov.h"
|
||||
#include "provisioner_main.h"
|
||||
#include "proxy_client.h"
|
||||
#include "proxy_server.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
/* Minimum valid Mesh Network PDU length. The Network headers
|
||||
* themselves take up 9 bytes. After that there is a minumum of 1 byte
|
||||
@ -97,7 +89,7 @@ static int dup_cache_next;
|
||||
static bool check_dup(struct net_buf_simple *data)
|
||||
{
|
||||
const u8_t *tail = net_buf_simple_tail(data);
|
||||
u32_t val;
|
||||
u32_t val = 0U;
|
||||
int i;
|
||||
|
||||
val = sys_get_be32(tail - 4) ^ sys_get_be32(tail - 8);
|
||||
@ -116,7 +108,7 @@ static bool check_dup(struct net_buf_simple *data)
|
||||
|
||||
static u64_t msg_hash(struct bt_mesh_net_rx *rx, struct net_buf_simple *pdu)
|
||||
{
|
||||
u32_t hash1, hash2;
|
||||
u32_t hash1 = 0U, hash2 = 0U;
|
||||
|
||||
/* Three least significant bytes of IVI + first byte of SEQ */
|
||||
hash1 = (BLE_MESH_NET_IVI_RX(rx) << 8) | pdu->data[2];
|
||||
@ -131,9 +123,9 @@ static bool msg_cache_match(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *pdu)
|
||||
{
|
||||
u64_t hash = msg_hash(rx, pdu);
|
||||
u16_t i;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(msg_cache); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(msg_cache); i++) {
|
||||
if (msg_cache[i] == hash) {
|
||||
return true;
|
||||
}
|
||||
@ -147,6 +139,21 @@ static bool msg_cache_match(struct bt_mesh_net_rx *rx,
|
||||
return false;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
void bt_mesh_msg_cache_clear(u16_t unicast_addr, u8_t elem_num)
|
||||
{
|
||||
u16_t src = 0U;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(msg_cache); i++) {
|
||||
src = (((u8_t)(msg_cache[i] >> 16)) << 8) | (u8_t)(msg_cache[i] >> 24);
|
||||
if (src >= unicast_addr && src < unicast_addr + elem_num) {
|
||||
memset(&msg_cache[i], 0x0, sizeof(msg_cache[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_subnet_get(u16_t net_idx)
|
||||
{
|
||||
int i;
|
||||
@ -168,8 +175,8 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
|
||||
const u8_t key[16])
|
||||
{
|
||||
u8_t p[] = { 0 };
|
||||
u8_t nid;
|
||||
int err;
|
||||
u8_t nid = 0U;
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_k2(key, p, sizeof(p), &nid, keys->enc, keys->privacy);
|
||||
if (err) {
|
||||
@ -217,9 +224,9 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
|
||||
defined(CONFIG_BLE_MESH_FRIEND))
|
||||
int friend_cred_set(struct friend_cred *cred, u8_t idx, const u8_t net_key[16])
|
||||
{
|
||||
u16_t lpn_addr, frnd_addr;
|
||||
int err;
|
||||
u8_t p[9];
|
||||
u16_t lpn_addr = 0U, frnd_addr = 0U;
|
||||
int err = 0;
|
||||
u8_t p[9] = {0};
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_LOW_POWER)
|
||||
if (cred->addr == bt_mesh.lpn.frnd) {
|
||||
@ -275,7 +282,7 @@ void friend_cred_refresh(u16_t net_idx)
|
||||
|
||||
int friend_cred_update(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
int err, i;
|
||||
int err = 0, i;
|
||||
|
||||
BT_DBG("net_idx 0x%04x", sub->net_idx);
|
||||
|
||||
@ -299,8 +306,8 @@ int friend_cred_update(struct bt_mesh_subnet *sub)
|
||||
struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr,
|
||||
u16_t lpn_counter, u16_t frnd_counter)
|
||||
{
|
||||
struct friend_cred *cred;
|
||||
int i, err;
|
||||
struct friend_cred *cred = NULL;
|
||||
int i, err = 0;
|
||||
|
||||
BT_DBG("net_idx 0x%04x addr 0x%04x", sub->net_idx, addr);
|
||||
|
||||
@ -426,7 +433,7 @@ u8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub)
|
||||
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
u8_t flags = bt_mesh_net_flags(sub);
|
||||
struct bt_mesh_subnet_keys *keys;
|
||||
struct bt_mesh_subnet_keys *keys = NULL;
|
||||
|
||||
if (sub->kr_flag) {
|
||||
BT_DBG("NetIndex %u Using new key", sub->net_idx);
|
||||
@ -445,8 +452,8 @@ int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub)
|
||||
int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
|
||||
u32_t iv_index)
|
||||
{
|
||||
struct bt_mesh_subnet *sub;
|
||||
int err;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("idx %u flags 0x%02x iv_index %u", idx, flags, iv_index);
|
||||
|
||||
@ -527,7 +534,7 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key)
|
||||
|
||||
if (sub->kr_flag) {
|
||||
if (sub->kr_phase == BLE_MESH_KR_PHASE_1) {
|
||||
BT_DBG("Phase 1 -> Phase 2");
|
||||
BT_INFO("Phase 1 -> Phase 2");
|
||||
sub->kr_phase = BLE_MESH_KR_PHASE_2;
|
||||
return true;
|
||||
}
|
||||
@ -546,7 +553,7 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key)
|
||||
* Intentional fall-through.
|
||||
*/
|
||||
case BLE_MESH_KR_PHASE_2:
|
||||
BT_DBG("KR Phase 0x%02x -> Normal", sub->kr_phase);
|
||||
BT_INFO("KR Phase 0x%02x -> Normal", sub->kr_phase);
|
||||
bt_mesh_net_revoke_keys(sub);
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) ||
|
||||
IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
@ -616,9 +623,7 @@ void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub)
|
||||
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -696,12 +701,12 @@ do_update:
|
||||
|
||||
if (iv_update) {
|
||||
bt_mesh.iv_index = iv_index;
|
||||
BT_DBG("IV Update state entered. New index 0x%08x",
|
||||
BT_INFO("IV Update state entered. New index 0x%08x",
|
||||
bt_mesh.iv_index);
|
||||
|
||||
bt_mesh_rpl_reset();
|
||||
} else {
|
||||
BT_DBG("Normal mode entered");
|
||||
BT_INFO("Normal mode entered");
|
||||
bt_mesh.seq = 0U;
|
||||
}
|
||||
|
||||
@ -720,6 +725,21 @@ do_update:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bt_mesh_primary_subnet_exist(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
|
||||
if (bt_mesh_subnet_get(BLE_MESH_KEY_PRIMARY)) {
|
||||
return true;
|
||||
}
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
if (bt_mesh_provisioner_subnet_get(BLE_MESH_KEY_PRIMARY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
u32_t bt_mesh_next_seq(void)
|
||||
{
|
||||
u32_t seq = bt_mesh.seq++;
|
||||
@ -730,10 +750,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)) {
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
bt_mesh_primary_subnet_exist()) {
|
||||
bt_mesh_beacon_ivu_initiator(true);
|
||||
#endif
|
||||
bt_mesh_net_iv_update(bt_mesh.iv_index + 1, true);
|
||||
bt_mesh_net_sec_update(NULL);
|
||||
}
|
||||
@ -745,10 +763,10 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
bool new_key, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
{
|
||||
const u8_t *enc, *priv;
|
||||
u32_t seq;
|
||||
u16_t dst;
|
||||
int err;
|
||||
const u8_t *enc = NULL, *priv = NULL;
|
||||
u32_t seq = 0U;
|
||||
u16_t dst = 0U;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("net_idx 0x%04x new_key %u len %u", sub->net_idx, new_key,
|
||||
buf->len);
|
||||
@ -801,7 +819,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
|
||||
static void bt_mesh_net_local(struct k_work *work)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
while ((buf = net_buf_slist_get(&bt_mesh.local_queue))) {
|
||||
BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
@ -814,11 +832,11 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
|
||||
bool proxy)
|
||||
{
|
||||
const bool ctl = (tx->ctx->app_idx == BLE_MESH_KEY_UNUSED);
|
||||
u32_t seq_val;
|
||||
u8_t nid;
|
||||
const u8_t *enc, *priv;
|
||||
u8_t *seq;
|
||||
int err;
|
||||
u32_t seq_val = 0U;
|
||||
u8_t nid = 0U;
|
||||
const u8_t *enc = NULL, *priv = NULL;
|
||||
u8_t *seq = NULL;
|
||||
int err = 0;
|
||||
|
||||
if (ctl && net_buf_simple_tailroom(buf) < 8) {
|
||||
BT_ERR("%s, Insufficient MIC space for CTL PDU", __func__);
|
||||
@ -877,7 +895,7 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
|
||||
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("src 0x%04x dst 0x%04x len %u headroom %u tailroom %u",
|
||||
tx->src, tx->ctx->addr, buf->len, net_buf_headroom(buf),
|
||||
@ -898,23 +916,19 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
* "The output filter of the interface connected to advertising or
|
||||
* GATT bearers shall drop all messages with TTL value set to 1."
|
||||
*/
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
err = 0;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
if (tx->ctx->send_ttl != 1U) {
|
||||
@ -962,7 +976,7 @@ static bool auth_match(struct bt_mesh_subnet_keys *keys,
|
||||
const u8_t net_id[8], u8_t flags,
|
||||
u32_t iv_index, const u8_t auth[8])
|
||||
{
|
||||
u8_t net_auth[8];
|
||||
u8_t net_auth[8] = {0};
|
||||
|
||||
if (memcmp(net_id, keys->net_id, 8)) {
|
||||
return false;
|
||||
@ -984,12 +998,15 @@ struct bt_mesh_subnet *bt_mesh_subnet_find(const u8_t net_id[8], u8_t flags,
|
||||
u32_t iv_index, const u8_t auth[8],
|
||||
bool *new_key)
|
||||
{
|
||||
size_t subnet_size = 0U;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
|
||||
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
|
||||
subnet_size = bt_mesh_rx_netkey_size();
|
||||
|
||||
if (sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
for (i = 0; i < subnet_size; i++) {
|
||||
struct bt_mesh_subnet *sub = bt_mesh_rx_netkey_get(i);
|
||||
|
||||
if (sub == NULL || sub->net_idx == BLE_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1028,11 +1045,6 @@ static int net_decrypt(struct bt_mesh_subnet *sub, const u8_t *enc,
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* TODO: For provisioner, when a device is re-provisioned and start to
|
||||
* send the same message(e.g. cfg_appkey_add), the status message is easy
|
||||
* to be filtered here. So when a device is re-provisioned, the related
|
||||
* msg_cache should be cleared. Will do it later.
|
||||
*/
|
||||
if (rx->net_if == BLE_MESH_NET_IF_ADV && msg_cache_match(rx, buf)) {
|
||||
BT_WARN("Duplicate found in Network Message Cache");
|
||||
return -EALREADY;
|
||||
@ -1046,15 +1058,11 @@ static int net_decrypt(struct bt_mesh_subnet *sub, const u8_t *enc,
|
||||
|
||||
BT_DBG("src 0x%04x", rx->ctx.addr);
|
||||
|
||||
#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
|
||||
|
||||
return bt_mesh_net_decrypt(enc, buf, BLE_MESH_NET_IVI_RX(rx), false);
|
||||
}
|
||||
@ -1103,7 +1111,7 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
size_t array_size = 0;
|
||||
size_t array_size = 0U;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
@ -1160,8 +1168,6 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len,
|
||||
* get sent to the advertising bearer. If the packet came in through GATT,
|
||||
* then we should only relay it if the GATT Proxy state is enabled.
|
||||
*/
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
|
||||
static bool relay_to_adv(enum bt_mesh_net_if net_if)
|
||||
{
|
||||
switch (net_if) {
|
||||
@ -1179,9 +1185,9 @@ static bool relay_to_adv(enum bt_mesh_net_if net_if)
|
||||
static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
|
||||
struct bt_mesh_net_rx *rx)
|
||||
{
|
||||
const u8_t *enc, *priv;
|
||||
struct net_buf *buf;
|
||||
u8_t nid, transmit;
|
||||
const u8_t *enc = NULL, *priv = NULL;
|
||||
struct net_buf *buf = NULL;
|
||||
u8_t nid = 0U, transmit = 0U;
|
||||
|
||||
if (rx->net_if == BLE_MESH_NET_IF_LOCAL) {
|
||||
/* Locally originated PDUs with TTL=1 will only be delivered
|
||||
@ -1301,8 +1307,6 @@ done:
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
void bt_mesh_net_header_parse(struct net_buf_simple *buf,
|
||||
struct bt_mesh_net_rx *rx)
|
||||
{
|
||||
@ -1379,25 +1383,15 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
||||
|
||||
static bool ready_to_recv(void)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
return false;
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
|
||||
return true;
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
if (bt_mesh_provisioner_get_all_node_count()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
BT_WARN("%s, Provisioner is disabled", __func__);
|
||||
return false;
|
||||
}
|
||||
if (!provisioner_get_prov_node_count()) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
||||
@ -1405,7 +1399,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(buf, 29);
|
||||
struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
|
||||
struct net_buf_simple_state state;
|
||||
struct net_buf_simple_state state = {0};
|
||||
|
||||
BT_DBG("rssi %d net_if %u", rssi, net_if);
|
||||
|
||||
@ -1420,14 +1414,10 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
||||
/* Save the state so the buffer can later be relayed */
|
||||
net_buf_simple_save(&buf, &state);
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
rx.local_match = (bt_mesh_fixed_group_match(rx.ctx.recv_dst) ||
|
||||
bt_mesh_elem_find(rx.ctx.recv_dst));
|
||||
@ -1449,22 +1439,19 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
||||
/* Relay if this was a group/virtual address, or if the destination
|
||||
* was neither a local element nor an LPN we're Friends for.
|
||||
*/
|
||||
#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 (IS_ENABLED(CONFIG_BLE_MESH_RELAY) &&
|
||||
(!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
|
||||
}
|
||||
|
||||
static void ivu_refresh(struct k_work *work)
|
||||
{
|
||||
bt_mesh.ivu_duration += BLE_MESH_IVU_HOURS;
|
||||
|
||||
BT_DBG("%s for %u hour%s",
|
||||
BT_INFO("%s for %u hour%s",
|
||||
bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS) ?
|
||||
"IVU in Progress" : "IVU Normal mode",
|
||||
bt_mesh.ivu_duration, bt_mesh.ivu_duration == 1U ? "" : "s");
|
||||
@ -1479,16 +1466,13 @@ static void ivu_refresh(struct k_work *work)
|
||||
}
|
||||
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS)) {
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
bt_mesh_beacon_ivu_initiator(true);
|
||||
#endif
|
||||
bt_mesh_net_iv_update(bt_mesh.iv_index, false);
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_store_iv(true);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NODE)
|
||||
void bt_mesh_net_start(void)
|
||||
{
|
||||
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
|
||||
@ -1533,7 +1517,6 @@ void bt_mesh_net_start(void)
|
||||
bt_mesh_prov_complete(net_idx, net_key, addr, flags, iv_index);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void bt_mesh_net_init(void)
|
||||
{
|
||||
@ -1541,3 +1524,34 @@ void bt_mesh_net_init(void)
|
||||
|
||||
k_work_init(&bt_mesh.local_work, bt_mesh_net_local);
|
||||
}
|
||||
|
||||
void bt_mesh_net_deinit(bool erase)
|
||||
{
|
||||
k_delayed_work_free(&bt_mesh.ivu_timer);
|
||||
|
||||
k_work_init(&bt_mesh.local_work, NULL);
|
||||
|
||||
/* Local queue uses a while loop, currently no need
|
||||
* to handle this.
|
||||
*/
|
||||
|
||||
#if FRIEND_CRED_COUNT > 0
|
||||
memset(friend_cred, 0, sizeof(friend_cred));
|
||||
#endif
|
||||
|
||||
memset(msg_cache, 0, sizeof(msg_cache));
|
||||
msg_cache_next = 0U;
|
||||
|
||||
memset(dup_cache, 0, sizeof(dup_cache));
|
||||
dup_cache_next = 0U;
|
||||
|
||||
bt_mesh.iv_index = 0U;
|
||||
bt_mesh.seq = 0U;
|
||||
|
||||
memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags));
|
||||
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_seq();
|
||||
bt_mesh_clear_iv();
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
#ifndef _NET_H_
|
||||
#define _NET_H_
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_access.h"
|
||||
|
||||
#define BLE_MESH_NET_FLAG_KR BIT(0)
|
||||
@ -208,7 +206,10 @@ struct bt_mesh_lpn {
|
||||
|
||||
/* bt_mesh_net.flags */
|
||||
enum {
|
||||
BLE_MESH_NODE, /* Device is a node */
|
||||
BLE_MESH_PROVISIONER, /* Device is a Provisioner */
|
||||
BLE_MESH_VALID, /* We have been provisioned */
|
||||
BLE_MESH_VALID_PROV, /* Provisioner has been enabled */
|
||||
BLE_MESH_SUSPENDED, /* Network is temporarily suspended */
|
||||
BLE_MESH_IVU_IN_PROGRESS, /* IV Update in Progress */
|
||||
BLE_MESH_IVU_INITIATOR, /* IV Update initiated by us */
|
||||
@ -319,6 +320,8 @@ extern struct bt_mesh_net bt_mesh;
|
||||
|
||||
#define BLE_MESH_NET_HDR_LEN 9
|
||||
|
||||
void bt_mesh_msg_cache_clear(u16_t unicast_addr, u8_t elem_num);
|
||||
|
||||
int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
|
||||
const u8_t key[16]);
|
||||
|
||||
@ -361,11 +364,15 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
||||
void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
|
||||
enum bt_mesh_net_if net_if);
|
||||
|
||||
bool bt_mesh_primary_subnet_exist(void);
|
||||
|
||||
u32_t bt_mesh_next_seq(void);
|
||||
|
||||
void bt_mesh_net_start(void);
|
||||
|
||||
void bt_mesh_net_init(void);
|
||||
void bt_mesh_net_deinit(bool erase);
|
||||
|
||||
void bt_mesh_net_header_parse(struct net_buf_simple *buf,
|
||||
struct bt_mesh_net_rx *rx);
|
||||
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "osi/alarm.h"
|
||||
|
||||
@ -24,16 +22,9 @@
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
|
||||
#include "mesh_hci.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_atomic.h"
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#include "provisioner_prov.h"
|
||||
#include "mesh_common.h"
|
||||
#include "mesh_aes_encrypt.h"
|
||||
#include "provisioner_prov.h"
|
||||
|
||||
/** @def BT_UUID_MESH_PROV
|
||||
* @brief Mesh Provisioning Service
|
||||
@ -72,7 +63,7 @@ struct bt_mesh_dev bt_mesh_dev;
|
||||
|
||||
/* P-256 Variables */
|
||||
static u8_t bt_mesh_public_key[64];
|
||||
static BT_OCTET32 bt_mesh_private_key = {
|
||||
static u8_t bt_mesh_private_key[32] = {
|
||||
0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38,
|
||||
0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
|
||||
0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99,
|
||||
@ -90,25 +81,25 @@ static sys_slist_t bt_mesh_gatts_db;
|
||||
static struct bt_mesh_conn bt_mesh_gatts_conn[BLE_MESH_MAX_CONN];
|
||||
static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb;
|
||||
|
||||
static BD_ADDR bt_mesh_gatts_addr;
|
||||
static u8_t bt_mesh_gatts_addr[6];
|
||||
|
||||
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
|
||||
|
||||
esp_err_t bt_mesh_host_init(void)
|
||||
int bt_mesh_host_init(void)
|
||||
{
|
||||
int rc;
|
||||
rc = btc_init();
|
||||
if (rc != 0) {
|
||||
return ESP_FAIL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = osi_alarm_create_mux();
|
||||
if (rc != 0) {
|
||||
return ESP_FAIL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
osi_alarm_init();
|
||||
return ESP_OK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ble_hs_hci_get_hci_version(void);
|
||||
@ -401,7 +392,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
if (bt_mesh_scan_dev_found_cb) {
|
||||
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, buf);
|
||||
}
|
||||
osi_free(buf);
|
||||
bt_mesh_free(buf);
|
||||
break;
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
@ -453,7 +444,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
*/
|
||||
#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);
|
||||
bt_mesh_provisioner_clear_link_info(bt_mesh_gattc_info[i].addr.val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -464,14 +455,14 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
*/
|
||||
#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);
|
||||
bt_mesh_provisioner_clear_link_info(bt_mesh_gattc_info[i].addr.val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#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();
|
||||
bt_mesh_provisioner_pbg_count_dec();
|
||||
}
|
||||
#endif
|
||||
/* Reset corresponding gattc info */
|
||||
@ -1710,7 +1701,7 @@ int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u
|
||||
{
|
||||
uint8_t dhkey[32];
|
||||
|
||||
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, BT_OCTET32_LEN));
|
||||
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, 32));
|
||||
|
||||
ble_sm_alg_gen_dhkey((uint8_t *)&remote_pk[0], (uint8_t *)&remote_pk[32], bt_mesh_private_key, dhkey);
|
||||
|
||||
|
@ -9,21 +9,15 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_PROV)
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_uuid.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_proxy.h"
|
||||
|
||||
#include "crypto.h"
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_common.h"
|
||||
#include "mesh_proxy.h"
|
||||
#include "proxy_server.h"
|
||||
#include "prov.h"
|
||||
|
||||
@ -199,6 +193,32 @@ static struct prov_link link;
|
||||
|
||||
static const struct bt_mesh_prov *prov;
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_ADV)
|
||||
static bt_mesh_mutex_t pb_buf_lock;
|
||||
|
||||
static void bt_mesh_pb_buf_mutex_new(void)
|
||||
{
|
||||
if (!pb_buf_lock.mutex) {
|
||||
bt_mesh_mutex_create(&pb_buf_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_pb_buf_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&pb_buf_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_pb_buf_lock(void)
|
||||
{
|
||||
bt_mesh_mutex_lock(&pb_buf_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_pb_buf_unlock(void)
|
||||
{
|
||||
bt_mesh_mutex_unlock(&pb_buf_lock);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_PB_ADV */
|
||||
|
||||
static void reset_state(void)
|
||||
{
|
||||
k_delayed_work_cancel(&link.prot_timer);
|
||||
@ -252,6 +272,8 @@ static void free_segments(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
bt_mesh_pb_buf_lock();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) {
|
||||
struct net_buf *buf = link.tx.buf[i];
|
||||
|
||||
@ -265,6 +287,8 @@ static void free_segments(void)
|
||||
BLE_MESH_ADV(buf)->busy = 0U;
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
bt_mesh_pb_buf_unlock();
|
||||
}
|
||||
|
||||
static void prov_clear_tx(void)
|
||||
@ -295,7 +319,7 @@ static void reset_adv_link(void)
|
||||
|
||||
static struct net_buf *adv_buf_create(void)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
buf = bt_mesh_adv_create(BLE_MESH_ADV_PROV, PROV_XMIT, BUF_TIMEOUT);
|
||||
if (!buf) {
|
||||
@ -319,8 +343,8 @@ static void gen_prov_ack_send(u8_t xact_id)
|
||||
static const struct bt_mesh_send_cb cb = {
|
||||
.start = ack_complete,
|
||||
};
|
||||
const struct bt_mesh_send_cb *complete;
|
||||
struct net_buf *buf;
|
||||
const struct bt_mesh_send_cb *complete = NULL;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("xact_id %u", xact_id);
|
||||
|
||||
@ -372,7 +396,7 @@ static void send_reliable(void)
|
||||
|
||||
static int bearer_ctl_send(u8_t op, void *data, u8_t data_len)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("op 0x%02x data_len %u", op, data_len);
|
||||
|
||||
@ -418,9 +442,9 @@ static inline u8_t next_transaction_id(void)
|
||||
|
||||
static int prov_send_adv(struct net_buf_simple *msg)
|
||||
{
|
||||
struct net_buf *start, *buf;
|
||||
u8_t seg_len, seg_id;
|
||||
u8_t xact_id;
|
||||
struct net_buf *start = NULL, *buf = NULL;
|
||||
u8_t seg_len = 0U, seg_id = 0U;
|
||||
u8_t xact_id = 0U;
|
||||
s32_t timeout = PROTOCOL_TIMEOUT;
|
||||
|
||||
BT_DBG("%s, len %u: %s", __func__, msg->len, bt_hex(msg->data, msg->len));
|
||||
@ -602,7 +626,7 @@ static void prov_invite(const u8_t *data)
|
||||
|
||||
static void prov_capabilities(const u8_t *data)
|
||||
{
|
||||
u16_t algorithms, output_action, input_action;
|
||||
u16_t algorithms = 0U, output_action = 0U, input_action = 0U;
|
||||
|
||||
BT_DBG("Elements: %u", data[0]);
|
||||
|
||||
@ -620,6 +644,10 @@ static void prov_capabilities(const u8_t *data)
|
||||
|
||||
input_action = sys_get_be16(&data[9]);
|
||||
BT_DBG("Input OOB Action: 0x%04x", input_action);
|
||||
|
||||
((void) algorithms);
|
||||
((void) output_action);
|
||||
((void) input_action);
|
||||
}
|
||||
|
||||
static bt_mesh_output_action_t output_action(u8_t action)
|
||||
@ -658,8 +686,8 @@ static bt_mesh_input_action_t input_action(u8_t action)
|
||||
|
||||
static int prov_auth(u8_t method, u8_t action, u8_t size)
|
||||
{
|
||||
bt_mesh_output_action_t output;
|
||||
bt_mesh_input_action_t input;
|
||||
bt_mesh_output_action_t output = 0U;
|
||||
bt_mesh_input_action_t input = 0U;
|
||||
|
||||
switch (method) {
|
||||
case AUTH_METHOD_NO_OOB:
|
||||
@ -695,8 +723,8 @@ static int prov_auth(u8_t method, u8_t action, u8_t size)
|
||||
}
|
||||
|
||||
if (output == BLE_MESH_DISPLAY_STRING) {
|
||||
unsigned char str[9];
|
||||
u8_t i;
|
||||
unsigned char str[9] = {'\0'};
|
||||
u8_t i = 0U;
|
||||
|
||||
bt_mesh_rand(str, size);
|
||||
|
||||
@ -720,7 +748,7 @@ static int prov_auth(u8_t method, u8_t action, u8_t size)
|
||||
u32_t div[8] = { 10, 100, 1000, 10000, 100000,
|
||||
1000000, 10000000, 100000000
|
||||
};
|
||||
u32_t num;
|
||||
u32_t num = 0U;
|
||||
|
||||
bt_mesh_rand(&num, sizeof(num));
|
||||
num %= div[size - 1];
|
||||
@ -760,11 +788,11 @@ static int prov_auth(u8_t method, u8_t action, u8_t size)
|
||||
|
||||
static void prov_start(const u8_t *data)
|
||||
{
|
||||
BT_DBG("Algorithm: 0x%02x", data[0]);
|
||||
BT_DBG("Public Key: 0x%02x", data[1]);
|
||||
BT_DBG("Auth Method: 0x%02x", data[2]);
|
||||
BT_DBG("Auth Action: 0x%02x", data[3]);
|
||||
BT_DBG("Auth Size: 0x%02x", data[4]);
|
||||
BT_INFO("Algorithm: 0x%02x", data[0]);
|
||||
BT_INFO("Public Key: 0x%02x", data[1]);
|
||||
BT_INFO("Auth Method: 0x%02x", data[2]);
|
||||
BT_INFO("Auth Action: 0x%02x", data[3]);
|
||||
BT_INFO("Auth Size: 0x%02x", data[4]);
|
||||
|
||||
if (data[0] != PROV_ALG_P256) {
|
||||
BT_ERR("%s, Unknown algorithm 0x%02x", __func__, data[0]);
|
||||
@ -860,7 +888,7 @@ static void send_input_complete(void)
|
||||
|
||||
int bt_mesh_input_number(u32_t num)
|
||||
{
|
||||
BT_DBG("%u", num);
|
||||
BT_INFO("%u", num);
|
||||
|
||||
if (!bt_mesh_atomic_test_and_clear_bit(link.flags, WAIT_NUMBER)) {
|
||||
return -EINVAL;
|
||||
@ -883,7 +911,7 @@ int bt_mesh_input_number(u32_t num)
|
||||
|
||||
int bt_mesh_input_string(const char *str)
|
||||
{
|
||||
BT_DBG("%s", str);
|
||||
BT_INFO("%s", str);
|
||||
|
||||
if (!bt_mesh_atomic_test_and_clear_bit(link.flags, WAIT_STRING)) {
|
||||
return -EINVAL;
|
||||
@ -933,7 +961,7 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx)
|
||||
static void send_pub_key(void)
|
||||
{
|
||||
PROV_BUF(buf, 65);
|
||||
const u8_t *key;
|
||||
const u8_t *key = NULL;
|
||||
|
||||
/* Copy remote key in little-endian for bt_mesh_dh_key_gen().
|
||||
* X and Y halves are swapped independently. Use response
|
||||
@ -1083,7 +1111,7 @@ static void prov_confirm(const u8_t *data)
|
||||
static void prov_random(const u8_t *data)
|
||||
{
|
||||
PROV_BUF(rnd, 17);
|
||||
u8_t conf_verify[16];
|
||||
u8_t conf_verify[16] = {0};
|
||||
|
||||
BT_DBG("Remote Random: %s", bt_hex(data, 16));
|
||||
|
||||
@ -1133,16 +1161,16 @@ static inline bool is_pb_gatt(void)
|
||||
static void prov_data(const u8_t *data)
|
||||
{
|
||||
PROV_BUF(msg, 1);
|
||||
u8_t session_key[16];
|
||||
u8_t nonce[13];
|
||||
u8_t dev_key[16];
|
||||
u8_t pdu[25];
|
||||
u8_t flags;
|
||||
u32_t iv_index;
|
||||
u16_t addr;
|
||||
u16_t net_idx;
|
||||
int err;
|
||||
bool identity_enable;
|
||||
u8_t session_key[16] = {0};
|
||||
u8_t nonce[13] = {0};
|
||||
u8_t dev_key[16] = {0};
|
||||
u8_t pdu[25] = {0};
|
||||
u8_t flags = 0U;
|
||||
u32_t iv_index = 0U;
|
||||
u16_t addr = 0U;
|
||||
u16_t net_idx = 0U;
|
||||
int err = 0;
|
||||
bool identity_enable = false;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -1269,6 +1297,8 @@ static void prov_retransmit(struct k_work *work)
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_pb_buf_lock();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) {
|
||||
struct net_buf *buf = link.tx.buf[i];
|
||||
|
||||
@ -1289,6 +1319,8 @@ static void prov_retransmit(struct k_work *work)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bt_mesh_pb_buf_unlock();
|
||||
}
|
||||
|
||||
static void link_open(struct prov_rx *rx, struct net_buf_simple *buf)
|
||||
@ -1447,7 +1479,7 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf)
|
||||
prov_send_fail_msg(PROV_ERR_NVAL_FMT);
|
||||
return;
|
||||
} else if (seg == link.rx.last_seg) {
|
||||
u8_t expect_len;
|
||||
u8_t expect_len = 0U;
|
||||
|
||||
expect_len = (link.rx.buf->len - 20U -
|
||||
((link.rx.last_seg - 1) * 23U));
|
||||
@ -1563,7 +1595,7 @@ static void gen_prov_recv(struct prov_rx *rx, struct net_buf_simple *buf)
|
||||
|
||||
void bt_mesh_pb_adv_recv(struct net_buf_simple *buf)
|
||||
{
|
||||
struct prov_rx rx;
|
||||
struct prov_rx rx = {0};
|
||||
|
||||
if (!bt_prov_active() && bt_mesh_is_provisioned()) {
|
||||
BT_DBG("Ignoring provisioning PDU - already provisioned");
|
||||
@ -1593,7 +1625,7 @@ void bt_mesh_pb_adv_recv(struct net_buf_simple *buf)
|
||||
#if defined(CONFIG_BLE_MESH_PB_GATT)
|
||||
int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t type;
|
||||
u8_t type = 0U;
|
||||
|
||||
BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
@ -1683,7 +1715,7 @@ bool bt_prov_active(void)
|
||||
|
||||
static void protocol_timeout(struct k_work *work)
|
||||
{
|
||||
BT_DBG("Protocol timeout");
|
||||
BT_WARN("Protocol timeout");
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_GATT)
|
||||
if (link.conn) {
|
||||
@ -1728,6 +1760,40 @@ int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)
|
||||
|
||||
reset_state();
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_ADV)
|
||||
bt_mesh_pb_buf_mutex_new();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_prov_deinit(void)
|
||||
{
|
||||
if (prov == NULL) {
|
||||
BT_ERR("%s, No provisioning context provided", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
k_delayed_work_free(&link.prot_timer);
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_ADV)
|
||||
prov_clear_tx();
|
||||
k_delayed_work_free(&link.tx.retransmit);
|
||||
#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);
|
||||
#endif /* CONFIG_BLE_MESH_USE_DUPLICATE_SCAN */
|
||||
#endif /* CONFIG_BLE_MESH_PB_ADV */
|
||||
|
||||
(void)memset(&link, 0, sizeof(link));
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_ADV)
|
||||
bt_mesh_pb_buf_mutex_free();
|
||||
#endif
|
||||
|
||||
prov = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define _PROV_H_
|
||||
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
void bt_mesh_pb_adv_recv(struct net_buf_simple *buf);
|
||||
@ -27,6 +26,7 @@ int bt_mesh_set_oob_pub_key(const u8_t pub_key_x[32], const u8_t pub_key_y[32],
|
||||
const struct bt_mesh_prov *bt_mesh_prov_get(void);
|
||||
|
||||
int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
|
||||
int bt_mesh_prov_deinit(void);
|
||||
|
||||
void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index);
|
||||
void bt_mesh_prov_reset(void);
|
||||
|
@ -1,71 +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 <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_BEACON)
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_trace.h"
|
||||
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "prov.h"
|
||||
#include "crypto.h"
|
||||
#include "beacon.h"
|
||||
#include "foundation.h"
|
||||
#include "provisioner_prov.h"
|
||||
|
||||
#define BEACON_TYPE_UNPROVISIONED 0x00
|
||||
#define BEACON_TYPE_SECURE 0x01
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
|
||||
static void provisioner_secure_beacon_recv(struct net_buf_simple *buf)
|
||||
{
|
||||
// TODO: Provisioner receive and handle Secure Network Beacon
|
||||
}
|
||||
|
||||
void provisioner_beacon_recv(struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t type;
|
||||
|
||||
BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
if (buf->len < 1) {
|
||||
BT_ERR("%s, Too short beacon", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
type = net_buf_simple_pull_u8(buf);
|
||||
switch (type) {
|
||||
case BEACON_TYPE_UNPROVISIONED:
|
||||
BT_DBG("Unprovisioned device beacon received");
|
||||
provisioner_unprov_beacon_recv(buf);
|
||||
break;
|
||||
case BEACON_TYPE_SECURE:
|
||||
provisioner_secure_beacon_recv(buf);
|
||||
break;
|
||||
default:
|
||||
BT_DBG("%s, Unknown beacon type 0x%02x", __func__, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
@ -1,20 +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_BEACON_H_
|
||||
#define _PROVISIONER_BEACON_H_
|
||||
|
||||
void provisioner_beacon_recv(struct net_buf_simple *buf);
|
||||
|
||||
#endif /* _PROVISIONER_BEACON_H_ */
|
File diff suppressed because it is too large
Load Diff
@ -15,101 +15,120 @@
|
||||
#ifndef _PROVISIONER_MAIN_H_
|
||||
#define _PROVISIONER_MAIN_H_
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_access.h"
|
||||
#include "net.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#define MESH_NAME_SIZE 31
|
||||
#define BLE_MESH_INVALID_NODE_INDEX 0xFFFF
|
||||
#define BLE_MESH_NODE_NAME_SIZE 31
|
||||
|
||||
/* Each node information stored by provisioner */
|
||||
struct bt_mesh_node_t {
|
||||
char node_name[MESH_NAME_SIZE]; /* Node name */
|
||||
u8_t dev_uuid[16]; /* Device UUID pointer, stored in provisioner_prov.c */
|
||||
u16_t oob_info; /* Node OOB information */
|
||||
u16_t unicast_addr; /* Node unicast address */
|
||||
u8_t element_num; /* Node element number */
|
||||
u16_t net_idx; /* Node provision net_idx */
|
||||
u8_t flags; /* Node key refresh flag and iv update flag */
|
||||
u32_t iv_index; /* Node IV Index */
|
||||
u8_t dev_key[16]; /* Node device key */
|
||||
struct bt_mesh_node {
|
||||
/* Device information */
|
||||
u8_t addr[6]; /* Node device address */
|
||||
u8_t addr_type; /* Node device address type */
|
||||
u8_t dev_uuid[16]; /* Node Device UUID */
|
||||
u16_t oob_info; /* Node OOB information */
|
||||
|
||||
/* Provisioning information */
|
||||
u16_t unicast_addr; /* Node unicast address */
|
||||
u8_t element_num; /* Node element number */
|
||||
u16_t net_idx; /* Node NetKey Index */
|
||||
u8_t flags; /* Node key refresh flag and iv update flag */
|
||||
u32_t iv_index; /* Node IV Index */
|
||||
u8_t dev_key[16]; /* Node device key */
|
||||
|
||||
/* Additional information */
|
||||
char name[BLE_MESH_NODE_NAME_SIZE]; /* Node name */
|
||||
u16_t comp_length; /* Length of Composition Data */
|
||||
u8_t *comp_data; /* Value of Composition Data */
|
||||
} __packed;
|
||||
|
||||
/* The following APIs are for key init, node provision & node reset. */
|
||||
int bt_mesh_provisioner_init(void);
|
||||
|
||||
int provisioner_node_provision(int node_index, const u8_t uuid[16], u16_t oob_info,
|
||||
u16_t unicast_addr, u8_t element_num, u16_t net_idx,
|
||||
u8_t flags, u32_t iv_index, const u8_t dev_key[16]);
|
||||
int bt_mesh_provisioner_net_create(void);
|
||||
|
||||
int provisioner_node_reset(int node_index);
|
||||
int bt_mesh_provisioner_deinit(bool erase);
|
||||
|
||||
int provisioner_upper_reset_all_nodes(void);
|
||||
bool bt_mesh_provisioner_check_is_addr_dup(u16_t addr, u8_t elem_num, bool comp_with_own);
|
||||
|
||||
int provisioner_upper_init(void);
|
||||
u16_t bt_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
/* The following APIs are for provisioner upper layers internal usage. */
|
||||
u16_t bt_mesh_provisioner_get_all_node_count(void);
|
||||
|
||||
const u8_t *provisioner_net_key_get(u16_t net_idx);
|
||||
int bt_mesh_provisioner_restore_node_info(struct bt_mesh_node *node, bool prov);
|
||||
|
||||
struct bt_mesh_subnet *provisioner_subnet_get(u16_t net_idx);
|
||||
int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16], u16_t oob_info,
|
||||
u16_t unicast_addr, u8_t element_num, u16_t net_idx, u8_t flags,
|
||||
u32_t iv_index, const u8_t dev_key[16], u16_t *index);
|
||||
|
||||
bool provisioner_check_msg_dst_addr(u16_t dst_addr);
|
||||
bool bt_mesh_provisioner_find_node_with_uuid(const u8_t uuid[16], bool reset);
|
||||
|
||||
const u8_t *provisioner_dev_key_get(u16_t dst_addr);
|
||||
bool bt_mesh_provisioner_find_node_with_addr(const bt_mesh_addr_t *addr, bool reset);
|
||||
|
||||
struct bt_mesh_app_key *provisioner_app_key_find(u16_t app_idx);
|
||||
int bt_mesh_provisioner_remove_node(const u8_t uuid[16]);
|
||||
|
||||
u32_t provisioner_get_prov_node_count(void);
|
||||
int bt_mesh_provisioner_restore_node_name(u16_t addr, const char *name);
|
||||
|
||||
/* The following APIs are for provisioner application use. */
|
||||
int bt_mesh_provisioner_restore_node_comp_data(u16_t addr, const u8_t *data, u16_t length, bool prov);
|
||||
|
||||
int bt_mesh_provisioner_store_node_info(struct bt_mesh_node_t *node_info);
|
||||
int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node);
|
||||
|
||||
int bt_mesh_provisioner_get_all_node_unicast_addr(struct net_buf_simple *buf);
|
||||
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const u8_t uuid[16]);
|
||||
|
||||
int bt_mesh_provisioner_set_node_name(int node_index, const char *name);
|
||||
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_addr(u16_t unicast_addr);
|
||||
|
||||
const char *bt_mesh_provisioner_get_node_name(int node_index);
|
||||
int bt_mesh_provisioner_delete_node_with_uuid(const u8_t uuid[16]);
|
||||
|
||||
int bt_mesh_provisioner_get_node_index(const char *name);
|
||||
int bt_mesh_provisioner_delete_node_with_addr(u16_t unicast_addr);
|
||||
|
||||
struct bt_mesh_node_t *bt_mesh_provisioner_get_node_info(u16_t unicast_addr);
|
||||
int bt_mesh_provisioner_set_node_name(u16_t index, const char *name);
|
||||
|
||||
u32_t bt_mesh_provisioner_get_net_key_count(void);
|
||||
const char *bt_mesh_provisioner_get_node_name(u16_t index);
|
||||
|
||||
u32_t bt_mesh_provisioner_get_app_key_count(void);
|
||||
u16_t bt_mesh_provisioner_get_node_index(const char *name);
|
||||
|
||||
int bt_mesh_provisioner_store_node_comp_data(u16_t addr, const u8_t *data, u16_t length);
|
||||
|
||||
const u8_t *bt_mesh_provisioner_net_key_get(u16_t net_idx);
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_provisioner_subnet_get(u16_t net_idx);
|
||||
|
||||
bool bt_mesh_provisioner_check_msg_dst(u16_t dst);
|
||||
|
||||
const u8_t *bt_mesh_provisioner_dev_key_get(u16_t dst);
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_provisioner_app_key_find(u16_t app_idx);
|
||||
|
||||
int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, u16_t *app_idx);
|
||||
|
||||
int bt_mesh_provisioner_local_app_key_update(const u8_t app_key[16], u16_t net_idx, u16_t app_idx);
|
||||
|
||||
const u8_t *bt_mesh_provisioner_local_app_key_get(u16_t net_idx, u16_t app_idx);
|
||||
|
||||
int bt_mesh_provisioner_local_app_key_delete(u16_t net_idx, u16_t app_idx);
|
||||
|
||||
int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx);
|
||||
|
||||
int bt_mesh_provisioner_local_net_key_update(const u8_t net_key[16], u16_t net_idx);
|
||||
|
||||
const u8_t *bt_mesh_provisioner_local_net_key_get(u16_t net_idx);
|
||||
|
||||
int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx);
|
||||
|
||||
int bt_mesh_provisioner_get_own_unicast_addr(u16_t *addr, u8_t *elem_num);
|
||||
|
||||
/* Provisioner bind local client model with proper appkey index */
|
||||
int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id,
|
||||
u16_t cid, u16_t app_idx);
|
||||
|
||||
/* This API can be used to change the net_idx binded with the app_idx. */
|
||||
int bt_mesh_provisioner_bind_local_app_net_idx(u16_t net_idx, u16_t app_idx);
|
||||
|
||||
/* Provisioner print own element information */
|
||||
int bt_mesh_provisioner_print_local_element_info(void);
|
||||
int bt_mesh_print_local_composition_data(void);
|
||||
|
||||
/* The following APIs are for fast provisioning */
|
||||
|
||||
const u8_t *fast_prov_dev_key_get(u16_t dst_addr);
|
||||
const u8_t *bt_mesh_fast_prov_dev_key_get(u16_t dst);
|
||||
|
||||
struct bt_mesh_subnet *fast_prov_subnet_get(u16_t net_idx);
|
||||
struct bt_mesh_subnet *bt_mesh_fast_prov_subnet_get(u16_t net_idx);
|
||||
|
||||
struct bt_mesh_app_key *fast_prov_app_key_find(u16_t net_idx, u16_t app_idx);
|
||||
struct bt_mesh_app_key *bt_mesh_fast_prov_app_key_find(u16_t app_idx);
|
||||
|
||||
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,8 +15,8 @@
|
||||
#ifndef _PROVISIONER_PROV_H_
|
||||
#define _PROVISIONER_PROV_H_
|
||||
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#if !CONFIG_BLE_MESH_PROVISIONER
|
||||
|
||||
@ -73,7 +73,7 @@ struct bt_mesh_prov_data_info {
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void provisioner_pbg_count_dec(void);
|
||||
void bt_mesh_provisioner_pbg_count_dec(void);
|
||||
|
||||
/**
|
||||
* @brief This function clears the part of the link info of the proper device.
|
||||
@ -82,7 +82,7 @@ void provisioner_pbg_count_dec(void);
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void provisioner_clear_link_conn_info(const u8_t addr[6]);
|
||||
void bt_mesh_provisioner_clear_link_info(const u8_t addr[6]);
|
||||
|
||||
/**
|
||||
* @brief This function handles the received PB-ADV PDUs.
|
||||
@ -91,7 +91,7 @@ void provisioner_clear_link_conn_info(const u8_t addr[6]);
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
void provisioner_pb_adv_recv(struct net_buf_simple *buf);
|
||||
void bt_mesh_provisioner_pb_adv_recv(struct net_buf_simple *buf);
|
||||
|
||||
/**
|
||||
* @brief This function sends provisioning invite to start
|
||||
@ -102,7 +102,7 @@ void provisioner_pb_adv_recv(struct net_buf_simple *buf);
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int provisioner_set_prov_conn(const u8_t addr[6], struct bt_mesh_conn *conn);
|
||||
int bt_mesh_provisioner_set_prov_conn(const u8_t addr[6], struct bt_mesh_conn *conn);
|
||||
|
||||
/**
|
||||
* @brief This function sends provisioning invite to start
|
||||
@ -113,7 +113,7 @@ int provisioner_set_prov_conn(const u8_t addr[6], struct bt_mesh_conn *conn);
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr);
|
||||
int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr);
|
||||
|
||||
/**
|
||||
* @brief This function resets the used information when
|
||||
@ -124,7 +124,7 @@ int provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr);
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int provisioner_pb_gatt_close(struct bt_mesh_conn *conn, u8_t reason);
|
||||
int bt_mesh_provisioner_pb_gatt_close(struct bt_mesh_conn *conn, u8_t reason);
|
||||
|
||||
/**
|
||||
* @brief This function handles the received PB-GATT provision
|
||||
@ -135,7 +135,7 @@ int provisioner_pb_gatt_close(struct bt_mesh_conn *conn, u8_t reason);
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf);
|
||||
int bt_mesh_provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf);
|
||||
|
||||
/**
|
||||
* @brief This function initializes provisioner's PB-GATT and PB-ADV
|
||||
@ -145,34 +145,40 @@ int provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *b
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int provisioner_prov_init(const struct bt_mesh_prov *prov_info);
|
||||
int bt_mesh_provisioner_prov_init(const struct bt_mesh_prov *prov_info);
|
||||
|
||||
/**
|
||||
* @brief This function deinitializes provisioner's PB-GATT and PB-ADV
|
||||
* related information.
|
||||
*
|
||||
* @param[in] erase: Indicate if erasing provisioning information from flash.
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_provisioner_prov_deinit(bool erase);
|
||||
|
||||
/**
|
||||
* @brief This function parses the received unprovisioned device
|
||||
* beacon advertising packets, and if checked, starts to provision this device
|
||||
* using PB-ADV bearer.
|
||||
*
|
||||
* @param[in] buf: Pointer to the buffer containing unprovisioned device beacon
|
||||
* @param[in] buf: Pointer to the buffer containing unprovisioned device beacon
|
||||
* @param[in] rssi: RSSI of the received unprovisioned device beacon
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void provisioner_unprov_beacon_recv(struct net_buf_simple *buf);
|
||||
void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, s8_t rssi);
|
||||
|
||||
void provisioner_prov_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr);
|
||||
void bt_mesh_provisioner_prov_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi);
|
||||
|
||||
/**
|
||||
* @brief This function gets the bt_mesh_prov pointer.
|
||||
*
|
||||
* @return bt_mesh_prov pointer(prov)
|
||||
*/
|
||||
const struct bt_mesh_prov *provisioner_get_prov_info(void);
|
||||
const struct bt_mesh_prov *bt_mesh_provisioner_get_prov_info(void);
|
||||
|
||||
/**
|
||||
* @brief This function resets all nodes information in provisioner_prov.c.
|
||||
*
|
||||
* @return Zero
|
||||
*/
|
||||
int provisioner_prov_reset_all_nodes(void);
|
||||
void bt_mesh_provisoner_restore_prov_info(u16_t primary_addr, u16_t alloc_addr);
|
||||
|
||||
/* The following APIs are for primary provisioner application use */
|
||||
|
||||
@ -186,7 +192,7 @@ int provisioner_prov_reset_all_nodes(void);
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*
|
||||
* @Note: 1. Currently address type only supports public address and static random address.
|
||||
* @note 1. Currently address type only supports public address and static random address.
|
||||
* 2. If device UUID and/or device address and address type already exist in the
|
||||
* device queue, but the bearer differs from the existing one, add operation
|
||||
* will also be successful and it will update the provision bearer supported by
|
||||
@ -194,6 +200,24 @@ int provisioner_prov_reset_all_nodes(void);
|
||||
*/
|
||||
int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u8_t flags);
|
||||
|
||||
/** @brief Provision an unprovisioned device with fixed unicast address.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the unprovisioned device
|
||||
* @param[in] addr: Device address of the unprovisioned device
|
||||
* @param[in] addr_type: Device address type of the unprovisioned device
|
||||
* @param[in] bearer: Provisioning bearer going to be used
|
||||
* @param[in] oob_info: OOB info of the unprovisioned device
|
||||
* @param[in] unicast_addr: Unicast address going to be allocated for the unprovisioned device
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*
|
||||
* @note 1. Currently address type only supports public address and static random address.
|
||||
* 2. Bearer must be equal to BLE_MESH_PROV_ADV or BLE_MESH_PROV_GATT
|
||||
*/
|
||||
int bt_mesh_provisioner_prov_device_with_addr(const u8_t uuid[16], const u8_t addr[6],
|
||||
u8_t addr_type, bt_mesh_prov_bearer_t bearer,
|
||||
u16_t oob_info, u16_t unicast_addr);
|
||||
|
||||
/** @brief Delete device from queue, reset current provisioning link and reset the node
|
||||
*
|
||||
* @param[in] del_dev: Pointer to the structure containing the device information
|
||||
@ -229,11 +253,12 @@ int bt_mesh_provisioner_set_dev_uuid_match(u8_t offset, u8_t length,
|
||||
* @param adv_type Adv packet type, currently this is not used and we can use bearer to device
|
||||
* the adv_type(ADV_IND or ADV_NONCONN_IND). This parameter will be used, when
|
||||
* scan response data will be supported.
|
||||
* @param rssi RSSI of the received advertising packet
|
||||
*
|
||||
*/
|
||||
typedef void (*unprov_adv_pkt_cb_t)(const u8_t addr[6], const u8_t addr_type,
|
||||
const u8_t adv_type, const u8_t dev_uuid[16],
|
||||
u16_t oob_info, bt_mesh_prov_bearer_t bearer);
|
||||
u16_t oob_info, bt_mesh_prov_bearer_t bearer, s8_t rssi);
|
||||
|
||||
/**
|
||||
* @brief This function registers the callback which notifies the application
|
||||
@ -244,7 +269,7 @@ typedef void (*unprov_adv_pkt_cb_t)(const u8_t addr[6], const u8_t addr_type,
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_prov_adv_pkt_cb_register(unprov_adv_pkt_cb_t cb);
|
||||
int bt_mesh_provisioner_adv_pkt_cb_register(unprov_adv_pkt_cb_t cb);
|
||||
|
||||
/**
|
||||
* @brief This function changes net_idx or flags or iv_index used in provisioning data.
|
||||
@ -255,6 +280,57 @@ int bt_mesh_prov_adv_pkt_cb_register(unprov_adv_pkt_cb_t cb);
|
||||
*/
|
||||
int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info);
|
||||
|
||||
/**
|
||||
* @brief This function sets the provisioning information needed by Provisioner,
|
||||
* including unicast address, IV Index, etc.
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_provisioner_set_prov_info(void);
|
||||
|
||||
/**
|
||||
* @brief This function sets the provisioning bearer type used by Provisioner.
|
||||
*
|
||||
* @param[in] bearers: Provisioning bearer type
|
||||
* @param[in] clear: Indicate if the corresponding bearer type will be cleared
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void bt_mesh_provisioner_set_prov_bearer(bt_mesh_prov_bearer_t bearers, bool clear);
|
||||
|
||||
/**
|
||||
* @brief This function gets the provisioning bearer type used by Provisioner.
|
||||
*
|
||||
* @return Currently supported provisioning bearer type
|
||||
*/
|
||||
bt_mesh_prov_bearer_t bt_mesh_provisioner_get_prov_bearer(void);
|
||||
|
||||
/**
|
||||
* @brief This function sets the Static OOB value used by Provisioner.
|
||||
*
|
||||
* @param[in] value: Static OOB value
|
||||
* @param[in] length: Static OOB value length
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_provisioner_set_static_oob_value(const u8_t *value, u8_t length);
|
||||
|
||||
/**
|
||||
* @brief This function gets the unicast address of primary element of Provisioner.
|
||||
*
|
||||
* @return Unicast address of primary element of Provisioner.
|
||||
*/
|
||||
u16_t bt_mesh_provisioner_get_primary_elem_addr(void);
|
||||
|
||||
/**
|
||||
* @brief This function sets the unicast address of primary element of Provisioner.
|
||||
*
|
||||
* @param[in] addr: unicast address of primary element
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_provisioner_set_primary_elem_addr(u16_t addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to input number/string out-put by unprovisioned device.
|
||||
*
|
||||
@ -264,7 +340,7 @@ int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info);
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_prov_set_oob_input_data(const u8_t idx, const u8_t *val, bool num_flag);
|
||||
int bt_mesh_provisioner_set_oob_input_data(const u8_t idx, const u8_t *val, bool num_flag);
|
||||
|
||||
/**
|
||||
* @brief This function is called to output number/string which will be input by unprovisioned device.
|
||||
@ -276,7 +352,7 @@ int bt_mesh_prov_set_oob_input_data(const u8_t idx, const u8_t *val, bool num_fl
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_prov_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size, bool num_flag);
|
||||
int bt_mesh_provisioner_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size, bool num_flag);
|
||||
|
||||
/**
|
||||
* @brief This function is called to read unprovisioned device's oob public key.
|
||||
@ -287,18 +363,18 @@ int bt_mesh_prov_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size,
|
||||
*
|
||||
* @return Zero - success, otherwise - fail
|
||||
*/
|
||||
int bt_mesh_prov_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], const u8_t pub_key_y[32]);
|
||||
int bt_mesh_provisioner_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], const u8_t pub_key_y[32]);
|
||||
|
||||
/* The following APIs are for fast provisioning */
|
||||
|
||||
/**
|
||||
* @brief This function is called to set fast_prov_flag.
|
||||
*
|
||||
* @param[in] flag: Flag set to fast_prov_flag
|
||||
* @param[in] enable: Enable or disable fast provisioning
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void provisioner_set_fast_prov_flag(bool flag);
|
||||
void bt_mesh_provisioner_fast_prov_enable(bool enable);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set netkey index used for fast provisioning.
|
||||
@ -308,14 +384,14 @@ void provisioner_set_fast_prov_flag(bool flag);
|
||||
*
|
||||
* @return status for set netkey index msg
|
||||
*/
|
||||
u8_t provisioner_set_fast_prov_net_idx(const u8_t *net_key, u16_t net_idx);
|
||||
u8_t bt_mesh_provisioner_set_fast_prov_net_idx(const u8_t *net_key, u16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get netkey index used for fast provisioning.
|
||||
*
|
||||
* @return net_idx of fast provisioning
|
||||
*/
|
||||
u16_t provisioner_get_fast_prov_net_idx(void);
|
||||
u16_t bt_mesh_provisioner_get_fast_prov_net_idx(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set unicast address range used for fast provisioning.
|
||||
|
@ -15,21 +15,15 @@
|
||||
#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 "mesh_common.h"
|
||||
#include "foundation.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "proxy_client.h"
|
||||
#include "provisioner_beacon.h"
|
||||
#include "provisioner_prov.h"
|
||||
#include "provisioner_main.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
|
||||
#define PDU_SAR(data) (data[0] >> 6)
|
||||
@ -67,9 +61,9 @@ 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;
|
||||
int i;
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
if (servers[i].conn == conn) {
|
||||
return &servers[i];
|
||||
}
|
||||
@ -82,7 +76,7 @@ static void proxy_sar_timeout(struct k_work *work)
|
||||
{
|
||||
struct bt_mesh_proxy_server *server = NULL;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
BT_WARN("%s", __func__);
|
||||
|
||||
server = CONTAINER_OF(work, struct bt_mesh_proxy_server, sar_timer.work);
|
||||
if (!server || !server->conn) {
|
||||
@ -128,8 +122,8 @@ 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;
|
||||
u8_t filter_type = 0U;
|
||||
u16_t list_size = 0U;
|
||||
|
||||
if (buf->len != 3) {
|
||||
BT_ERR("%s, Invalid Proxy Filter Status length %d", __func__, buf->len);
|
||||
@ -144,7 +138,7 @@ static void filter_status(struct bt_mesh_proxy_server *server,
|
||||
|
||||
list_size = net_buf_simple_pull_be16(buf);
|
||||
|
||||
BT_DBG("%s, filter_type 0x%02x list_size %d", __func__, filter_type, list_size);
|
||||
BT_INFO("%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);
|
||||
@ -157,8 +151,8 @@ 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;
|
||||
u8_t opcode = 0U;
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_net_decode(&server->buf, BLE_MESH_NET_IF_PROXY_CFG,
|
||||
&rx, &buf);
|
||||
@ -205,15 +199,7 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_server *server)
|
||||
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
|
||||
}
|
||||
bt_mesh_beacon_recv(&server->buf, 0);
|
||||
break;
|
||||
case BLE_MESH_PROXY_CONFIG:
|
||||
BT_DBG("Mesh Configuration PDU");
|
||||
@ -223,7 +209,7 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_server *server)
|
||||
#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);
|
||||
bt_mesh_provisioner_pb_gatt_recv(server->conn, &server->buf);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -242,7 +228,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
|
||||
{
|
||||
struct bt_mesh_proxy_server *server = find_server(conn);
|
||||
const u8_t *data = buf;
|
||||
u16_t srvc_uuid;
|
||||
u16_t srvc_uuid = 0U;
|
||||
|
||||
if (!server) {
|
||||
BT_ERR("%s, No Proxy Server object found", __func__);
|
||||
@ -339,8 +325,8 @@ static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t 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;
|
||||
u16_t mtu = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (conn == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -438,7 +424,7 @@ static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn,
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
if (server->conn_type == PROV) {
|
||||
provisioner_pb_gatt_close(conn, reason);
|
||||
bt_mesh_provisioner_pb_gatt_close(conn, reason);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -473,12 +459,12 @@ static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
|
||||
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__);
|
||||
if (bt_mesh_provisioner_set_prov_conn(addr->val, server->conn)) {
|
||||
BT_ERR("%s, bt_mesh_provisioner_set_prov_conn failed", __func__);
|
||||
bt_mesh_gattc_disconnect(server->conn);
|
||||
return -EIO;
|
||||
}
|
||||
return provisioner_pb_gatt_open(conn, addr->val);
|
||||
return bt_mesh_provisioner_pb_gatt_open(conn, addr->val);
|
||||
}
|
||||
|
||||
return -ENOMEM;
|
||||
@ -500,13 +486,13 @@ static ssize_t prov_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int provisioner_pb_gatt_enable(void)
|
||||
int bt_mesh_provisioner_pb_gatt_enable(void)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
if (servers[i].conn) {
|
||||
servers[i].conn_type = PROV;
|
||||
}
|
||||
@ -515,13 +501,13 @@ int provisioner_pb_gatt_enable(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int provisioner_pb_gatt_disable(void)
|
||||
int bt_mesh_provisioner_pb_gatt_disable(void)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
struct bt_mesh_proxy_server *server = &servers[i];
|
||||
|
||||
if (server->conn && server->conn_type == PROV) {
|
||||
@ -582,11 +568,11 @@ static ssize_t proxy_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len)
|
||||
*/
|
||||
int bt_mesh_proxy_client_enable(void)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
if (servers[i].conn) {
|
||||
servers[i].conn_type = PROXY;
|
||||
}
|
||||
@ -604,7 +590,7 @@ int bt_mesh_proxy_client_enable(void)
|
||||
|
||||
int bt_mesh_proxy_client_disable(void)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -615,7 +601,7 @@ int bt_mesh_proxy_client_disable(void)
|
||||
* it should be disconnected.
|
||||
*/
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
struct bt_mesh_proxy_server *server = &servers[i];
|
||||
|
||||
if (server->conn && server->conn_type == PROXY) {
|
||||
@ -645,7 +631,7 @@ static struct bt_mesh_prov_conn_cb conn_callbacks = {
|
||||
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_t size = 0U, i = 0U;
|
||||
|
||||
size = bt_mesh_rx_netkey_size();
|
||||
|
||||
@ -659,14 +645,14 @@ static struct bt_mesh_subnet *bt_mesh_is_net_id_exist(const u8_t net_id[8])
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr)
|
||||
void bt_mesh_proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi)
|
||||
{
|
||||
bt_mesh_proxy_adv_ctx_t ctx = {0};
|
||||
u8_t type;
|
||||
u8_t type = 0U;
|
||||
|
||||
/* Check if connection reaches the maximum limitation */
|
||||
if (bt_mesh_gattc_get_free_conn_count() == 0) {
|
||||
BT_WARN("%s, max connections", __func__);
|
||||
BT_INFO("BLE connections for mesh reach max limit");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -697,14 +683,14 @@ void proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t
|
||||
}
|
||||
|
||||
if (proxy_client_adv_recv_cb) {
|
||||
proxy_client_adv_recv_cb(addr, type, &ctx);
|
||||
proxy_client_adv_recv_cb(addr, type, &ctx, rssi);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
int result = 0;
|
||||
|
||||
if (!addr || addr_type > BLE_MESH_ADDR_RANDOM) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -726,7 +712,7 @@ int bt_mesh_proxy_client_connect(const u8_t addr[6], u8_t addr_type, u16_t net_i
|
||||
|
||||
int bt_mesh_proxy_client_disconnect(u8_t conn_handle)
|
||||
{
|
||||
struct bt_mesh_conn *conn;
|
||||
struct bt_mesh_conn *conn = NULL;
|
||||
|
||||
if (conn_handle >= BLE_MESH_MAX_CONN) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -748,12 +734,10 @@ int bt_mesh_proxy_client_disconnect(u8_t conn_handle)
|
||||
bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst)
|
||||
{
|
||||
bool send = false;
|
||||
int err;
|
||||
u8_t i;
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
BT_DBG("%u bytes to dst 0x%04x", buf->len, dst);
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
struct bt_mesh_proxy_server *server = &servers[i];
|
||||
NET_BUF_SIMPLE_DEFINE(msg, 32);
|
||||
|
||||
@ -771,6 +755,7 @@ bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst)
|
||||
if (err) {
|
||||
BT_ERR("%s, Failed to send proxy net message (err %d)", __func__, err);
|
||||
} else {
|
||||
BT_INFO("%u bytes to dst 0x%04x", buf->len, dst);
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
@ -791,33 +776,35 @@ static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub)
|
||||
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
bool send = false;
|
||||
int err;
|
||||
u8_t i;
|
||||
int err = 0;
|
||||
int 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_is_provisioned()) {
|
||||
for (i = 0; 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;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
for (i = 0; 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]);
|
||||
}
|
||||
}
|
||||
return send;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
return send;
|
||||
}
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
if (servers[i].conn && servers[i].conn_type == PROXY) {
|
||||
err = beacon_send(servers[i].conn, sub);
|
||||
if (err) {
|
||||
@ -844,17 +831,13 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me
|
||||
.src = bt_mesh_primary_addr(),
|
||||
};
|
||||
struct net_buf_simple *buf = NULL;
|
||||
u16_t alloc_len;
|
||||
int err;
|
||||
u16_t alloc_len = 0U;
|
||||
int err = 0;
|
||||
|
||||
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
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
|
||||
tx.sub = bt_mesh_subnet_get(net_idx);
|
||||
#endif
|
||||
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
|
||||
tx.sub = bt_mesh_provisioner_subnet_get(net_idx);
|
||||
}
|
||||
if (!tx.sub) {
|
||||
BT_ERR("%s, Failed to find subnet", __func__);
|
||||
@ -940,7 +923,7 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me
|
||||
|
||||
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;
|
||||
struct bt_mesh_conn *conn = NULL;
|
||||
|
||||
if (conn_handle >= BLE_MESH_MAX_CONN || !pdu || pdu->opcode > BLE_MESH_PROXY_CFG_FILTER_REMOVE) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -971,10 +954,10 @@ int bt_mesh_proxy_client_send_cfg(u8_t conn_handle, u16_t net_idx, struct bt_mes
|
||||
|
||||
int bt_mesh_proxy_prov_client_init(void)
|
||||
{
|
||||
u8_t i;
|
||||
int i;
|
||||
|
||||
/* Initialize the server receive buffers */
|
||||
for (i = 0U; i < ARRAY_SIZE(servers); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
struct bt_mesh_proxy_server *server = &servers[i];
|
||||
|
||||
k_delayed_work_init(&server->sar_timer, proxy_sar_timeout);
|
||||
@ -995,4 +978,22 @@ int bt_mesh_proxy_prov_client_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_proxy_prov_client_deinit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Initialize the server receive buffers */
|
||||
for (i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
struct bt_mesh_proxy_server *server = &servers[i];
|
||||
k_delayed_work_free(&server->sar_timer);
|
||||
memset(server, 0, sizeof(struct bt_mesh_proxy_server));
|
||||
}
|
||||
|
||||
memset(server_buf_data, 0, sizeof(server_buf_data));
|
||||
|
||||
bt_mesh_gattc_conn_cb_deregister();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||
|
@ -12,11 +12,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _PROVISIONER_PROXY_H_
|
||||
#define _PROVISIONER_PROXY_H_
|
||||
#ifndef _PROXY_CLIENT_H_
|
||||
#define _PROXY_CLIENT_H_
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "net.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#define BLE_MESH_PROXY_ADV_NET_ID 0x00
|
||||
#define BLE_MESH_PROXY_ADV_NODE_ID 0x01
|
||||
@ -72,13 +72,13 @@ typedef struct {
|
||||
|
||||
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_provisioner_pb_gatt_enable(void);
|
||||
int bt_mesh_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_recv_adv_cb_t)(const bt_mesh_addr_t *addr, u8_t type, bt_mesh_proxy_adv_ctx_t *ctx, s8_t rssi);
|
||||
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);
|
||||
@ -88,7 +88,7 @@ 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);
|
||||
void bt_mesh_proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi);
|
||||
|
||||
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);
|
||||
@ -98,5 +98,6 @@ 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);
|
||||
int bt_mesh_proxy_prov_client_deinit(void);
|
||||
|
||||
#endif /* _PROVISIONER_PROXY_H_ */
|
||||
#endif /* _PROXY_CLIENT_H_ */
|
||||
|
@ -9,24 +9,18 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_PROXY)
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "mesh_trace.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "adv.h"
|
||||
#include "net.h"
|
||||
#include "prov.h"
|
||||
#include "beacon.h"
|
||||
#include "foundation.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "proxy_server.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
|
||||
/* 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)),
|
||||
@ -83,7 +77,9 @@ static bool prov_fast_adv;
|
||||
|
||||
static struct bt_mesh_proxy_client {
|
||||
struct bt_mesh_conn *conn;
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||
u16_t filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE];
|
||||
#endif
|
||||
enum __packed {
|
||||
NONE,
|
||||
WHITELIST,
|
||||
@ -172,7 +168,7 @@ static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type,
|
||||
static int filter_set(struct bt_mesh_proxy_client *client,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t type;
|
||||
u8_t type = 0U;
|
||||
|
||||
if (buf->len < 1) {
|
||||
BT_WARN("Too short Filter Set message");
|
||||
@ -250,8 +246,8 @@ static void send_filter_status(struct bt_mesh_proxy_client *client,
|
||||
.ctx = &rx->ctx,
|
||||
.src = bt_mesh_primary_addr(),
|
||||
};
|
||||
u16_t filter_size;
|
||||
int i, err;
|
||||
u16_t filter_size = 0U;
|
||||
int i, err = 0;
|
||||
|
||||
/* Configuration messages always have dst unassigned */
|
||||
tx.ctx->addr = BLE_MESH_ADDR_UNASSIGNED;
|
||||
@ -292,9 +288,9 @@ static void send_filter_status(struct bt_mesh_proxy_client *client,
|
||||
static void proxy_cfg(struct bt_mesh_proxy_client *client)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(buf, 29);
|
||||
struct bt_mesh_net_rx rx;
|
||||
u8_t opcode;
|
||||
int err;
|
||||
struct bt_mesh_net_rx rx = {0};
|
||||
u8_t opcode = 0U;
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_net_decode(&client->buf, BLE_MESH_NET_IF_PROXY_CFG,
|
||||
&rx, &buf);
|
||||
@ -321,7 +317,7 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client)
|
||||
break;
|
||||
case CFG_FILTER_ADD:
|
||||
while (buf.len >= 2) {
|
||||
u16_t addr;
|
||||
u16_t addr = 0U;
|
||||
|
||||
addr = net_buf_simple_pull_be16(&buf);
|
||||
filter_add(client, addr);
|
||||
@ -330,7 +326,7 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client)
|
||||
break;
|
||||
case CFG_FILTER_REMOVE:
|
||||
while (buf.len >= 2) {
|
||||
u16_t addr;
|
||||
u16_t addr = 0U;
|
||||
|
||||
addr = net_buf_simple_pull_be16(&buf);
|
||||
filter_remove(client, addr);
|
||||
@ -355,7 +351,7 @@ static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub)
|
||||
|
||||
static void proxy_send_beacons(struct k_work *work)
|
||||
{
|
||||
struct bt_mesh_proxy_client *client;
|
||||
struct bt_mesh_proxy_client *client = NULL;
|
||||
int i;
|
||||
|
||||
client = CONTAINER_OF(work, struct bt_mesh_proxy_client, send_beacons);
|
||||
@ -450,7 +446,7 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_client *client)
|
||||
break;
|
||||
case BLE_MESH_PROXY_BEACON:
|
||||
BT_DBG("Mesh Beacon PDU");
|
||||
bt_mesh_beacon_recv(&client->buf);
|
||||
bt_mesh_beacon_recv(&client->buf, 0);
|
||||
break;
|
||||
case BLE_MESH_PROXY_CONFIG:
|
||||
BT_DBG("Mesh Configuration PDU");
|
||||
@ -561,7 +557,7 @@ static int conn_count;
|
||||
|
||||
static void proxy_connected(struct bt_mesh_conn *conn, u8_t err)
|
||||
{
|
||||
struct bt_mesh_proxy_client *client;
|
||||
struct bt_mesh_proxy_client *client = NULL;
|
||||
int i;
|
||||
|
||||
BT_DBG("conn %p err 0x%02x", conn, err);
|
||||
@ -590,7 +586,9 @@ static void proxy_connected(struct bt_mesh_conn *conn, u8_t err)
|
||||
|
||||
client->conn = bt_mesh_conn_ref(conn);
|
||||
client->filter_type = NONE;
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||
(void)memset(client->filter, 0, sizeof(client->filter));
|
||||
#endif
|
||||
net_buf_simple_reset(&client->buf);
|
||||
}
|
||||
|
||||
@ -636,7 +634,7 @@ static ssize_t prov_ccc_write(struct bt_mesh_conn *conn,
|
||||
const void *buf, u16_t len,
|
||||
u16_t offset, u8_t flags)
|
||||
{
|
||||
struct bt_mesh_proxy_client *client;
|
||||
struct bt_mesh_proxy_client *client = NULL;
|
||||
u16_t *value = attr->user_data;
|
||||
|
||||
BT_DBG("len %u: %s", len, bt_hex(buf, len));
|
||||
@ -771,8 +769,8 @@ static ssize_t proxy_ccc_write(struct bt_mesh_conn *conn,
|
||||
const void *buf, u16_t len,
|
||||
u16_t offset, u8_t flags)
|
||||
{
|
||||
struct bt_mesh_proxy_client *client;
|
||||
u16_t value;
|
||||
struct bt_mesh_proxy_client *client = NULL;
|
||||
u16_t value = 0U;
|
||||
|
||||
BT_DBG("len %u: %s", len, bt_hex(buf, len));
|
||||
|
||||
@ -901,7 +899,7 @@ void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, u16_t addr)
|
||||
struct bt_mesh_proxy_client *client =
|
||||
CONTAINER_OF(buf, struct bt_mesh_proxy_client, buf);
|
||||
|
||||
BT_DBG("filter_type %u addr 0x%04x", client->filter_type, addr);
|
||||
BT_INFO("filter_type %u addr 0x%04x", client->filter_type, addr);
|
||||
|
||||
if (client->filter_type == WHITELIST) {
|
||||
filter_add(client, addr);
|
||||
@ -998,7 +996,7 @@ static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t len)
|
||||
static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type,
|
||||
struct net_buf_simple *msg)
|
||||
{
|
||||
u16_t mtu;
|
||||
u16_t mtu = 0U;
|
||||
|
||||
BT_DBG("conn %p type 0x%02x len %u: %s", conn, type, msg->len,
|
||||
bt_hex(msg->data, msg->len));
|
||||
@ -1104,9 +1102,9 @@ static size_t gatt_proxy_adv_create(struct bt_mesh_adv_data *proxy_sd)
|
||||
static int node_id_adv(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
struct bt_mesh_adv_data proxy_sd = {0};
|
||||
size_t proxy_sd_len;
|
||||
u8_t tmp[16];
|
||||
int err;
|
||||
size_t proxy_sd_len = 0U;
|
||||
u8_t tmp[16] = {0};
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -1144,8 +1142,8 @@ static int node_id_adv(struct bt_mesh_subnet *sub)
|
||||
static int net_id_adv(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
struct bt_mesh_adv_data proxy_sd = {0};
|
||||
size_t proxy_sd_len;
|
||||
int err;
|
||||
size_t proxy_sd_len = 0U;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -1225,7 +1223,7 @@ static int sub_count(void)
|
||||
static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
s32_t remaining = K_FOREVER;
|
||||
int subnet_count;
|
||||
int subnet_count = 0;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
@ -1264,7 +1262,7 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
|
||||
subnet_count = sub_count();
|
||||
BT_DBG("sub_count %u", subnet_count);
|
||||
if (subnet_count > 1) {
|
||||
s32_t max_timeout;
|
||||
s32_t max_timeout = 0;
|
||||
|
||||
/* We use NODE_ID_TIMEOUT as a starting point since it may
|
||||
* be less than 60 seconds. Divide this period into at least
|
||||
@ -1291,8 +1289,8 @@ static size_t gatt_prov_adv_create(struct bt_mesh_adv_data prov_sd[2])
|
||||
const struct bt_mesh_prov *prov = bt_mesh_prov_get();
|
||||
const char *name = device_name;
|
||||
size_t name_len = strlen(name);
|
||||
size_t prov_sd_len = 0;
|
||||
size_t sd_space = 31;
|
||||
size_t prov_sd_len = 0U;
|
||||
size_t sd_space = 31U;
|
||||
|
||||
memcpy(prov_svc_data + 2, prov->uuid, 16);
|
||||
sys_put_be16(prov->oob_info, prov_svc_data + 18);
|
||||
@ -1377,7 +1375,7 @@ s32_t bt_mesh_proxy_adv_start(void)
|
||||
|
||||
void bt_mesh_proxy_adv_stop(void)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("adv_enabled %u", proxy_adv_enabled);
|
||||
|
||||
@ -1402,6 +1400,14 @@ int bt_mesh_proxy_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||
bt_mesh_gatts_service_register(&proxy_svc);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_GATT)
|
||||
bt_mesh_gatts_service_register(&prov_svc);
|
||||
#endif
|
||||
|
||||
/* Initialize the client receive buffers */
|
||||
for (i = 0; i < ARRAY_SIZE(clients); i++) {
|
||||
struct bt_mesh_proxy_client *client = &clients[i];
|
||||
@ -1422,4 +1428,33 @@ int bt_mesh_proxy_init(void)
|
||||
return bt_mesh_gatts_set_local_device_name(device_name);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
int bt_mesh_proxy_deinit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
proxy_adv_enabled = false;
|
||||
gatt_svc = MESH_GATT_NONE;
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||
bt_mesh_gatts_service_deregister(&proxy_svc);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PB_GATT)
|
||||
bt_mesh_gatts_service_deregister(&prov_svc);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(clients); i++) {
|
||||
struct bt_mesh_proxy_client *client = &clients[i];
|
||||
k_delayed_work_free(&client->sar_timer);
|
||||
memset(client, 0, sizeof(struct bt_mesh_proxy_client));
|
||||
}
|
||||
|
||||
memset(client_buf_data, 0, sizeof(client_buf_data));
|
||||
memset(device_name, 0, sizeof(device_name));
|
||||
|
||||
bt_mesh_gatts_conn_cb_deregister();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define _PROXY_H_
|
||||
|
||||
#include "net.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
|
||||
#define BLE_MESH_PROXY_NET_PDU 0x00
|
||||
@ -61,5 +60,6 @@ bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst);
|
||||
void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, u16_t addr);
|
||||
|
||||
int bt_mesh_proxy_init(void);
|
||||
int bt_mesh_proxy_deinit(void);
|
||||
|
||||
#endif /* _PROXY_H_ */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,19 +7,20 @@
|
||||
#ifndef _SETTINGS_H_
|
||||
#define _SETTINGS_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "net.h"
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
int settings_core_init(void);
|
||||
int settings_core_load(void);
|
||||
int settings_core_commit(void);
|
||||
int settings_core_deinit(void);
|
||||
|
||||
void bt_mesh_store_role(void);
|
||||
void bt_mesh_store_net(void);
|
||||
void bt_mesh_store_iv(bool only_duration);
|
||||
void bt_mesh_clear_iv(void);
|
||||
void bt_mesh_store_seq(void);
|
||||
void bt_mesh_clear_seq(void);
|
||||
void bt_mesh_store_rpl(struct bt_mesh_rpl *rpl);
|
||||
void bt_mesh_store_subnet(struct bt_mesh_subnet *sub);
|
||||
void bt_mesh_store_app_key(struct bt_mesh_app_key *key);
|
||||
@ -30,11 +31,31 @@ void bt_mesh_store_mod_sub(struct bt_mesh_model *mod);
|
||||
void bt_mesh_store_mod_pub(struct bt_mesh_model *mod);
|
||||
void bt_mesh_store_label(void);
|
||||
|
||||
void bt_mesh_clear_role(void);
|
||||
void bt_mesh_clear_net(void);
|
||||
void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub);
|
||||
void bt_mesh_clear_app_key(struct bt_mesh_app_key *key);
|
||||
void bt_mesh_clear_rpl(void);
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
void bt_mesh_store_prov_info(u16_t primary_addr, u16_t alloc_addr);
|
||||
void bt_mesh_clear_prov_info(void);
|
||||
void bt_mesh_store_p_net_idx(void);
|
||||
void bt_mesh_clear_p_net_idx(void);
|
||||
void bt_mesh_store_p_app_idx(void);
|
||||
void bt_mesh_clear_p_app_idx(void);
|
||||
void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub);
|
||||
void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key);
|
||||
void bt_mesh_clear_p_subnet(struct bt_mesh_subnet *sub);
|
||||
void bt_mesh_clear_p_app_key(struct bt_mesh_app_key *key);
|
||||
void bt_mesh_clear_rpl_single(u16_t src);
|
||||
void bt_mesh_store_node_info(struct bt_mesh_node *node, bool prov);
|
||||
void bt_mesh_clear_node_info(u16_t unicast_addr, bool prov);
|
||||
void bt_mesh_store_node_name(struct bt_mesh_node *node, bool prov);
|
||||
void bt_mesh_store_node_comp_data(struct bt_mesh_node *node, bool prov);
|
||||
#endif
|
||||
|
||||
int bt_mesh_settings_init(void);
|
||||
int bt_mesh_settings_deinit(void);
|
||||
|
||||
#endif /* _SETTINGS_H_ */
|
||||
|
@ -13,17 +13,12 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nvs.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
#include "settings_nvs.h"
|
||||
#include "settings.h"
|
||||
|
||||
@ -41,6 +36,8 @@ struct settings_context {
|
||||
int (*settings_init)(void);
|
||||
int (*settings_load)(void);
|
||||
int (*settings_commit)(void);
|
||||
int (*settings_deinit)(void);
|
||||
int (*settings_erase)(void);
|
||||
};
|
||||
|
||||
static struct settings_context settings_ctx[] = {
|
||||
@ -49,6 +46,7 @@ static struct settings_context settings_ctx[] = {
|
||||
.settings_init = settings_core_init,
|
||||
.settings_load = settings_core_load,
|
||||
.settings_commit = settings_core_commit,
|
||||
.settings_deinit = settings_core_deinit,
|
||||
},
|
||||
[SETTINGS_SERVER] = {
|
||||
.nvs_name = "mesh_server",
|
||||
@ -62,12 +60,25 @@ static struct settings_context settings_ctx[] = {
|
||||
|
||||
void bt_mesh_settings_foreach(void)
|
||||
{
|
||||
int i, err;
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
err = nvs_flash_init_partition(CONFIG_BLE_MESH_PARTITION_NAME);
|
||||
if (err != ESP_OK) {
|
||||
BT_ERR("Failed to init mesh partition, name %s, err %d", CONFIG_BLE_MESH_PARTITION_NAME, err);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
struct settings_context *ctx = &settings_ctx[i];
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
err = nvs_open_from_partition(CONFIG_BLE_MESH_PARTITION_NAME, ctx->nvs_name, NVS_READWRITE, &ctx->handle);
|
||||
#else
|
||||
err = nvs_open(ctx->nvs_name, NVS_READWRITE, &ctx->handle);
|
||||
#endif
|
||||
if (err != ESP_OK) {
|
||||
BT_ERR("%s, Open nvs failed, name %s, err %d", __func__, ctx->nvs_name, err);
|
||||
continue;
|
||||
@ -90,6 +101,26 @@ void bt_mesh_settings_foreach(void)
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_settings_deforeach(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
struct settings_context *ctx = &settings_ctx[i];
|
||||
|
||||
if (ctx->settings_deinit && ctx->settings_deinit()) {
|
||||
BT_ERR("%s, Deinit settings failed, name %s", __func__, ctx->nvs_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
nvs_close(ctx->handle);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
nvs_flash_deinit_partition(CONFIG_BLE_MESH_PARTITION_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* API used to get BLE Mesh related nvs handle */
|
||||
|
||||
static inline nvs_handle settings_get_nvs_handle(enum settings_type type)
|
||||
@ -101,7 +132,7 @@ static inline nvs_handle settings_get_nvs_handle(enum settings_type type)
|
||||
|
||||
static int settings_save(nvs_handle handle, const char *key, const u8_t *val, size_t len)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (key == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -145,7 +176,7 @@ int bt_mesh_save_core_settings(const char *key, const u8_t *val, size_t len)
|
||||
static int settings_load(nvs_handle handle, const char *key,
|
||||
u8_t *buf, size_t buf_len, bool *exist)
|
||||
{
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (key == NULL || buf == NULL || exist == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -178,8 +209,8 @@ int bt_mesh_load_core_settings(const char *key, u8_t *buf, size_t buf_len, bool
|
||||
|
||||
static size_t settings_get_length(nvs_handle handle, const char *key)
|
||||
{
|
||||
size_t len = 0;
|
||||
int err;
|
||||
size_t len = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (key == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -205,9 +236,9 @@ static size_t settings_get_length(nvs_handle handle, const char *key)
|
||||
static struct net_buf_simple *settings_get_item(nvs_handle handle, const char *key)
|
||||
{
|
||||
struct net_buf_simple *buf = NULL;
|
||||
size_t length;
|
||||
bool exist;
|
||||
int err;
|
||||
size_t length = 0U;
|
||||
bool exist = false;
|
||||
int err = 0;
|
||||
|
||||
length = settings_get_length(handle, key);
|
||||
if (!length) {
|
||||
@ -250,7 +281,7 @@ struct net_buf_simple *bt_mesh_get_core_settings_item(const char *key)
|
||||
static bool is_settings_item_exist(struct net_buf_simple *buf, const u16_t val)
|
||||
{
|
||||
struct net_buf_simple_state state = {0};
|
||||
size_t length;
|
||||
size_t length = 0U;
|
||||
int i;
|
||||
|
||||
if (!buf) {
|
||||
@ -278,8 +309,8 @@ static int settings_add_item(nvs_handle handle, const char *key, const u16_t val
|
||||
{
|
||||
struct net_buf_simple *store = NULL;
|
||||
struct net_buf_simple *buf = NULL;
|
||||
size_t length = 0;
|
||||
int err;
|
||||
size_t length = 0U;
|
||||
int err = 0;
|
||||
|
||||
buf = settings_get_item(handle, key);
|
||||
|
||||
@ -323,9 +354,10 @@ static int settings_remove_item(nvs_handle handle, const char *key, const u16_t
|
||||
{
|
||||
struct net_buf_simple *store = NULL;
|
||||
struct net_buf_simple *buf = NULL;
|
||||
size_t length = 0;
|
||||
size_t buf_len;
|
||||
int i, err;
|
||||
size_t length = 0U;
|
||||
size_t buf_len = 0U;
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
buf = settings_get_item(handle, key);
|
||||
|
||||
|
@ -15,8 +15,6 @@
|
||||
#ifndef _BLE_MESH_SETTINGS_NVS_H_
|
||||
#define _BLE_MESH_SETTINGS_NVS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_buf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -30,6 +28,7 @@ extern "C" {
|
||||
#define BLE_MESH_GET_MODEL_KEY(a, b) ((u16_t)(((u16_t)((a) << 8)) | b))
|
||||
|
||||
void bt_mesh_settings_foreach(void);
|
||||
void bt_mesh_settings_deforeach(void);
|
||||
|
||||
int bt_mesh_save_core_settings(const char *key, const u8_t *val, size_t len);
|
||||
|
||||
|
@ -10,16 +10,12 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_access.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "test.h"
|
||||
#include "crypto.h"
|
||||
#include "net.h"
|
||||
#include "foundation.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "mesh_main.h"
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_SELF_TEST)
|
||||
|
||||
@ -38,7 +34,7 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info)
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
int i, j, k;
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (info == NULL || !BLE_MESH_ADDR_IS_UNICAST(info->unicast_addr) ||
|
||||
!BLE_MESH_ADDR_IS_GROUP(info->group_addr)) {
|
||||
|
@ -10,12 +10,7 @@
|
||||
#ifndef _BLE_MESH_TEST_H_
|
||||
#define _BLE_MESH_TEST_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mesh_buf.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "mesh_types.h"
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_SELF_TEST)
|
||||
int bt_mesh_test(void);
|
||||
|
@ -7,31 +7,22 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_TRANS)
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_util.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_main.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "crypto.h"
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "net.h"
|
||||
#include "lpn.h"
|
||||
#include "friend.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
#include "settings.h"
|
||||
#include "transport.h"
|
||||
#include "mesh_main.h"
|
||||
#include "mesh_common.h"
|
||||
#include "client_common.h"
|
||||
#include "cfg_srv.h"
|
||||
|
||||
/* The transport layer needs at least three buffers for itself to avoid
|
||||
@ -110,6 +101,30 @@ static u8_t seg_rx_buf_data[(CONFIG_BLE_MESH_RX_SEG_MSG_COUNT *
|
||||
|
||||
static u16_t hb_sub_dst = BLE_MESH_ADDR_UNASSIGNED;
|
||||
|
||||
static bt_mesh_mutex_t tx_seg_lock;
|
||||
|
||||
static void bt_mesh_tx_seg_mutex_new(void)
|
||||
{
|
||||
if (!tx_seg_lock.mutex) {
|
||||
bt_mesh_mutex_create(&tx_seg_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_tx_seg_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&tx_seg_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_tx_seg_lock(void)
|
||||
{
|
||||
bt_mesh_mutex_lock(&tx_seg_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_tx_seg_unlock(void)
|
||||
{
|
||||
bt_mesh_mutex_unlock(&tx_seg_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_set_hb_sub_dst(u16_t addr)
|
||||
{
|
||||
hb_sub_dst = addr;
|
||||
@ -118,7 +133,7 @@ void bt_mesh_set_hb_sub_dst(u16_t addr)
|
||||
static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("src 0x%04x dst 0x%04x app_idx 0x%04x sdu_len %u",
|
||||
tx->src, tx->ctx->addr, tx->ctx->app_idx, sdu->len);
|
||||
@ -198,6 +213,8 @@ static void seg_tx_reset(struct seg_tx *tx)
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_tx_seg_lock();
|
||||
|
||||
for (i = 0; i <= tx->seg_n; i++) {
|
||||
if (!tx->seg[i]) {
|
||||
continue;
|
||||
@ -211,6 +228,8 @@ static void seg_tx_reset(struct seg_tx *tx)
|
||||
|
||||
tx->nack_count = 0U;
|
||||
|
||||
bt_mesh_tx_seg_unlock();
|
||||
|
||||
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_IVU_PENDING)) {
|
||||
BT_DBG("Proceding with pending IV Update");
|
||||
/* bt_mesh_net_iv_update() will re-enable the flag if this
|
||||
@ -274,7 +293,9 @@ static const struct bt_mesh_send_cb seg_sent_cb = {
|
||||
|
||||
static void seg_tx_send_unacked(struct seg_tx *tx)
|
||||
{
|
||||
int i, err;
|
||||
int i, err = 0;
|
||||
|
||||
bt_mesh_tx_seg_lock();
|
||||
|
||||
for (i = 0; i <= tx->seg_n; i++) {
|
||||
struct net_buf *seg = tx->seg[i];
|
||||
@ -290,6 +311,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
|
||||
|
||||
if (!(BLE_MESH_ADV(seg)->seg.attempts--)) {
|
||||
BT_WARN("Ran out of retransmit attempts");
|
||||
bt_mesh_tx_seg_unlock();
|
||||
seg_tx_complete(tx, -ETIMEDOUT);
|
||||
return;
|
||||
}
|
||||
@ -300,10 +322,13 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
|
||||
&seg_sent_cb, tx);
|
||||
if (err) {
|
||||
BT_ERR("%s, Sending segment failed", __func__);
|
||||
bt_mesh_tx_seg_unlock();
|
||||
seg_tx_complete(tx, -EIO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bt_mesh_tx_seg_unlock();
|
||||
}
|
||||
|
||||
static void seg_retransmit(struct k_work *work)
|
||||
@ -316,9 +341,9 @@ static void seg_retransmit(struct k_work *work)
|
||||
static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
u8_t seg_hdr, seg_o;
|
||||
u16_t seq_zero;
|
||||
struct seg_tx *tx;
|
||||
u8_t seg_hdr = 0U, seg_o = 0U;
|
||||
u16_t seq_zero = 0U;
|
||||
struct seg_tx *tx = NULL;
|
||||
int i;
|
||||
|
||||
BT_DBG("src 0x%04x dst 0x%04x app_idx 0x%04x aszmic %u sdu_len %u",
|
||||
@ -385,9 +410,9 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
|
||||
}
|
||||
|
||||
for (seg_o = 0U; sdu->len; seg_o++) {
|
||||
struct net_buf *seg;
|
||||
u16_t len;
|
||||
int err;
|
||||
struct net_buf *seg = NULL;
|
||||
u16_t len = 0U;
|
||||
int err = 0;
|
||||
|
||||
seg = bt_mesh_adv_create(BLE_MESH_ADV_DATA, net_tx->xmit,
|
||||
BUF_TIMEOUT);
|
||||
@ -412,7 +437,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
|
||||
net_buf_simple_pull(sdu, len);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
enum bt_mesh_friend_pdu_type type;
|
||||
enum bt_mesh_friend_pdu_type type = BLE_MESH_FRIEND_PDU_PARTIAL;
|
||||
|
||||
if (seg_o == tx->seg_n) {
|
||||
type = BLE_MESH_FRIEND_PDU_COMPLETE;
|
||||
@ -485,9 +510,9 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
const u8_t *key = NULL;
|
||||
u8_t *ad, role;
|
||||
u8_t aid;
|
||||
int err;
|
||||
u8_t *ad = NULL, role = 0U;
|
||||
u8_t aid = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (net_buf_simple_tailroom(msg) < 4) {
|
||||
BT_ERR("%s, Insufficient tailroom for Transport MIC", __func__);
|
||||
@ -627,10 +652,10 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
|
||||
u8_t aszmic, struct net_buf_simple *buf)
|
||||
{
|
||||
struct net_buf_simple *sdu = NULL;
|
||||
size_t array_size = 0;
|
||||
u8_t *ad;
|
||||
u16_t i;
|
||||
int err;
|
||||
size_t array_size = 0U;
|
||||
size_t i = 0U;
|
||||
u8_t *ad = NULL;
|
||||
int err = 0;
|
||||
|
||||
BT_DBG("ASZMIC %u AKF %u AID 0x%02x", aszmic, AKF(&hdr), AID(&hdr));
|
||||
BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
@ -667,7 +692,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
|
||||
if (!AKF(&hdr)) {
|
||||
array_size = bt_mesh_rx_devkey_size();
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
for (i = 0U; i < array_size; i++) {
|
||||
const u8_t *dev_key = NULL;
|
||||
|
||||
dev_key = bt_mesh_rx_devkey_get(i, rx->ctx.addr);
|
||||
@ -699,7 +724,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
|
||||
|
||||
array_size = bt_mesh_rx_appkey_size();
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
for (i = 0U; i < array_size; i++) {
|
||||
struct bt_mesh_app_keys *keys = NULL;
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
|
||||
@ -750,7 +775,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr,
|
||||
|
||||
static struct seg_tx *seg_tx_lookup(u16_t seq_zero, u8_t obo, u16_t addr)
|
||||
{
|
||||
struct seg_tx *tx;
|
||||
struct seg_tx *tx = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(seg_tx); i++) {
|
||||
@ -781,11 +806,11 @@ static struct seg_tx *seg_tx_lookup(u16_t seq_zero, u8_t obo, u16_t addr)
|
||||
static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr,
|
||||
struct net_buf_simple *buf, u64_t *seq_auth)
|
||||
{
|
||||
struct seg_tx *tx;
|
||||
unsigned int bit;
|
||||
u32_t ack;
|
||||
u16_t seq_zero;
|
||||
u8_t obo;
|
||||
struct seg_tx *tx = NULL;
|
||||
unsigned int bit = 0;
|
||||
u32_t ack = 0U;
|
||||
u16_t seq_zero = 0U;
|
||||
u8_t obo = 0U;
|
||||
|
||||
if (buf->len < 6) {
|
||||
BT_ERR("%s, Too short ack message", __func__);
|
||||
@ -852,8 +877,8 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr,
|
||||
static int trans_heartbeat(struct bt_mesh_net_rx *rx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t init_ttl, hops;
|
||||
u16_t feat;
|
||||
u8_t init_ttl = 0U, hops = 0U;
|
||||
u16_t feat = 0U;
|
||||
|
||||
if (buf->len < 3) {
|
||||
BT_ERR("%s, Too short heartbeat message", __func__);
|
||||
@ -870,7 +895,7 @@ static int trans_heartbeat(struct bt_mesh_net_rx *rx,
|
||||
|
||||
hops = (init_ttl - rx->ctx.recv_ttl + 1);
|
||||
|
||||
BT_DBG("src 0x%04x TTL %u InitTTL %u (%u hop%s) feat 0x%04x",
|
||||
BT_INFO("src 0x%04x TTL %u InitTTL %u (%u hop%s) feat 0x%04x",
|
||||
rx->ctx.addr, rx->ctx.recv_ttl, init_ttl, hops,
|
||||
(hops == 1U) ? "" : "s", feat);
|
||||
|
||||
@ -947,7 +972,7 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, u8_t hdr,
|
||||
static int trans_unseg(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx,
|
||||
u64_t *seq_auth)
|
||||
{
|
||||
u8_t hdr;
|
||||
u8_t hdr = 0U;
|
||||
|
||||
BT_DBG("AFK %u AID 0x%02x", AKF(buf->data), AID(buf->data));
|
||||
|
||||
@ -978,8 +1003,8 @@ static int trans_unseg(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx,
|
||||
|
||||
static inline s32_t ack_timeout(struct seg_rx *rx)
|
||||
{
|
||||
s32_t to;
|
||||
u8_t ttl;
|
||||
s32_t to = 0;
|
||||
u8_t ttl = 0U;
|
||||
|
||||
if (rx->ttl == BLE_MESH_TTL_DEFAULT) {
|
||||
ttl = bt_mesh_default_ttl_get();
|
||||
@ -1005,7 +1030,7 @@ int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
|
||||
size_t data_len, u64_t *seq_auth,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_buf *buf = NULL;
|
||||
|
||||
BT_DBG("src 0x%04x dst 0x%04x ttl 0x%02x ctl 0x%02x", tx->src,
|
||||
tx->ctx->addr, tx->ctx->send_ttl, ctl_op);
|
||||
@ -1054,7 +1079,7 @@ static int send_ack(struct bt_mesh_subnet *sub, u16_t src, u16_t dst,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
u16_t seq_zero = *seq_auth & TRANS_SEQ_ZERO_MASK;
|
||||
u8_t buf[6];
|
||||
u8_t buf[6] = {0};
|
||||
|
||||
BT_DBG("SeqZero 0x%04x Block 0x%08x OBO %u", seq_zero, block, obo);
|
||||
|
||||
@ -1237,12 +1262,12 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
|
||||
u8_t *seg_count)
|
||||
{
|
||||
struct bt_mesh_rpl *rpl = NULL;
|
||||
struct seg_rx *rx;
|
||||
struct seg_rx *rx = NULL;
|
||||
u8_t *hdr = buf->data;
|
||||
u16_t seq_zero;
|
||||
u8_t seg_n;
|
||||
u8_t seg_o;
|
||||
int err;
|
||||
u16_t seq_zero = 0U;
|
||||
u8_t seg_n = 0U;
|
||||
u8_t seg_o = 0U;
|
||||
int err = 0;
|
||||
|
||||
if (buf->len < 5) {
|
||||
BT_ERR("%s, Too short segmented message (len %u)", __func__, buf->len);
|
||||
@ -1412,7 +1437,7 @@ found_rx:
|
||||
/* Location in buffer can be calculated based on seg_o & rx->ctl */
|
||||
memcpy(rx->buf.data + (seg_o * seg_len(rx->ctl)), buf->data, buf->len);
|
||||
|
||||
BT_DBG("Received %u/%u", seg_o, seg_n);
|
||||
BT_INFO("Received %u/%u", seg_o, seg_n);
|
||||
|
||||
/* Mark segment as received */
|
||||
rx->block |= BIT(seg_o);
|
||||
@ -1450,9 +1475,9 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
|
||||
{
|
||||
u64_t seq_auth = TRANS_SEQ_AUTH_NVAL;
|
||||
enum bt_mesh_friend_pdu_type pdu_type = BLE_MESH_FRIEND_PDU_SINGLE;
|
||||
struct net_buf_simple_state state;
|
||||
struct net_buf_simple_state state = {0};
|
||||
u8_t seg_count = 0U;
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
|
||||
rx->friend_match = bt_mesh_friend_match(rx->sub->net_idx,
|
||||
@ -1573,6 +1598,35 @@ void bt_mesh_trans_init(void)
|
||||
(i * CONFIG_BLE_MESH_RX_SDU_MAX));
|
||||
seg_rx[i].buf.data = seg_rx[i].buf.__buf;
|
||||
}
|
||||
|
||||
bt_mesh_tx_seg_mutex_new();
|
||||
}
|
||||
|
||||
void bt_mesh_trans_deinit(bool erase)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(seg_rx); i++) {
|
||||
seg_rx_reset(&seg_rx[i], true);
|
||||
}
|
||||
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_rpl();
|
||||
} else {
|
||||
bt_mesh_rpl_clear();
|
||||
}
|
||||
|
||||
bt_mesh_tx_reset();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(seg_tx); i++) {
|
||||
k_delayed_work_free(&seg_tx[i].retransmit);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(seg_rx); i++) {
|
||||
k_delayed_work_free(&seg_rx[i].ack);
|
||||
}
|
||||
|
||||
bt_mesh_tx_seg_mutex_free();
|
||||
}
|
||||
|
||||
void bt_mesh_rpl_clear(void)
|
||||
@ -1627,7 +1681,7 @@ void bt_mesh_heartbeat_send(void)
|
||||
|
||||
hb.feat = sys_cpu_to_be16(feat);
|
||||
|
||||
BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
|
||||
BT_INFO("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);
|
||||
@ -1636,7 +1690,7 @@ void bt_mesh_heartbeat_send(void)
|
||||
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
|
||||
const u8_t **key, u8_t *aid, u8_t role, u16_t dst)
|
||||
{
|
||||
struct bt_mesh_app_key *app_key;
|
||||
struct bt_mesh_app_key *app_key = NULL;
|
||||
|
||||
if (app_idx == BLE_MESH_KEY_DEV) {
|
||||
*key = bt_mesh_tx_devkey_get(role, dst);
|
||||
@ -1654,7 +1708,7 @@ int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
app_key = bt_mesh_tx_appkey_get(role, app_idx, subnet->net_idx);
|
||||
app_key = bt_mesh_tx_appkey_get(role, app_idx);
|
||||
if (!app_key) {
|
||||
BT_ERR("%s, Failed to get AppKey", __func__);
|
||||
return -ENOENT;
|
||||
|
@ -10,6 +10,8 @@
|
||||
#ifndef _TRANSPORT_H_
|
||||
#define _TRANSPORT_H_
|
||||
|
||||
#include "net.h"
|
||||
|
||||
#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff
|
||||
|
||||
#define BLE_MESH_TX_SDU_MAX (CONFIG_BLE_MESH_TX_SEG_MAX * 12)
|
||||
@ -97,6 +99,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||
int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx);
|
||||
|
||||
void bt_mesh_trans_init(void);
|
||||
void bt_mesh_trans_deinit(bool erase);
|
||||
|
||||
void bt_mesh_rpl_clear(void);
|
||||
|
||||
|
@ -15,16 +15,10 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "osi/allocator.h"
|
||||
#include "osi/mutex.h"
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_slist.h"
|
||||
#include "mesh_main.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "mesh_main.h"
|
||||
#include "client_common.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t tx_dst)
|
||||
{
|
||||
@ -174,7 +168,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
|
||||
bt_mesh_client_internal_data_t *internal = NULL;
|
||||
bt_mesh_client_user_data_t *cli = NULL;
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
if (!model || !ctx || !msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -196,7 +190,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
|
||||
err = -EBUSY;
|
||||
} else {
|
||||
/* Don't forget to free the node in the timeout (timer_handler) function. */
|
||||
node = (bt_mesh_client_node_t *)osi_calloc(sizeof(bt_mesh_client_node_t));
|
||||
node = (bt_mesh_client_node_t *)bt_mesh_calloc(sizeof(bt_mesh_client_node_t));
|
||||
if (!node) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
@ -206,11 +200,11 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
|
||||
node->opcode = opcode;
|
||||
if ((node->op_pending = bt_mesh_client_get_status_op(cli->op_pair, cli->op_pair_size, opcode)) == 0) {
|
||||
BT_ERR("%s, Not found the status opcode in the op_pair list", __func__);
|
||||
osi_free(node);
|
||||
bt_mesh_free(node);
|
||||
return -EINVAL;
|
||||
}
|
||||
if ((err = bt_mesh_model_send(model, ctx, msg, cb, cb_data)) != 0) {
|
||||
osi_free(node);
|
||||
bt_mesh_free(node);
|
||||
} else {
|
||||
bt_mesh_list_lock();
|
||||
sys_slist_append(&internal->queue, &node->client_node);
|
||||
@ -223,26 +217,28 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
|
||||
return err;
|
||||
}
|
||||
|
||||
static osi_mutex_t client_model_mutex;
|
||||
static bt_mesh_mutex_t client_model_lock;
|
||||
|
||||
static void bt_mesh_client_model_mutex_new(void)
|
||||
{
|
||||
static bool init;
|
||||
|
||||
if (!init) {
|
||||
osi_mutex_new(&client_model_mutex);
|
||||
init = true;
|
||||
if (!client_model_lock.mutex) {
|
||||
bt_mesh_mutex_create(&client_model_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_client_model_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&client_model_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_client_model_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&client_model_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&client_model_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_client_model_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&client_model_mutex);
|
||||
bt_mesh_mutex_unlock(&client_model_lock);
|
||||
}
|
||||
|
||||
int bt_mesh_client_init(struct bt_mesh_model *model)
|
||||
@ -267,7 +263,7 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
|
||||
}
|
||||
|
||||
if (!cli->internal_data) {
|
||||
data = osi_calloc(sizeof(bt_mesh_client_internal_data_t));
|
||||
data = bt_mesh_calloc(sizeof(bt_mesh_client_internal_data_t));
|
||||
if (!data) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
@ -287,6 +283,35 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_client_deinit(struct bt_mesh_model *model)
|
||||
{
|
||||
bt_mesh_client_user_data_t *client = NULL;
|
||||
|
||||
if (!model) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
client = (bt_mesh_client_user_data_t *)model->user_data;
|
||||
if (!client) {
|
||||
BT_ERR("%s, Client user_data is NULL", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (client->internal_data) {
|
||||
/* Remove items from the list */
|
||||
bt_mesh_client_clear_list(client->internal_data);
|
||||
|
||||
/* Free the allocated internal data */
|
||||
bt_mesh_free(client->internal_data);
|
||||
client->internal_data = NULL;
|
||||
}
|
||||
|
||||
bt_mesh_client_model_mutex_free();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
|
||||
{
|
||||
bt_mesh_client_internal_data_t *internal = NULL;
|
||||
@ -314,7 +339,7 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
|
||||
sys_slist_find_and_remove(&internal->queue, &node->client_node);
|
||||
bt_mesh_list_unlock();
|
||||
// Free the node
|
||||
osi_free(node);
|
||||
bt_mesh_free(node);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -334,7 +359,7 @@ int bt_mesh_client_clear_list(void *data)
|
||||
bt_mesh_list_lock();
|
||||
while (!sys_slist_is_empty(&internal->queue)) {
|
||||
node = (void *)sys_slist_get_not_empty(&internal->queue);
|
||||
osi_free(node);
|
||||
bt_mesh_free(node);
|
||||
}
|
||||
bt_mesh_list_unlock();
|
||||
|
||||
|
@ -14,19 +14,8 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "osi/allocator.h"
|
||||
#include "osi/mutex.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_kernel.h"
|
||||
#include "mesh_trace.h"
|
||||
|
||||
#include "mesh.h"
|
||||
#include "model_opcode.h"
|
||||
#include "mesh_common.h"
|
||||
#include "generic_client.h"
|
||||
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
@ -120,32 +109,36 @@ static const bt_mesh_client_op_pair_t gen_op_pair[] = {
|
||||
{ BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS },
|
||||
};
|
||||
|
||||
static osi_mutex_t generic_client_mutex;
|
||||
static bt_mesh_mutex_t generic_client_lock;
|
||||
|
||||
static void bt_mesh_generic_client_mutex_new(void)
|
||||
{
|
||||
static bool init;
|
||||
|
||||
if (!init) {
|
||||
osi_mutex_new(&generic_client_mutex);
|
||||
init = true;
|
||||
if (!generic_client_lock.mutex) {
|
||||
bt_mesh_mutex_create(&generic_client_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_generic_client_mutex_free(void)
|
||||
{
|
||||
bt_mesh_mutex_free(&generic_client_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_generic_client_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&generic_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
||||
bt_mesh_mutex_lock(&generic_client_lock);
|
||||
}
|
||||
|
||||
static void bt_mesh_generic_client_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&generic_client_mutex);
|
||||
bt_mesh_mutex_unlock(&generic_client_lock);
|
||||
}
|
||||
|
||||
static void timeout_handler(struct k_work *work)
|
||||
{
|
||||
struct k_delayed_work *timer = NULL;
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
u32_t opcode = 0U;
|
||||
|
||||
BT_WARN("Receive generic status message timeout");
|
||||
|
||||
@ -156,10 +149,11 @@ static void timeout_handler(struct k_work *work)
|
||||
if (timer && !k_delayed_work_free(timer)) {
|
||||
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);
|
||||
// Don't forget to release the node at the end.
|
||||
memcpy(&ctx, &node->ctx, sizeof(ctx));
|
||||
opcode = node->opcode;
|
||||
bt_mesh_client_free_node(node);
|
||||
bt_mesh_generic_client_cb_evt_to_btc(
|
||||
opcode, BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, ctx.model, &ctx, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +169,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
u8_t *val = NULL;
|
||||
u8_t evt = 0xFF;
|
||||
size_t len = 0;
|
||||
size_t len = 0U;
|
||||
|
||||
BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
@ -186,7 +180,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic OnOff Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_onoff_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onoff_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -207,7 +201,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Level Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_level_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_level_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -228,7 +222,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Default Trans Time Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -244,7 +238,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic OnPowerUp Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_onpowerup_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onpowerup_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -260,7 +254,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Power Level Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_power_level_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_level_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -281,7 +275,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Power Last Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_power_last_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_last_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -297,7 +291,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Power Default Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_power_default_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_default_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -313,7 +307,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Power Range Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_power_range_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_range_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -331,7 +325,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Battery Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_battery_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_battery_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -353,7 +347,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Location Global Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_loc_global_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_global_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -371,7 +365,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
BT_ERR("Invalid Generic Location Local Status length %d", buf->len);
|
||||
return;
|
||||
}
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_loc_local_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_local_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -387,7 +381,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: {
|
||||
struct bt_mesh_gen_user_properties_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_user_properties_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_properties_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -395,7 +389,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->user_property_ids = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->user_property_ids) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->user_property_ids, buf->data, buf->len);
|
||||
@ -405,7 +399,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: {
|
||||
struct bt_mesh_gen_user_property_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_user_property_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_property_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -417,7 +411,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->user_property_value = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->user_property_value) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->user_property_value, buf->data, buf->len);
|
||||
@ -428,7 +422,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: {
|
||||
struct bt_mesh_gen_admin_properties_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_admin_properties_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_properties_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -436,7 +430,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->admin_property_ids = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->admin_property_ids) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->admin_property_ids, buf->data, buf->len);
|
||||
@ -446,7 +440,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: {
|
||||
struct bt_mesh_gen_admin_property_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_admin_property_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_property_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -458,7 +452,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->admin_property_value = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->admin_property_value) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->admin_property_value, buf->data, buf->len);
|
||||
@ -469,7 +463,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: {
|
||||
struct bt_mesh_gen_manu_properties_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_manu_properties_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_properties_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -477,7 +471,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->manu_property_ids = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->manu_property_ids) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->manu_property_ids, buf->data, buf->len);
|
||||
@ -487,7 +481,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: {
|
||||
struct bt_mesh_gen_manu_property_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_manu_property_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_property_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -499,7 +493,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->manu_property_value = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->manu_property_value) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->manu_property_value, buf->data, buf->len);
|
||||
@ -510,7 +504,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: {
|
||||
struct bt_mesh_gen_client_properties_status *status = NULL;
|
||||
status = osi_calloc(sizeof(struct bt_mesh_gen_client_properties_status));
|
||||
status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_client_properties_status));
|
||||
if (!status) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return;
|
||||
@ -518,7 +512,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
status->client_property_ids = bt_mesh_alloc_buf(buf->len);
|
||||
if (!status->client_property_ids) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
osi_free(status);
|
||||
bt_mesh_free(status);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(status->client_property_ids, buf->data, buf->len);
|
||||
@ -582,9 +576,9 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
}
|
||||
|
||||
if (!k_delayed_work_free(&node->timer)) {
|
||||
bt_mesh_generic_client_cb_evt_to_btc(node->opcode, evt, model, ctx, val, len);
|
||||
// Don't forget to release the node at the end.
|
||||
u32_t opcode = node->opcode;
|
||||
bt_mesh_client_free_node(node);
|
||||
bt_mesh_generic_client_cb_evt_to_btc(opcode, evt, model, ctx, val, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -637,7 +631,7 @@ static void generic_status(struct bt_mesh_model *model,
|
||||
break;
|
||||
}
|
||||
|
||||
osi_free(val);
|
||||
bt_mesh_free(val);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -695,7 +689,7 @@ const struct bt_mesh_model_op gen_property_cli_op[] = {
|
||||
static int gen_get_state(bt_mesh_client_common_param_t *common, void *value)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_GEN_GET_STATE_MSG_LEN);
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
bt_mesh_model_msg_init(&msg, common->opcode);
|
||||
|
||||
@ -745,7 +739,7 @@ static int gen_set_state(bt_mesh_client_common_param_t *common,
|
||||
void *value, u16_t value_len, bool need_ack)
|
||||
{
|
||||
struct net_buf_simple *msg = NULL;
|
||||
int err;
|
||||
int err = 0;
|
||||
|
||||
msg = bt_mesh_alloc_buf(value_len);
|
||||
if (!msg) {
|
||||
@ -989,8 +983,8 @@ int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void
|
||||
int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status)
|
||||
{
|
||||
bt_mesh_generic_client_t *client = NULL;
|
||||
u16_t length = 0;
|
||||
bool need_ack = false;
|
||||
u16_t length = 0U;
|
||||
bool need_ack = false;
|
||||
|
||||
if (!common || !common->model || !set) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
@ -1173,7 +1167,7 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary)
|
||||
}
|
||||
|
||||
if (!client->internal_data) {
|
||||
internal = osi_calloc(sizeof(generic_internal_data_t));
|
||||
internal = bt_mesh_calloc(sizeof(generic_internal_data_t));
|
||||
if (!internal) {
|
||||
BT_ERR("%s, Failed to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
@ -1233,3 +1227,72 @@ int bt_mesh_gen_property_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_init(model, primary);
|
||||
}
|
||||
|
||||
static int generic_client_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
bt_mesh_generic_client_t *client = NULL;
|
||||
|
||||
if (!model) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
client = (bt_mesh_generic_client_t *)model->user_data;
|
||||
if (!client) {
|
||||
BT_ERR("%s, Generic Client user_data is NULL", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (client->internal_data) {
|
||||
/* Remove items from the list */
|
||||
bt_mesh_client_clear_list(client->internal_data);
|
||||
|
||||
/* Free the allocated internal data */
|
||||
bt_mesh_free(client->internal_data);
|
||||
client->internal_data = NULL;
|
||||
}
|
||||
|
||||
bt_mesh_generic_client_mutex_free();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_gen_onoff_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_level_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_def_trans_time_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_pwr_onoff_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_pwr_level_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_battery_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_location_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
||||
int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary)
|
||||
{
|
||||
return generic_client_deinit(model, primary);
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ void bt_mesh_client_model_unlock(void);
|
||||
|
||||
int bt_mesh_client_init(struct bt_mesh_model *model);
|
||||
|
||||
int bt_mesh_client_deinit(struct bt_mesh_model *model);
|
||||
|
||||
/**
|
||||
* @brief Check if the msg received by client model is a publish msg or not
|
||||
*
|
||||
@ -110,14 +112,6 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node);
|
||||
|
||||
int bt_mesh_client_clear_list(void *data);
|
||||
|
||||
enum {
|
||||
NODE = 0,
|
||||
PROVISIONER,
|
||||
FAST_PROV,
|
||||
};
|
||||
|
||||
#define ROLE_NVAL 0xFF
|
||||
|
||||
typedef struct {
|
||||
struct bt_mesh_model *model; /* The client model structure */
|
||||
u8_t role; /* Role of the device - Node/Provisioner */
|
||||
|
@ -19,9 +19,6 @@
|
||||
#ifndef _GENERIC_CLIENT_H_
|
||||
#define _GENERIC_CLIENT_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
#include "client_common.h"
|
||||
|
||||
/* Generic client model common structure */
|
||||
@ -466,6 +463,87 @@ int bt_mesh_gen_location_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
*/
|
||||
int bt_mesh_gen_property_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic onoff client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic onoff client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_onoff_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic level client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic level client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_level_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic default transition time
|
||||
* client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic default transition time client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_def_trans_time_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic power onoff client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic power onoff client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_pwr_onoff_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic power level client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic power level client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_pwr_level_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic battery client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic battery client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_battery_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic location client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic location client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_location_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize generic property client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to generic property client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get generic states.
|
||||
*
|
||||
|
@ -19,9 +19,6 @@
|
||||
#ifndef _LIGHTING_CLIENT_H_
|
||||
#define _LIGHTING_CLIENT_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
#include "client_common.h"
|
||||
|
||||
/* Light client model common structure */
|
||||
@ -467,6 +464,56 @@ int bt_mesh_light_xyl_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
*/
|
||||
int bt_mesh_light_lc_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize light lightness client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to light lightness client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_light_lightness_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize light ctl client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to light ctl client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_light_ctl_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize light hsl client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to light hsl client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_light_hsl_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize light xyl client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to light xyl client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_light_xyl_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize light lc client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to light lc client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_light_lc_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get light states.
|
||||
*
|
||||
|
@ -19,9 +19,6 @@
|
||||
#ifndef _SENSOR_CLIENT_H_
|
||||
#define _SENSOR_CLIENT_H_
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_kernel.h"
|
||||
|
||||
#include "client_common.h"
|
||||
|
||||
/* Sensor Client Model Context */
|
||||
@ -142,6 +139,16 @@ struct bt_mesh_sensor_series_get {
|
||||
*/
|
||||
int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to de-initialize sensor client model user_data.
|
||||
*
|
||||
* @param[in] model: Pointer to sensor client model
|
||||
* @param[in] primary: Whether belongs to primary element
|
||||
*
|
||||
* @return Zero-success, other-fail
|
||||
*/
|
||||
int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get sensor states.
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user