mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
components/bt: Add support of NimBLE host in ESP BLE Mesh
This commit is contained in:
parent
5b0d262489
commit
f58d7d14c7
@ -289,6 +289,11 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/bluedroid/stack/smp/smp_l2c.c"
|
||||
"host/bluedroid/stack/smp/smp_main.c"
|
||||
"host/bluedroid/stack/smp/smp_utils.c")
|
||||
|
||||
if(CONFIG_BLE_MESH)
|
||||
list(APPEND srcs "esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_BLE_MESH)
|
||||
@ -335,9 +340,7 @@ if(CONFIG_BT_ENABLED)
|
||||
"esp_ble_mesh/mesh_core/lpn.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_aes_encrypt.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_atomic.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_bearer_adapt.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_buf.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_hci.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_kernel.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_main.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_util.c"
|
||||
@ -469,6 +472,10 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/porting/nimble/src/os_cputime.c"
|
||||
"host/nimble/esp-hci/src/esp_nimble_hci.c")
|
||||
|
||||
if (CONFIG_BLE_MESH)
|
||||
list(APPEND srcs "esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_BT_NIMBLE_MESH)
|
||||
|
||||
list(APPEND include_dirs
|
||||
|
@ -410,7 +410,6 @@ endmenu
|
||||
|
||||
menuconfig BLE_MESH
|
||||
bool "ESP BLE Mesh Support"
|
||||
depends on BT_BLUEDROID_ENABLED
|
||||
help
|
||||
This option enables ESP BLE Mesh support. The specific features that are
|
||||
available may depend on other features that have been enabled in the
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "esp_log.h"
|
||||
#include "bt_common.h"
|
||||
#include "osi/allocator.h"
|
||||
#include "btc/btc_alarm.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "common/bt_target.h"
|
||||
@ -32,7 +33,6 @@
|
||||
#include "btc_blufi_prf.h"
|
||||
#include "blufi_int.h"
|
||||
#include "btc/btc_dm.h"
|
||||
#include "btc/btc_alarm.h"
|
||||
#include "bta/bta_gatt_api.h"
|
||||
#if CLASSIC_BT_INCLUDED
|
||||
#include "btc/btc_profile_queue.h"
|
||||
@ -94,7 +94,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
||||
#endif ///GATTS_INCLUDED == TRUE
|
||||
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
||||
#endif
|
||||
[BTC_PID_ALARM] = {btc_alarm_handler, NULL },
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#if CLASSIC_BT_INCLUDED
|
||||
#if (BTC_GAP_BT_INCLUDED == TRUE)
|
||||
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
|
||||
|
@ -15,9 +15,7 @@
|
||||
#ifndef __BTC_MANAGE_H__
|
||||
#define __BTC_MANAGE_H__
|
||||
|
||||
#include "bta/bta_api.h"
|
||||
#include "btc/btc_task.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#if BTC_DYNAMIC_MEMORY == FALSE
|
||||
extern void *btc_profile_cb_tab[BTC_PID_NUM];
|
||||
|
@ -49,7 +49,7 @@
|
||||
#ifdef CONFIG_BTC_TASK_STACK_SIZE
|
||||
#define UC_BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE
|
||||
#else
|
||||
#define UC_BTC_TASK_STACK_SIZE 3072
|
||||
#define UC_BTC_TASK_STACK_SIZE 4096
|
||||
#endif
|
||||
|
||||
/**********************************************************
|
||||
|
@ -129,26 +129,31 @@ COMPONENT_PRIV_INCLUDEDIRS += common/btc/include \
|
||||
COMPONENT_SRCDIRS += common/osi \
|
||||
common/btc/core
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core/bluedroid_host
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/include \
|
||||
esp_ble_mesh/mesh_core/settings \
|
||||
esp_ble_mesh/btc/include \
|
||||
esp_ble_mesh/mesh_models/common/include \
|
||||
esp_ble_mesh/mesh_models/client/include \
|
||||
esp_ble_mesh/api/core/include \
|
||||
esp_ble_mesh/api/models/include \
|
||||
esp_ble_mesh/api
|
||||
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/include \
|
||||
esp_ble_mesh/mesh_core/settings \
|
||||
esp_ble_mesh/btc/include \
|
||||
esp_ble_mesh/mesh_models/common/include \
|
||||
esp_ble_mesh/mesh_models/client/include \
|
||||
esp_ble_mesh/api/core/include \
|
||||
esp_ble_mesh/api/models/include \
|
||||
esp_ble_mesh/api
|
||||
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/settings \
|
||||
esp_ble_mesh/btc \
|
||||
esp_ble_mesh/mesh_models/common \
|
||||
esp_ble_mesh/mesh_models/client \
|
||||
esp_ble_mesh/api/core \
|
||||
esp_ble_mesh/api/models
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/settings \
|
||||
esp_ble_mesh/btc \
|
||||
esp_ble_mesh/mesh_models/common \
|
||||
esp_ble_mesh/mesh_models/client \
|
||||
esp_ble_mesh/api/core \
|
||||
esp_ble_mesh/api/models
|
||||
endif
|
||||
|
||||
|
||||
@ -196,6 +201,17 @@ endif
|
||||
|
||||
COMPONENT_OBJEXCLUDE += host/nimble/nimble/nimble/host/store/config/src/ble_store_config_conf.o
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
COMPONENT_PRIV_INCLUDEDIRS += common/btc/include \
|
||||
common/include
|
||||
|
||||
COMPONENT_SRCDIRS += common/osi \
|
||||
common/btc/core \
|
||||
esp_ble_mesh/mesh_core/nimble_host
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS += common/osi/include
|
||||
endif
|
||||
|
||||
ifdef CONFIG_BT_NIMBLE_MESH
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/nimble/host/mesh/include
|
||||
|
@ -8,6 +8,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_USE_DUPLICATE_SCAN
|
||||
bool "Support Duplicate Scan in BLE Mesh"
|
||||
depends on BT_BLUEDROID_ENABLED
|
||||
select BLE_SCAN_DUPLICATE
|
||||
select BLE_MESH_SCAN_DUPLICATE_EN
|
||||
default y
|
||||
|
@ -19,10 +19,9 @@
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/alarm.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
@ -32,12 +31,18 @@ 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;
|
||||
|
||||
if (prov == NULL || comp == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
ret = bt_mesh_host_init();
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Create a semaphore
|
||||
if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) {
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
@ -41,7 +39,7 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
|
||||
btc_msg_t msg = {0};
|
||||
esp_err_t status;
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
if (device_role > ROLE_FAST_PROV) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -118,7 +116,7 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
|
||||
|
||||
esp_err_t esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_MODEL, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -198,7 +196,7 @@ esp_err_t esp_ble_mesh_node_local_reset(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -218,7 +216,7 @@ esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -251,7 +249,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -283,7 +281,7 @@ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -306,7 +304,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_provisioning_api.h"
|
||||
@ -29,7 +27,7 @@
|
||||
|
||||
esp_err_t esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_PROV, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -44,7 +42,7 @@ esp_err_t esp_ble_mesh_node_prov_enable(esp_ble_mesh_prov_bearer_t bearers)
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -60,7 +58,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers)
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -81,7 +79,7 @@ esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_k
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -104,7 +102,7 @@ esp_err_t esp_ble_mesh_node_input_number(uint32_t number)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -124,7 +122,7 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -145,7 +143,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -168,7 +166,7 @@ esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pu
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -191,7 +189,7 @@ esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -214,7 +212,7 @@ esp_err_t esp_ble_mesh_provisioner_input_number(uint32_t number, uint8_t link_id
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -232,7 +230,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_enable(esp_ble_mesh_prov_bearer_t bearer
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -249,7 +247,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -271,7 +269,7 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -280,7 +278,7 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
|
||||
arg.provisioner_dev_add.add_dev.addr_type = add_dev->addr_type;
|
||||
arg.provisioner_dev_add.add_dev.oob_info = add_dev->oob_info;
|
||||
arg.provisioner_dev_add.add_dev.bearer = add_dev->bearer;
|
||||
memcpy(arg.provisioner_dev_add.add_dev.addr, add_dev->addr, sizeof(esp_bd_addr_t));
|
||||
memcpy(arg.provisioner_dev_add.add_dev.addr, add_dev->addr, sizeof(esp_ble_mesh_bd_addr_t));
|
||||
memcpy(arg.provisioner_dev_add.add_dev.uuid, add_dev->uuid, 16);
|
||||
arg.provisioner_dev_add.flags = flags;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
@ -297,7 +295,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -306,7 +304,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
arg.provisioner_dev_del.del_dev.flag = del_dev->flag;
|
||||
if (del_dev->flag & DEL_DEV_ADDR_FLAG) {
|
||||
arg.provisioner_dev_del.del_dev.addr_type = del_dev->addr_type;
|
||||
memcpy(arg.provisioner_dev_del.del_dev.addr, del_dev->addr, sizeof(esp_bd_addr_t));
|
||||
memcpy(arg.provisioner_dev_del.del_dev.addr, del_dev->addr, sizeof(esp_ble_mesh_bd_addr_t));
|
||||
} else if (del_dev->flag & DEL_DEV_UUID_FLAG) {
|
||||
memcpy(arg.provisioner_dev_del.del_dev.uuid, del_dev->uuid, 16);
|
||||
}
|
||||
@ -320,7 +318,7 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val,
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -346,7 +344,7 @@ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_inf
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -379,7 +377,7 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -408,7 +406,7 @@ esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t acti
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
@ -28,7 +26,7 @@ esp_err_t esp_ble_mesh_proxy_identity_enable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -41,7 +39,7 @@ esp_err_t esp_ble_mesh_proxy_gatt_enable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -54,7 +52,7 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
|
@ -259,7 +259,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
* @param[in] bearer: Adv packet received from PB-GATT or PB-ADV bearer.
|
||||
*
|
||||
*/
|
||||
typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_bd_addr_t addr, const esp_ble_addr_type_t addr_type,
|
||||
typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_ble_mesh_bd_addr_t addr, const esp_ble_mesh_addr_type_t addr_type,
|
||||
const uint8_t adv_type, const uint8_t *dev_uuid,
|
||||
uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer);
|
||||
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#include "mesh_proxy.h"
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_main.h"
|
||||
@ -31,6 +29,16 @@
|
||||
#include "model_opcode.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#define ESP_BLE_HOST_STATUS_ENABLED ESP_BLUEDROID_STATUS_ENABLED
|
||||
#define ESP_BLE_HOST_STATUS_CHECK(status) ESP_BLUEDROID_STATUS_CHECK(status)
|
||||
#else
|
||||
#define ESP_BLE_HOST_STATUS_ENABLED 0
|
||||
#define ESP_BLE_HOST_STATUS_CHECK(status) do {} while (0)
|
||||
#endif
|
||||
|
||||
/*!< The maximum length of a BLE Mesh message, including Opcode, Payload and TransMIC */
|
||||
#define ESP_BLE_MESH_SDU_MAX_LEN 384
|
||||
|
||||
@ -790,6 +798,30 @@ typedef enum {
|
||||
.input_action = in_act, \
|
||||
}
|
||||
|
||||
typedef uint8_t UINT8;
|
||||
typedef uint16_t UINT16;
|
||||
typedef uint32_t UINT32;
|
||||
typedef uint64_t UINT64;
|
||||
|
||||
#define BT_OCTET32_LEN 32
|
||||
typedef UINT8 BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */
|
||||
|
||||
|
||||
#ifndef BD_ADDR_LEN
|
||||
#define BD_ADDR_LEN 6
|
||||
typedef uint8_t BD_ADDR[BD_ADDR_LEN];
|
||||
#endif
|
||||
|
||||
typedef uint8_t esp_ble_mesh_bd_addr_t[BD_ADDR_LEN];
|
||||
|
||||
/// BLE device address type
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_ADDR_TYPE_PUBLIC = 0x00,
|
||||
ESP_BLE_MESH_ADDR_TYPE_RANDOM = 0x01,
|
||||
ESP_BLE_MESH_ADDR_TYPE_RPA_PUBLIC = 0x02,
|
||||
ESP_BLE_MESH_ADDR_TYPE_RPA_RANDOM = 0x03,
|
||||
} esp_ble_mesh_addr_type_t;
|
||||
|
||||
typedef struct esp_ble_mesh_model esp_ble_mesh_model_t;
|
||||
|
||||
/** Abstraction that describes a BLE Mesh Element.
|
||||
@ -1110,8 +1142,8 @@ typedef uint8_t esp_ble_mesh_dev_add_flag_t;
|
||||
|
||||
/** Information of the device which is going to be added for provisioning. */
|
||||
typedef struct {
|
||||
esp_bd_addr_t addr; /*!< Device address */
|
||||
esp_ble_addr_type_t addr_type; /*!< Device address type */
|
||||
esp_ble_mesh_bd_addr_t addr; /*!< Device address */
|
||||
esp_ble_mesh_addr_type_t addr_type; /*!< Device address type */
|
||||
uint8_t uuid[16]; /*!< Device UUID */
|
||||
uint16_t oob_info; /*!< Device OOB Info */
|
||||
/*!< ADD_DEV_START_PROV_NOW_FLAG shall not be set if the bearer has both PB-ADV and PB-GATT enabled */
|
||||
@ -1124,8 +1156,8 @@ typedef struct {
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
esp_bd_addr_t addr; /*!< Device address */
|
||||
esp_ble_addr_type_t addr_type; /*!< Device address type */
|
||||
esp_ble_mesh_bd_addr_t addr; /*!< Device address */
|
||||
esp_ble_mesh_addr_type_t addr_type; /*!< Device address type */
|
||||
};
|
||||
uint8_t uuid[16]; /*!< Device UUID */
|
||||
};
|
||||
@ -1340,7 +1372,7 @@ typedef union {
|
||||
struct ble_mesh_provisioner_recv_unprov_adv_pkt_param {
|
||||
uint8_t dev_uuid[16]; /*!< Device UUID of the unprovisoned device */
|
||||
uint8_t addr[6]; /*!< Device address of the unprovisoned device */
|
||||
esp_ble_addr_type_t addr_type; /*!< Device address type */
|
||||
esp_ble_mesh_addr_type_t addr_type; /*!< Device address type */
|
||||
uint16_t oob_info; /*!< OOB Info of the unprovisoned device */
|
||||
uint8_t adv_type; /*!< Avertising type of the unprovisoned device */
|
||||
esp_ble_mesh_prov_bearer_t bearer; /*!< Bearer of the unprovisoned device */
|
||||
|
@ -17,22 +17,19 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -47,7 +44,7 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_CONFIG_CLIENT;
|
||||
@ -69,7 +66,7 @@ esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_CONFIG_CLIENT;
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_GENERIC_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GENERIC_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GENERIC_CLIENT;
|
||||
|
@ -17,22 +17,19 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_health_client_callback(esp_ble_mesh_health_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_HEALTH_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_server_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_HEALTH_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -47,7 +44,7 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
@ -69,7 +66,7 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
@ -86,7 +83,7 @@ esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element)
|
||||
btc_ble_mesh_health_server_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_HEALTH_SERVER;
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_LIGHTING_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_LIGHTING_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_LIGHTING_CLIENT;
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_SENSOR_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_SENSOR_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_SENSOR_CLIENT;
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_TIME_SCENE_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
|
||||
|
@ -689,7 +689,7 @@ static void btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb(
|
||||
}
|
||||
|
||||
memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.dev_uuid, dev_uuid, 16);
|
||||
memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.addr, addr, ESP_BD_ADDR_LEN);
|
||||
memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.addr, addr, BLE_MESH_ADDR_LEN);
|
||||
mesh_param.provisioner_recv_unprov_adv_pkt.addr_type = addr_type;
|
||||
mesh_param.provisioner_recv_unprov_adv_pkt.oob_info = oob_info;
|
||||
mesh_param.provisioner_recv_unprov_adv_pkt.adv_type = adv_type;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_buf.h"
|
||||
|
@ -388,7 +388,7 @@ void bt_mesh_adv_init(void)
|
||||
xBleMeshQueue = xQueueCreate(150, sizeof(bt_mesh_msg_t));
|
||||
configASSERT(xBleMeshQueue);
|
||||
int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL,
|
||||
configMAX_PRIORITIES - 7, NULL, TASK_PINNED_TO_CORE);
|
||||
configMAX_PRIORITIES - 7, NULL, ADV_TASK_CORE);
|
||||
configASSERT(ret == pdTRUE);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "stack/hcimsgs.h"
|
||||
#include "osi/future.h"
|
||||
#include "osi/allocator.h"
|
||||
#include "bt_common.h"
|
||||
#include "device/controller.h"
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
@ -32,6 +34,8 @@
|
||||
#include "provisioner_prov.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
struct bt_mesh_dev bt_mesh_dev;
|
||||
|
||||
#define BLE_MESH_BTM_CHECK_STATUS(func) do { \
|
||||
tBTM_STATUS __status = (func); \
|
||||
if ((__status != BTM_SUCCESS) && (__status != BTM_CMD_STARTED)) { \
|
||||
@ -97,6 +101,40 @@ static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
|
||||
static tBTA_GATTC_IF bt_mesh_gattc_if;
|
||||
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
esp_err_t bt_mesh_host_init(void)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void bt_mesh_hci_init(void)
|
||||
{
|
||||
const uint8_t *features = controller_get_interface()->get_features_ble()->as_array;
|
||||
if (features != NULL) {
|
||||
memcpy(bt_mesh_dev.features[0], features, 8);
|
||||
memcpy(bt_mesh_dev.le.features, features, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently 20ms non-connectable adv interval is supported, and we need to add
|
||||
* a flag to indicate this support.
|
||||
*/
|
||||
#ifdef CONFIG_BLE_MESH_HCI_5_0
|
||||
bt_mesh_dev.hci_version = BLE_MESH_HCI_VERSION_5_0;
|
||||
#else
|
||||
bt_mesh_dev.hci_version = controller_get_interface()->get_bt_version()->hci_version;
|
||||
#endif
|
||||
bt_mesh_dev.lmp_version = controller_get_interface()->get_bt_version()->lmp_version;
|
||||
bt_mesh_dev.hci_revision = controller_get_interface()->get_bt_version()->hci_revision;
|
||||
bt_mesh_dev.lmp_subversion = controller_get_interface()->get_bt_version()->lmp_subversion;
|
||||
bt_mesh_dev.manufacturer = controller_get_interface()->get_bt_version()->manufacturer;
|
||||
|
||||
const uint8_t *p = controller_get_interface()->get_ble_supported_states();
|
||||
uint64_t states_fh = 0, states_sh = 0;
|
||||
STREAM_TO_UINT32(states_fh, p);
|
||||
STREAM_TO_UINT32(states_sh, p);
|
||||
bt_mesh_dev.le.states = (states_sh << 32) | states_fh;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
@ -16,8 +16,23 @@
|
||||
#include "mesh_uuid.h"
|
||||
|
||||
/* BLE Mesh Max Connection Count */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
|
||||
|
||||
#define 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)
|
||||
#else
|
||||
#define ADV_TASK_CORE (0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* BD ADDR types */
|
||||
#define BLE_MESH_ADDR_PUBLIC 0x00
|
||||
#define BLE_MESH_ADDR_RANDOM 0x01
|
||||
@ -620,6 +635,8 @@ struct bt_mesh_gatt_attr {
|
||||
.attr_count = ARRAY_SIZE(_attrs), \
|
||||
}
|
||||
|
||||
esp_err_t bt_mesh_host_init(void);
|
||||
|
||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
const struct bt_mesh_adv_data *sd, size_t sd_len);
|
||||
|
@ -47,6 +47,12 @@
|
||||
|
||||
#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
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2015-2016 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "stack/bt_types.h"
|
||||
#include "device/controller.h"
|
||||
|
||||
#include "mesh_hci.h"
|
||||
|
||||
struct bt_mesh_dev bt_mesh_dev;
|
||||
|
||||
void bt_mesh_hci_init(void)
|
||||
{
|
||||
const uint8_t *features = controller_get_interface()->get_features_ble()->as_array;
|
||||
if (features != NULL) {
|
||||
memcpy(bt_mesh_dev.features[0], features, 8);
|
||||
memcpy(bt_mesh_dev.le.features, features, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently 20ms non-connectable adv interval is supported, and we need to add
|
||||
* a flag to indicate this support.
|
||||
*/
|
||||
#ifdef CONFIG_BLE_MESH_HCI_5_0
|
||||
bt_mesh_dev.hci_version = BLE_MESH_HCI_VERSION_5_0;
|
||||
#else
|
||||
bt_mesh_dev.hci_version = controller_get_interface()->get_bt_version()->hci_version;
|
||||
#endif
|
||||
bt_mesh_dev.lmp_version = controller_get_interface()->get_bt_version()->lmp_version;
|
||||
bt_mesh_dev.hci_revision = controller_get_interface()->get_bt_version()->hci_revision;
|
||||
bt_mesh_dev.lmp_subversion = controller_get_interface()->get_bt_version()->lmp_subversion;
|
||||
bt_mesh_dev.manufacturer = controller_get_interface()->get_bt_version()->manufacturer;
|
||||
|
||||
const uint8_t *p = controller_get_interface()->get_ble_supported_states();
|
||||
uint64_t states_fh = 0, states_sh = 0;
|
||||
STREAM_TO_UINT32(states_fh, p);
|
||||
STREAM_TO_UINT32(states_sh, p);
|
||||
bt_mesh_dev.le.states = (states_sh << 32) | states_fh;
|
||||
}
|
@ -14,8 +14,7 @@
|
||||
#include "osi/alarm.h"
|
||||
#include "osi/hash_functions.h"
|
||||
|
||||
#include "common/bt_trace.h"
|
||||
#include "common/bt_defs.h"
|
||||
#include "bt_common.h"
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
|
1796
components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c
Normal file
1796
components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,7 @@
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_gap_bt_api.h"
|
||||
#include "common/bt_trace.h"
|
||||
#include "bta/bta_api.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "btc_gap_bt.h"
|
||||
#include "btc/btc_storage.h"
|
||||
|
@ -53,6 +53,7 @@ config BT_NIMBLE_PINNED_TO_CORE
|
||||
config BT_NIMBLE_TASK_STACK_SIZE
|
||||
int "NimBLE Host task stack size"
|
||||
depends on BT_NIMBLE_ENABLED
|
||||
default 5120 if BLE_MESH
|
||||
default 4096
|
||||
help
|
||||
This configures stack size of NimBLE host task
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c"
|
||||
"ble_mesh_demo_init.c"
|
||||
"board.c")
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
|
@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
/* BLE */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
static SemaphoreHandle_t mesh_sem;
|
||||
static uint8_t own_addr_type;
|
||||
void ble_store_config_init(void);
|
||||
static uint8_t addr_val[6] = {0};
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, addr_val, BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void mesh_on_reset(int reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "Resetting state; reason=%d", reason);
|
||||
}
|
||||
|
||||
static void mesh_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
ESP_LOGI(TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
xSemaphoreGive(mesh_sem);
|
||||
}
|
||||
|
||||
void mesh_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(TAG, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
mesh_sem = xSemaphoreCreateBinary();
|
||||
if (mesh_sem == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create mesh semaphore");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
|
||||
|
||||
nimble_port_init();
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = mesh_on_reset;
|
||||
ble_hs_cfg.sync_cb = mesh_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(mesh_host_task);
|
||||
|
||||
xSemaphoreTake(mesh_sem, portMAX_DELAY);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_DEMO_INIT_H_
|
||||
#define _BLE_MESH_DEMO_INIT_H_
|
||||
|
||||
#define TAG "ble_mesh_client"
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid);
|
||||
|
||||
esp_err_t bluetooth_init(void);
|
||||
|
||||
#endif
|
@ -13,9 +13,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
#include "esp_ble_mesh_provisioning_api.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
@ -23,8 +20,7 @@
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define TAG "ble_mesh_client"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
|
||||
#define CID_ESP 0x02E5
|
||||
|
||||
@ -450,8 +446,6 @@ static int ble_mesh_init(void)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), ESP_BD_ADDR_LEN);
|
||||
|
||||
esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb);
|
||||
esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_cb);
|
||||
@ -471,45 +465,6 @@ static int ble_mesh_init(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
int err;
|
||||
@ -518,12 +473,21 @@ void app_main(void)
|
||||
|
||||
board_init();
|
||||
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = bluetooth_init();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ble_mesh_get_dev_uuid(dev_uuid);
|
||||
|
||||
/* Initialize the Bluetooth Mesh Subsystem */
|
||||
err = ble_mesh_init();
|
||||
if (err) {
|
||||
|
@ -82,7 +82,7 @@ ble_mesh_provisioner_add_key_t provisioner_add_key;
|
||||
|
||||
void ble_mesh_regist_provisioner_cmd(void);
|
||||
|
||||
void ble_mesh_prov_adv_cb(const esp_bd_addr_t addr, const esp_ble_addr_type_t addr_type, const uint8_t adv_type,
|
||||
void ble_mesh_prov_adv_cb(const esp_ble_mesh_bd_addr_t addr, const esp_ble_mesh_addr_type_t addr_type, const uint8_t adv_type,
|
||||
const uint8_t *dev_uuid, uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer);
|
||||
|
||||
void ble_mesh_register_mesh_provisioner(void)
|
||||
@ -90,12 +90,12 @@ void ble_mesh_register_mesh_provisioner(void)
|
||||
ble_mesh_regist_provisioner_cmd();
|
||||
}
|
||||
|
||||
void ble_mesh_prov_adv_cb(const esp_bd_addr_t addr, const esp_ble_addr_type_t addr_type, const uint8_t adv_type,
|
||||
void ble_mesh_prov_adv_cb(const esp_ble_mesh_bd_addr_t addr, const esp_ble_mesh_addr_type_t addr_type, const uint8_t adv_type,
|
||||
const uint8_t *dev_uuid, uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer)
|
||||
{
|
||||
ESP_LOGD(TAG, "enter %s\n", __func__);
|
||||
ESP_LOGI(TAG, "scan device address:");
|
||||
esp_log_buffer_hex(TAG, addr, sizeof(esp_bd_addr_t));
|
||||
esp_log_buffer_hex(TAG, addr, sizeof(esp_ble_mesh_bd_addr_t));
|
||||
ESP_LOGI(TAG, "scan device uuid:");
|
||||
esp_log_buffer_hex(TAG, dev_uuid, 16);
|
||||
ESP_LOGD(TAG, "exit %s\n", __func__);
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c")
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c"
|
||||
"ble_mesh_demo_init.c")
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
|
||||
|
@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
/* BLE */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
static SemaphoreHandle_t mesh_sem;
|
||||
static uint8_t own_addr_type;
|
||||
void ble_store_config_init(void);
|
||||
static uint8_t addr_val[6] = {0};
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, addr_val, BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void mesh_on_reset(int reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "Resetting state; reason=%d", reason);
|
||||
}
|
||||
|
||||
static void mesh_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
ESP_LOGI(TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
xSemaphoreGive(mesh_sem);
|
||||
}
|
||||
|
||||
void mesh_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(TAG, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
mesh_sem = xSemaphoreCreateBinary();
|
||||
if (mesh_sem == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create mesh semaphore");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
|
||||
|
||||
nimble_port_init();
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = mesh_on_reset;
|
||||
ble_hs_cfg.sync_cb = mesh_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(mesh_host_task);
|
||||
|
||||
xSemaphoreTake(mesh_sem, portMAX_DELAY);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_DEMO_INIT_H_
|
||||
#define _BLE_MESH_DEMO_INIT_H_
|
||||
|
||||
#define TAG "FAST_PROV_CLIENT_DEMO"
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid);
|
||||
|
||||
esp_err_t bluetooth_init(void);
|
||||
|
||||
#endif
|
@ -19,10 +19,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#include "esp_gap_ble_api.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
#include "esp_ble_mesh_provisioning_api.h"
|
||||
@ -33,8 +29,7 @@
|
||||
#include "esp_fast_prov_common.h"
|
||||
#include "esp_fast_prov_operation.h"
|
||||
#include "esp_fast_prov_client_model.h"
|
||||
|
||||
#define TAG "FAST_PROV_CLIENT_DEMO"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
|
||||
#define PROV_OWN_ADDR 0x0001
|
||||
#define APP_KEY_OCTET 0x12
|
||||
@ -191,8 +186,8 @@ static void provisioner_prov_complete(int node_index, const uint8_t uuid[16], ui
|
||||
}
|
||||
}
|
||||
|
||||
static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_BD_ADDR_LEN],
|
||||
esp_ble_addr_type_t addr_type, uint16_t oob_info,
|
||||
static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[BLE_MESH_ADDR_LEN],
|
||||
esp_ble_mesh_addr_type_t addr_type, uint16_t oob_info,
|
||||
uint8_t adv_type, esp_ble_mesh_prov_bearer_t bearer)
|
||||
{
|
||||
esp_ble_mesh_unprov_dev_add_t add_dev = {0};
|
||||
@ -532,8 +527,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
memcpy(dev_uuid, esp_bt_dev_get_address(), 6);
|
||||
|
||||
prov_info.unicast_min = prov.prov_start_address + prov_info.max_node_num;
|
||||
prov_info.match_len = sizeof(match);
|
||||
memcpy(prov_info.match_val, match, sizeof(match));
|
||||
@ -544,18 +537,18 @@ static esp_err_t ble_mesh_init(void)
|
||||
esp_ble_mesh_register_config_client_callback(example_config_client_callback);
|
||||
esp_ble_mesh_register_generic_client_callback(example_generic_client_callback);
|
||||
|
||||
err = esp_ble_mesh_provisioner_set_dev_uuid_match(match, 0x02, 0x00, false);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: Failed to set matching device UUID", __func__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
err = esp_ble_mesh_init(&prov, &comp);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: Failed to initialize BLE Mesh", __func__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
err = esp_ble_mesh_provisioner_set_dev_uuid_match(match, 0x02, 0x00, false);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: Failed to set matching device UUID", __func__);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
err = esp_ble_mesh_client_model_init(&vnd_models[0]);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: Failed to initialize fast prov client model", __func__);
|
||||
@ -579,57 +572,27 @@ static esp_err_t ble_mesh_init(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
ESP_LOGI(TAG, "Initializing...");
|
||||
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = bluetooth_init();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ble_mesh_get_dev_uuid(dev_uuid);
|
||||
|
||||
/* Initialize the Bluetooth Mesh Subsystem */
|
||||
err = ble_mesh_init();
|
||||
if (err) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c"
|
||||
"ble_mesh_demo_init.c"
|
||||
"board.c")
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
|
@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
/* BLE */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
static SemaphoreHandle_t mesh_sem;
|
||||
static uint8_t own_addr_type;
|
||||
void ble_store_config_init(void);
|
||||
static uint8_t addr_val[6] = {0};
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, addr_val, BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void mesh_on_reset(int reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "Resetting state; reason=%d", reason);
|
||||
}
|
||||
|
||||
static void mesh_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
ESP_LOGI(TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
xSemaphoreGive(mesh_sem);
|
||||
}
|
||||
|
||||
void mesh_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(TAG, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
mesh_sem = xSemaphoreCreateBinary();
|
||||
if (mesh_sem == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create mesh semaphore");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
|
||||
|
||||
nimble_port_init();
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = mesh_on_reset;
|
||||
ble_hs_cfg.sync_cb = mesh_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(mesh_host_task);
|
||||
|
||||
xSemaphoreTake(mesh_sem, portMAX_DELAY);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_DEMO_INIT_H_
|
||||
#define _BLE_MESH_DEMO_INIT_H_
|
||||
|
||||
#define TAG "FAST_PROV_SERVER_DEMO"
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid);
|
||||
|
||||
esp_err_t bluetooth_init(void);
|
||||
|
||||
#endif
|
@ -18,10 +18,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
@ -33,8 +29,7 @@
|
||||
#include "esp_fast_prov_operation.h"
|
||||
#include "esp_fast_prov_client_model.h"
|
||||
#include "esp_fast_prov_server_model.h"
|
||||
|
||||
#define TAG "FAST_PROV_SERVER_DEMO"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
|
||||
extern struct _led_state led_state[3];
|
||||
extern struct k_delayed_work send_self_prov_node_addr_timer;
|
||||
@ -336,8 +331,8 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint
|
||||
}
|
||||
}
|
||||
|
||||
static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_BD_ADDR_LEN],
|
||||
esp_ble_addr_type_t addr_type, uint16_t oob_info,
|
||||
static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[BLE_MESH_ADDR_LEN],
|
||||
esp_ble_mesh_addr_type_t addr_type, uint16_t oob_info,
|
||||
uint8_t adv_type, esp_ble_mesh_prov_bearer_t bearer)
|
||||
{
|
||||
esp_ble_mesh_unprov_dev_add_t add_dev = {0};
|
||||
@ -358,7 +353,7 @@ static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_B
|
||||
add_dev.oob_info = oob_info;
|
||||
add_dev.bearer = (uint8_t)bearer;
|
||||
memcpy(add_dev.uuid, dev_uuid, 16);
|
||||
memcpy(add_dev.addr, addr, ESP_BD_ADDR_LEN);
|
||||
memcpy(add_dev.addr, addr, BLE_MESH_ADDR_LEN);
|
||||
flag = ADD_DEV_RM_AFTER_PROV_FLAG | ADD_DEV_START_PROV_NOW_FLAG | ADD_DEV_FLUSHABLE_DEV_FLAG;
|
||||
err = esp_ble_mesh_provisioner_add_unprov_dev(&add_dev, flag);
|
||||
if (err != ESP_OK) {
|
||||
@ -733,9 +728,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
/* First two bytes of device uuid is compared with match value by Provisioner */
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), 6);
|
||||
|
||||
esp_ble_mesh_register_prov_callback(example_ble_mesh_provisioning_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(example_ble_mesh_custom_model_cb);
|
||||
esp_ble_mesh_register_config_client_callback(example_ble_mesh_config_client_cb);
|
||||
@ -774,47 +766,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
@ -827,12 +778,21 @@ void app_main(void)
|
||||
return;
|
||||
}
|
||||
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = bluetooth_init();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ble_mesh_get_dev_uuid(dev_uuid);
|
||||
|
||||
/* Initialize the Bluetooth Mesh Subsystem */
|
||||
err = ble_mesh_init();
|
||||
if (err) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c"
|
||||
"ble_mesh_demo_init.c"
|
||||
"board.c")
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
|
@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
/* BLE */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
static SemaphoreHandle_t mesh_sem;
|
||||
static uint8_t own_addr_type;
|
||||
void ble_store_config_init(void);
|
||||
static uint8_t addr_val[6] = {0};
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, addr_val, BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void mesh_on_reset(int reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "Resetting state; reason=%d", reason);
|
||||
}
|
||||
|
||||
static void mesh_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
ESP_LOGI(TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
xSemaphoreGive(mesh_sem);
|
||||
}
|
||||
|
||||
void mesh_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(TAG, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
mesh_sem = xSemaphoreCreateBinary();
|
||||
if (mesh_sem == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create mesh semaphore");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
|
||||
|
||||
nimble_port_init();
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = mesh_on_reset;
|
||||
ble_hs_cfg.sync_cb = mesh_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(mesh_host_task);
|
||||
|
||||
xSemaphoreTake(mesh_sem, portMAX_DELAY);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_DEMO_INIT_H_
|
||||
#define _BLE_MESH_DEMO_INIT_H_
|
||||
|
||||
#define TAG "ble_mesh_node"
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid);
|
||||
|
||||
esp_err_t bluetooth_init(void);
|
||||
|
||||
#endif
|
@ -13,10 +13,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
@ -24,8 +20,7 @@
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define TAG "ble_mesh_node"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
|
||||
#define CID_ESP 0x02E5
|
||||
|
||||
@ -314,8 +309,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), ESP_BD_ADDR_LEN);
|
||||
|
||||
esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb);
|
||||
|
||||
@ -334,45 +327,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
int err;
|
||||
@ -381,12 +335,21 @@ void app_main(void)
|
||||
|
||||
board_init();
|
||||
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = bluetooth_init();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ble_mesh_get_dev_uuid(dev_uuid);
|
||||
|
||||
/* Initialize the Bluetooth Mesh Subsystem */
|
||||
err = ble_mesh_init();
|
||||
if (err) {
|
||||
|
@ -97,7 +97,7 @@ static esp_err_t ble_mesh_init(void)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), ESP_BD_ADDR_LEN);
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), BLE_MESH_ADDR_LEN);
|
||||
|
||||
// See comment 1
|
||||
esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb);
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c")
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c"
|
||||
"ble_mesh_demo_init.c")
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
|
||||
|
@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
/* BLE */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
static SemaphoreHandle_t mesh_sem;
|
||||
static uint8_t own_addr_type;
|
||||
void ble_store_config_init(void);
|
||||
static uint8_t addr_val[6] = {0};
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, addr_val, BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void mesh_on_reset(int reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "Resetting state; reason=%d", reason);
|
||||
}
|
||||
|
||||
static void mesh_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
ESP_LOGI(TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
xSemaphoreGive(mesh_sem);
|
||||
}
|
||||
|
||||
void mesh_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(TAG, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
mesh_sem = xSemaphoreCreateBinary();
|
||||
if (mesh_sem == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create mesh semaphore");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
|
||||
|
||||
nimble_port_init();
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = mesh_on_reset;
|
||||
ble_hs_cfg.sync_cb = mesh_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(mesh_host_task);
|
||||
|
||||
xSemaphoreTake(mesh_sem, portMAX_DELAY);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_DEMO_INIT_H_
|
||||
#define _BLE_MESH_DEMO_INIT_H_
|
||||
|
||||
#define TAG "ble_mesh_provisioner"
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid);
|
||||
|
||||
esp_err_t bluetooth_init(void);
|
||||
|
||||
#endif
|
@ -12,10 +12,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
#include "esp_ble_mesh_provisioning_api.h"
|
||||
@ -23,7 +19,7 @@
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
#define TAG "ble_mesh_provisioner"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
|
||||
#define LED_OFF 0x0
|
||||
#define LED_ON 0x1
|
||||
@ -243,8 +239,8 @@ static void prov_link_close(esp_ble_mesh_prov_bearer_t bearer, uint8_t reason)
|
||||
bearer == ESP_BLE_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT", reason);
|
||||
}
|
||||
|
||||
static void recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_BD_ADDR_LEN],
|
||||
esp_ble_addr_type_t addr_type, uint16_t oob_info,
|
||||
static void recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[BD_ADDR_LEN],
|
||||
esp_ble_mesh_addr_type_t addr_type, uint16_t oob_info,
|
||||
uint8_t adv_type, esp_ble_mesh_prov_bearer_t bearer)
|
||||
{
|
||||
esp_ble_mesh_unprov_dev_add_t add_dev = {0};
|
||||
@ -255,11 +251,11 @@ static void recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_BD_ADDR_L
|
||||
* to the application layer.
|
||||
*/
|
||||
|
||||
ESP_LOGI(TAG, "address: %s, address type: %d, adv type: %d", bt_hex(addr, ESP_BD_ADDR_LEN), addr_type, adv_type);
|
||||
ESP_LOGI(TAG, "address: %s, address type: %d, adv type: %d", bt_hex(addr, BD_ADDR_LEN), addr_type, adv_type);
|
||||
ESP_LOGI(TAG, "device uuid: %s", bt_hex(dev_uuid, 16));
|
||||
ESP_LOGI(TAG, "oob info: %d, bearer: %s", oob_info, (bearer & ESP_BLE_MESH_PROV_ADV) ? "PB-ADV" : "PB-GATT");
|
||||
|
||||
memcpy(add_dev.addr, addr, ESP_BD_ADDR_LEN);
|
||||
memcpy(add_dev.addr, addr, BD_ADDR_LEN);
|
||||
add_dev.addr_type = (uint8_t)addr_type;
|
||||
memcpy(add_dev.uuid, dev_uuid, 16);
|
||||
add_dev.oob_info = oob_info;
|
||||
@ -608,14 +604,11 @@ static int ble_mesh_init(void)
|
||||
prov_key.app_idx = APP_KEY_IDX;
|
||||
memset(prov_key.app_key, APP_KEY_OCTET, sizeof(prov_key.app_key));
|
||||
|
||||
memcpy(dev_uuid, esp_bt_dev_get_address(), ESP_BD_ADDR_LEN);
|
||||
|
||||
esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb);
|
||||
esp_ble_mesh_register_config_client_callback(esp_ble_mesh_config_client_cb);
|
||||
esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_client_cb);
|
||||
|
||||
esp_ble_mesh_provisioner_set_dev_uuid_match(match, sizeof(match), 0x0, false);
|
||||
|
||||
err = esp_ble_mesh_init(&provision, &composition);
|
||||
if (err) {
|
||||
@ -623,6 +616,8 @@ static int ble_mesh_init(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_ble_mesh_provisioner_set_dev_uuid_match(match, sizeof(match), 0x0, false);
|
||||
|
||||
esp_ble_mesh_provisioner_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT);
|
||||
|
||||
esp_ble_mesh_provisioner_add_local_app_key(prov_key.app_key, prov_key.net_idx, prov_key.app_idx);
|
||||
@ -632,57 +627,27 @@ static int ble_mesh_init(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
ESP_LOGI(TAG, "Initializing...");
|
||||
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = bluetooth_init();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ble_mesh_get_dev_uuid(dev_uuid);
|
||||
|
||||
/* Initialize the Bluetooth Mesh Subsystem */
|
||||
err = ble_mesh_init();
|
||||
if (err) {
|
||||
|
@ -21,7 +21,7 @@ static int ble_mesh_init(void)
|
||||
prov_key.app_idx = ESP_BLE_MESH_APP_IDX;
|
||||
memset(prov_key.app_key, APP_KEY_OCTET, sizeof(prov_key.app_key));
|
||||
|
||||
memcpy(dev_uuid, esp_bt_dev_get_address(), ESP_BD_ADDR_LEN);
|
||||
memcpy(dev_uuid, esp_bt_dev_get_address(), BLE_MESH_ADDR_LEN);
|
||||
|
||||
esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb);
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(COMPONENT_SRCS "ble_mesh_demo_main.c"
|
||||
"ble_mesh_demo_init.c"
|
||||
"board.c")
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
|
@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sdkconfig.h>
|
||||
/* BLE */
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "esp_nimble_hci.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
static SemaphoreHandle_t mesh_sem;
|
||||
static uint8_t own_addr_type;
|
||||
void ble_store_config_init(void);
|
||||
static uint8_t addr_val[6] = {0};
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid)
|
||||
{
|
||||
memcpy(dev_uuid + 2, addr_val, BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
static void mesh_on_reset(int reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "Resetting state; reason=%d", reason);
|
||||
}
|
||||
|
||||
static void mesh_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
ESP_LOGI(TAG, "error determining address type; rc=%d", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
xSemaphoreGive(mesh_sem);
|
||||
}
|
||||
|
||||
void mesh_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(TAG, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
esp_err_t bluetooth_init(void)
|
||||
{
|
||||
mesh_sem = xSemaphoreCreateBinary();
|
||||
if (mesh_sem == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to create mesh semaphore");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
|
||||
|
||||
nimble_port_init();
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = mesh_on_reset;
|
||||
ble_hs_cfg.sync_cb = mesh_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(mesh_host_task);
|
||||
|
||||
xSemaphoreTake(mesh_sem, portMAX_DELAY);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#ifndef _BLE_MESH_DEMO_INIT_H_
|
||||
#define _BLE_MESH_DEMO_INIT_H_
|
||||
|
||||
#define TAG "BLE_MESH_WIFI_COEXIST_DEMO"
|
||||
|
||||
void ble_mesh_get_dev_uuid(uint8_t *dev_uuid);
|
||||
|
||||
esp_err_t bluetooth_init(void);
|
||||
|
||||
#endif
|
@ -30,10 +30,6 @@
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "cmd_decl.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_device.h"
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "esp_ble_mesh_common_api.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
@ -45,8 +41,7 @@
|
||||
#include "esp_fast_prov_operation.h"
|
||||
#include "esp_fast_prov_client_model.h"
|
||||
#include "esp_fast_prov_server_model.h"
|
||||
|
||||
#define TAG "BLE_MESH_WIFI_COEXIST_DEMO"
|
||||
#include "ble_mesh_demo_init.h"
|
||||
|
||||
extern struct _led_state led_state[3];
|
||||
extern struct k_delayed_work send_self_prov_node_addr_timer;
|
||||
@ -348,8 +343,8 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint
|
||||
}
|
||||
}
|
||||
|
||||
static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_BD_ADDR_LEN],
|
||||
esp_ble_addr_type_t addr_type, uint16_t oob_info,
|
||||
static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[BLE_MESH_ADDR_LEN],
|
||||
esp_ble_mesh_addr_type_t addr_type, uint16_t oob_info,
|
||||
uint8_t adv_type, esp_ble_mesh_prov_bearer_t bearer)
|
||||
{
|
||||
esp_ble_mesh_unprov_dev_add_t add_dev = {0};
|
||||
@ -370,7 +365,7 @@ static void example_recv_unprov_adv_pkt(uint8_t dev_uuid[16], uint8_t addr[ESP_B
|
||||
add_dev.oob_info = oob_info;
|
||||
add_dev.bearer = (uint8_t)bearer;
|
||||
memcpy(add_dev.uuid, dev_uuid, 16);
|
||||
memcpy(add_dev.addr, addr, ESP_BD_ADDR_LEN);
|
||||
memcpy(add_dev.addr, addr, BLE_MESH_ADDR_LEN);
|
||||
flag = ADD_DEV_RM_AFTER_PROV_FLAG | ADD_DEV_START_PROV_NOW_FLAG | ADD_DEV_FLUSHABLE_DEV_FLAG;
|
||||
err = esp_ble_mesh_provisioner_add_unprov_dev(&add_dev, flag);
|
||||
if (err != ESP_OK) {
|
||||
@ -745,9 +740,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
/* First two bytes of device uuid is compared with match value by Provisioner */
|
||||
memcpy(dev_uuid + 2, esp_bt_dev_get_address(), 6);
|
||||
|
||||
esp_ble_mesh_register_prov_callback(example_ble_mesh_provisioning_cb);
|
||||
esp_ble_mesh_register_custom_model_callback(example_ble_mesh_custom_model_cb);
|
||||
esp_ble_mesh_register_config_client_callback(example_ble_mesh_config_client_cb);
|
||||
@ -786,47 +778,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t bluetooth_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||
|
||||
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
ret = esp_bt_controller_init(&bt_cfg);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s initialize controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable controller failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bluedroid_init();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s init bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp_bluedroid_enable();
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "%s enable bluetooth failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
|
||||
static void initialize_console(void)
|
||||
@ -960,12 +911,21 @@ void app_main(void)
|
||||
return;
|
||||
}
|
||||
|
||||
err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = bluetooth_init();
|
||||
if (err) {
|
||||
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
ble_mesh_get_dev_uuid(dev_uuid);
|
||||
|
||||
/* Initialize the Bluetooth Mesh Subsystem */
|
||||
err = ble_mesh_init();
|
||||
if (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user