Merge branch 'feat/ble_mesh_support_ble_scan_v4.2' into 'release/v4.2'

ble_mesh: stack: Add BLE scan callback when mesh is enabled (v4.2)

See merge request espressif/esp-idf!11963
This commit is contained in:
Island 2021-01-14 19:01:05 +08:00
commit 8911c29122
28 changed files with 989 additions and 427 deletions

View File

@ -340,6 +340,7 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c"
"esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c"
"esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c"
"esp_ble_mesh/btc/btc_ble_mesh_ble.c"
"esp_ble_mesh/btc/btc_ble_mesh_config_model.c"
"esp_ble_mesh/btc/btc_ble_mesh_generic_model.c"
"esp_ble_mesh/btc/btc_ble_mesh_health_model.c"
@ -391,6 +392,7 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/mesh_core/proxy_server.c"
"esp_ble_mesh/mesh_core/settings_uid.c"
"esp_ble_mesh/mesh_core/settings.c"
"esp_ble_mesh/mesh_core/scan.c"
"esp_ble_mesh/mesh_core/test.c"
"esp_ble_mesh/mesh_core/transport.c"
"esp_ble_mesh/mesh_models/common/device_property.c"

View File

@ -57,6 +57,7 @@
#endif
#if CONFIG_BLE_MESH
#include "btc_ble_mesh_ble.h"
#include "btc_ble_mesh_prov.h"
#include "btc_ble_mesh_health_model.h"
#include "btc_ble_mesh_config_model.h"
@ -158,6 +159,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
#if CONFIG_BLE_MESH_TIME_SCENE_SERVER
[BTC_PID_TIME_SCENE_SERVER] = {NULL, btc_ble_mesh_time_scene_server_cb_handler},
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
[BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
#endif /* #if CONFIG_BLE_MESH */
};

View File

@ -87,6 +87,7 @@ typedef enum {
BTC_PID_LIGHTING_SERVER,
BTC_PID_SENSOR_SERVER,
BTC_PID_TIME_SCENE_SERVER,
BTC_PID_BLE_MESH_BLE_COEX,
#endif /* CONFIG_BLE_MESH */
BTC_PID_NUM,
} btc_pid_t; //btc profile id

View File

@ -102,6 +102,35 @@ if BLE_MESH
If enabled, users can use the function esp_ble_mesh_deinit() to de-initialize
the whole BLE Mesh stack.
menu "BLE Mesh and BLE coexistence support"
config BLE_MESH_SUPPORT_BLE_ADV
bool "Support sending normal BLE advertising packets"
default n
help
When selected, users can send normal BLE advertising packets
with specific API.
if BLE_MESH_SUPPORT_BLE_ADV
config BLE_MESH_BLE_ADV_BUF_COUNT
int "Number of advertising buffers for BLE advertising packets"
default 3
range 1 255
help
Number of advertising buffers for BLE packets available.
endif # BLE_MESH_SUPPORT_BLE_ADV
config BLE_MESH_SUPPORT_BLE_SCAN
bool "Support scanning normal BLE advertising packets"
default n
help
When selected, users can register a callback and receive normal BLE
advertising packets in the application layer.
endmenu # BLE Mesh and BLE coexistence support
config BLE_MESH_FAST_PROV
bool "Enable BLE Mesh Fast Provisioning"
select BLE_MESH_NODE
@ -510,24 +539,6 @@ if BLE_MESH
SDU size is 60 bytes, which leaves 56 bytes for application layer data
using a 4-byte MIC, or 52 bytes using an 8-byte MIC.
config BLE_MESH_SUPPORT_BLE_ADV
bool "Support sending normal BLE advertising packets"
default n
help
When selected, users can send normal BLE advertising packets
with specific API.
if BLE_MESH_SUPPORT_BLE_ADV
config BLE_MESH_BLE_ADV_BUF_COUNT
int "Number of advertising buffers for BLE advertising packets"
default 3
range 1 255
help
Number of advertising buffers for BLE packets available.
endif # BLE_MESH_SUPPORT_BLE_ADV
config BLE_MESH_IVU_DIVIDER
int "Divider for IV Update state refresh timer"
default 4

View File

@ -1,4 +1,4 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
// Copyright 2017-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -15,19 +15,25 @@
#include <stdint.h>
#include <string.h>
#include "btc/btc_manage.h"
#include "esp_err.h"
#include "btc_ble_mesh_prov.h"
#include "esp_ble_mesh_defs.h"
#include "btc_ble_mesh_ble.h"
#include "esp_ble_mesh_ble_api.h"
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback)
{
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
return (btc_profile_cb_set(BTC_PID_BLE_MESH_BLE_COEX, callback) == 0 ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t *param,
const esp_ble_mesh_ble_adv_data_t *data)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_ble_mesh_ble_args_t arg = {0};
btc_msg_t msg = {0};
if (param == NULL) {
@ -37,21 +43,21 @@ esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_START_BLE_ADVERTISING;
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
msg.act = BTC_BLE_MESH_ACT_START_BLE_ADV;
memcpy(&arg.start_ble_advertising.param, param, sizeof(esp_ble_mesh_ble_adv_param_t));
memcpy(&arg.start_ble_adv.param, param, sizeof(esp_ble_mesh_ble_adv_param_t));
if (data) {
memcpy(&arg.start_ble_advertising.data, data, sizeof(esp_ble_mesh_ble_adv_data_t));
memcpy(&arg.start_ble_adv.data, data, sizeof(esp_ble_mesh_ble_adv_data_t));
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_stop_ble_advertising(uint8_t index)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_ble_mesh_ble_args_t arg = {0};
btc_msg_t msg = {0};
if (index >= CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT) {
@ -61,13 +67,44 @@ esp_err_t esp_ble_mesh_stop_ble_advertising(uint8_t index)
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_STOP_BLE_ADVERTISING;
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
msg.act = BTC_BLE_MESH_ACT_STOP_BLE_ADV;
arg.stop_ble_advertising.index = index;
arg.stop_ble_adv.index = index;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param)
{
btc_ble_mesh_ble_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
msg.act = BTC_BLE_MESH_ACT_START_BLE_SCAN;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
esp_err_t esp_ble_mesh_stop_ble_scanning(void)
{
btc_ble_mesh_ble_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
msg.act = BTC_BLE_MESH_ACT_STOP_BLE_SCAN;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */

View File

@ -1,4 +1,4 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
// Copyright 2017-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -21,6 +21,106 @@
extern "C" {
#endif
/** This enum value is the event of BLE operations */
typedef enum {
ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT, /*!< Start BLE advertising completion event */
ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT, /*!< Stop BLE advertising completion event */
ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT, /*!< Start BLE scanning completion event */
ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT, /*!< Stop BLE scanning completion event */
ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT, /*!< Scanning BLE advertising packets event */
ESP_BLE_MESH_BLE_EVT_MAX,
} esp_ble_mesh_ble_cb_event_t;
/** BLE operation callback parameters */
typedef union {
/**
* @brief ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of starting BLE advertising */
uint8_t index; /*!< Index of the BLE advertising */
} start_ble_advertising_comp; /*!< Event parameters of ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of stopping BLE advertising */
uint8_t index; /*!< Index of the BLE advertising */
} stop_ble_advertising_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of starting BLE scanning */
} start_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of stopping BLE scanning */
} stop_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
*/
struct {
uint8_t addr[6]; /*!< Device address */
uint8_t addr_type; /*!< Device address type */
uint8_t adv_type; /*!< Advertising data type */
uint8_t *data; /*!< Advertising data */
uint16_t length; /*!< Advertising data length */
int8_t rssi; /*!< RSSI of the advertising packet */
} scan_ble_adv_pkt; /*!< Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT */
} esp_ble_mesh_ble_cb_param_t;
/**
* @brief BLE scanning callback function type
*
* @param event: BLE scanning callback event type
* @param param: BLE scanning callback parameter
*/
typedef void (* esp_ble_mesh_ble_cb_t)(esp_ble_mesh_ble_cb_event_t event,
esp_ble_mesh_ble_cb_param_t *param);
/**
* @brief Register BLE scanning callback.
*
* @param[in] callback: Pointer to the BLE scaning callback function.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback);
/** Count for sending BLE advertising packet infinitely */
#define ESP_BLE_MESH_BLE_ADV_INFINITE 0xFFFF
/*!< This enum value is the priority of BLE advertising packet */
typedef enum {
ESP_BLE_MESH_BLE_ADV_PRIO_LOW,
ESP_BLE_MESH_BLE_ADV_PRIO_HIGH,
} esp_ble_mesh_ble_adv_priority_t;
/** Context of BLE advertising parameters. */
typedef struct {
uint16_t interval; /*!< BLE advertising interval */
uint8_t adv_type; /*!< BLE advertising type */
uint8_t own_addr_type; /*!< Own address type */
uint8_t peer_addr_type; /*!< Peer address type */
uint8_t peer_addr[BD_ADDR_LEN]; /*!< Peer address */
uint16_t duration; /*!< Duration is milliseconds */
uint16_t period; /*!< Period in milliseconds */
uint16_t count; /*!< Number of advertising duration */
uint8_t priority:2; /*!< Priority of BLE advertising packet */
} esp_ble_mesh_ble_adv_param_t;
/** Context of BLE advertising data. */
typedef struct {
uint8_t adv_data_len; /*!< Advertising data length */
uint8_t adv_data[31]; /*!< Advertising data */
uint8_t scan_rsp_data_len; /*!< Scan response data length */
uint8_t scan_rsp_data[31]; /*!< Scan response data */
} esp_ble_mesh_ble_adv_data_t;
/**
* @brief This function is called to start BLE advertising with the corresponding data
* and parameters while BLE Mesh is working at the same time.
@ -58,6 +158,31 @@ esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t
*/
esp_err_t esp_ble_mesh_stop_ble_advertising(uint8_t index);
/** Context of BLE scanning parameters. */
typedef struct {
uint32_t duration; /*!< Duration used to scan normal BLE advertising packets */
} esp_ble_mesh_ble_scan_param_t;
/**
* @brief This function is called to start scanning normal BLE advertising packets
* and notifying the packets to the application layer.
*
* @param[in] param: Pointer to the BLE scanning parameters
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param);
/**
* @brief This function is called to stop notifying normal BLE advertising packets
* to the application layer.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_stop_ble_scanning(void);
#ifdef __cplusplus
}
#endif

View File

@ -777,36 +777,6 @@ typedef enum {
PROXY_FILTER_BLACKLIST,
} esp_ble_mesh_proxy_filter_type_t;
/** Count for sending BLE advertising packet infinitely */
#define ESP_BLE_MESH_BLE_ADV_INFINITE 0xFFFF
/*!< This enum value is the priority of BLE advertising packet */
typedef enum {
ESP_BLE_MESH_BLE_ADV_PRIO_LOW,
ESP_BLE_MESH_BLE_ADV_PRIO_HIGH,
} esp_ble_mesh_ble_adv_priority_t;
/** Context of BLE advertising parameters. */
typedef struct {
uint16_t interval; /*!< BLE advertising interval */
uint8_t adv_type; /*!< BLE advertising type */
uint8_t own_addr_type; /*!< Own address type */
uint8_t peer_addr_type; /*!< Peer address type */
uint8_t peer_addr[BD_ADDR_LEN]; /*!< Peer address */
uint16_t duration; /*!< Duration is milliseconds */
uint16_t period; /*!< Period in milliseconds */
uint16_t count; /*!< Number of advertising duration */
uint8_t priority:2; /*!< Priority of BLE advertising packet */
} esp_ble_mesh_ble_adv_param_t;
/** Context of BLE advertising data. */
typedef struct {
uint8_t adv_data_len; /*!< Advertising data length */
uint8_t adv_data[31]; /*!< Advertising data */
uint8_t scan_rsp_data_len; /*!< Scan response data length */
uint8_t scan_rsp_data[31]; /*!< Scan response data */
} esp_ble_mesh_ble_adv_data_t;
/*!< Provisioner heartbeat filter type */
#define ESP_BLE_MESH_HEARTBEAT_FILTER_ACCEPTLIST 0x00
#define ESP_BLE_MESH_HEARTBEAT_FILTER_REJECTLIST 0x01
@ -902,8 +872,6 @@ typedef enum {
ESP_BLE_MESH_PROXY_CLIENT_SET_FILTER_TYPE_COMP_EVT, /*!< Proxy Client set filter type completion event */
ESP_BLE_MESH_PROXY_CLIENT_ADD_FILTER_ADDR_COMP_EVT, /*!< Proxy Client add filter address completion event */
ESP_BLE_MESH_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT, /*!< Proxy Client remove filter address completion event */
ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT, /*!< Start BLE advertising completion event */
ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT, /*!< Stop BLE advertising completion event */
ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT, /*!< Local model subscribes group address completion event */
ESP_BLE_MESH_MODEL_UNSUBSCRIBE_GROUP_ADDR_COMP_EVT, /*!< Local model unsubscribes group address completion event */
ESP_BLE_MESH_DEINIT_MESH_COMP_EVT, /*!< De-initialize BLE Mesh stack completion event */
@ -1486,20 +1454,6 @@ typedef union {
uint8_t conn_handle; /*!< Proxy connection handle */
uint16_t net_idx; /*!< Corresponding NetKey Index */
} proxy_client_remove_filter_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT */
/**
* @brief ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT
*/
struct ble_mesh_start_ble_advertising_comp_param {
int err_code; /*!< Indicate the result of starting BLE advertising */
uint8_t index; /*!< Index of the BLE advertising */
} start_ble_advertising_comp; /*!< Event parameter of ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT
*/
struct ble_mesh_stop_ble_advertising_comp_param {
int err_code; /*!< Indicate the result of stopping BLE advertising */
uint8_t index; /*!< Index of the BLE advertising */
} stop_ble_advertising_comp; /*!< Event parameter of ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT */
/**
* @brief ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT
*/

View File

@ -0,0 +1,203 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <string.h>
#include "btc_ble_mesh_ble.h"
#include "adv.h"
#include "scan.h"
#include "mesh_bearer_adapt.h"
#include "esp_ble_mesh_ble_api.h"
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_src)
{
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
esp_ble_mesh_ble_cb_param_t *p_dst_data = (esp_ble_mesh_ble_cb_param_t *)p_dst;
esp_ble_mesh_ble_cb_param_t *p_src_data = (esp_ble_mesh_ble_cb_param_t *)p_src;
if (!msg || !p_src_data || !p_dst_data) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
switch (msg->act) {
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
if (p_src_data->scan_ble_adv_pkt.data && p_src_data->scan_ble_adv_pkt.length) {
p_dst_data->scan_ble_adv_pkt.length = p_src_data->scan_ble_adv_pkt.length;
p_dst_data->scan_ble_adv_pkt.data = bt_mesh_calloc(p_src_data->scan_ble_adv_pkt.length);
if (p_dst_data->scan_ble_adv_pkt.data) {
memcpy(p_dst_data->scan_ble_adv_pkt.data, p_src_data->scan_ble_adv_pkt.data,
p_src_data->scan_ble_adv_pkt.length);
} else {
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
}
}
break;
default:
break;
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
}
static void btc_ble_mesh_ble_free_req_data(btc_msg_t *msg)
{
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
esp_ble_mesh_ble_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
arg = (esp_ble_mesh_ble_cb_param_t *)msg->arg;
switch (msg->act) {
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
if (arg->scan_ble_adv_pkt.data) {
bt_mesh_free(arg->scan_ble_adv_pkt.data);
}
break;
default:
break;
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
}
static void btc_ble_mesh_ble_callback(esp_ble_mesh_ble_cb_param_t *cb_params, uint8_t act)
{
btc_msg_t msg = {0};
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_BLE_MESH_BLE_COEX)) {
return;
}
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
msg.act = act;
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_ble_cb_param_t),
btc_ble_mesh_ble_copy_req_data);
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi)
{
esp_ble_mesh_ble_cb_param_t param = {0};
if (addr == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
memcpy(param.scan_ble_adv_pkt.addr, addr->val, sizeof(addr->val));
param.scan_ble_adv_pkt.addr_type = addr->type;
if (data && length) {
param.scan_ble_adv_pkt.data = data;
param.scan_ble_adv_pkt.length = length;
}
param.scan_ble_adv_pkt.adv_type = adv_type;
param.scan_ble_adv_pkt.rssi = rssi;
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT);
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_ble_cb_param_t param = {0};
btc_ble_mesh_ble_args_t *arg = NULL;
if (!msg || !msg->arg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
arg = (btc_ble_mesh_ble_args_t *)msg->arg;
switch (msg->act) {
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
case BTC_BLE_MESH_ACT_START_BLE_ADV: {
struct bt_mesh_ble_adv_param *set = (struct bt_mesh_ble_adv_param *)&arg->start_ble_adv.param;
struct bt_mesh_ble_adv_data *data = NULL;
if (arg->start_ble_adv.data.adv_data_len || arg->start_ble_adv.data.scan_rsp_data_len) {
data = (struct bt_mesh_ble_adv_data *)&arg->start_ble_adv.data;
}
param.start_ble_advertising_comp.err_code =
bt_mesh_start_ble_advertising(set, data, &param.start_ble_advertising_comp.index);
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT);
break;
}
case BTC_BLE_MESH_ACT_STOP_BLE_ADV:
param.stop_ble_advertising_comp.index = arg->stop_ble_adv.index;
param.stop_ble_advertising_comp.err_code =
bt_mesh_stop_ble_advertising(arg->stop_ble_adv.index);
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT);
break;
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
case BTC_BLE_MESH_ACT_START_BLE_SCAN:
param.start_ble_scan_comp.err_code =
bt_mesh_start_ble_scan((struct bt_mesh_ble_scan_param *)&arg->start_ble_scan.param);
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT);
break;
case BTC_BLE_MESH_ACT_STOP_BLE_SCAN:
param.stop_ble_scan_comp.err_code = bt_mesh_stop_ble_scan();
btc_ble_mesh_ble_callback(&param, ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT);
break;
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
default:
return;
}
}
static inline void btc_ble_mesh_ble_cb_to_app(esp_ble_mesh_ble_cb_event_t event,
esp_ble_mesh_ble_cb_param_t *param)
{
esp_ble_mesh_ble_cb_t btc_ble_mesh_cb =
(esp_ble_mesh_ble_cb_t)btc_profile_cb_get(BTC_PID_BLE_MESH_BLE_COEX);
if (btc_ble_mesh_cb) {
btc_ble_mesh_cb(event, param);
}
}
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_ble_cb_param_t *param = NULL;
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
param = (esp_ble_mesh_ble_cb_param_t *)msg->arg;
if (msg->act < ESP_BLE_MESH_BLE_EVT_MAX) {
btc_ble_mesh_ble_cb_to_app(msg->act, param);
} else {
BT_ERR("%s, Unknown act %d", __func__, msg->act);
}
btc_ble_mesh_ble_free_req_data(msg);
}
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */

View File

@ -2209,26 +2209,6 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
break;
}
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
case BTC_BLE_MESH_ACT_START_BLE_ADVERTISING: {
struct bt_mesh_ble_adv_param *set = (struct bt_mesh_ble_adv_param *)&arg->start_ble_advertising.param;
struct bt_mesh_ble_adv_data *data = NULL;
if (arg->start_ble_advertising.data.adv_data_len ||
arg->start_ble_advertising.data.scan_rsp_data_len) {
data = (struct bt_mesh_ble_adv_data *)&arg->start_ble_advertising.data;
}
act = ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT;
param.start_ble_advertising_comp.err_code =
bt_mesh_start_ble_advertising(set, data, &param.start_ble_advertising_comp.index);
break;
}
case BTC_BLE_MESH_ACT_STOP_BLE_ADVERTISING:
act = ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT;
param.stop_ble_advertising_comp.index = arg->stop_ble_advertising.index;
param.stop_ble_advertising_comp.err_code =
bt_mesh_stop_ble_advertising(arg->stop_ble_advertising.index);
break;
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
case BTC_BLE_MESH_ACT_MODEL_SUBSCRIBE_GROUP_ADDR:
act = ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT;
param.model_sub_group_addr_comp.element_addr = arg->model_sub_group_addr.element_addr;

View File

@ -0,0 +1,62 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _BTC_BLE_MESH_BLE_H_
#define _BTC_BLE_MESH_BLE_H_
#include <stdint.h>
#include "btc/btc_manage.h"
#include "mesh_bearer_adapt.h"
#include "esp_ble_mesh_ble_api.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef union {
struct {
esp_ble_mesh_ble_adv_param_t param;
esp_ble_mesh_ble_adv_data_t data;
} start_ble_adv;
struct {
uint8_t index;
} stop_ble_adv;
struct {
esp_ble_mesh_ble_scan_param_t param;
} start_ble_scan;
struct {
/* RFU */
} stop_ble_scan;
} btc_ble_mesh_ble_args_t;
typedef enum {
BTC_BLE_MESH_ACT_START_BLE_ADV,
BTC_BLE_MESH_ACT_STOP_BLE_ADV,
BTC_BLE_MESH_ACT_START_BLE_SCAN,
BTC_BLE_MESH_ACT_STOP_BLE_SCAN,
} btc_ble_mesh_ble_act_t;
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi);
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg);
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg);
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_BLE_H_ */

View File

@ -83,8 +83,6 @@ typedef enum {
BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE,
BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR,
BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR,
BTC_BLE_MESH_ACT_START_BLE_ADVERTISING,
BTC_BLE_MESH_ACT_STOP_BLE_ADVERTISING,
BTC_BLE_MESH_ACT_MODEL_SUBSCRIBE_GROUP_ADDR,
BTC_BLE_MESH_ACT_MODEL_UNSUBSCRIBE_GROUP_ADDR,
BTC_BLE_MESH_ACT_DEINIT_MESH,
@ -305,13 +303,6 @@ typedef union {
uint16_t addr_num;
uint16_t *addr;
} proxy_client_remove_filter_addr;
struct ble_mesh_start_ble_advertising_args {
esp_ble_mesh_ble_adv_param_t param;
esp_ble_mesh_ble_adv_data_t data;
} start_ble_advertising;
struct ble_mesh_stop_ble_advertising_args {
uint8_t index;
} stop_ble_advertising;
struct ble_mesh_model_sub_group_addr_args {
uint16_t element_addr;
uint16_t company_id;

View File

@ -45,6 +45,9 @@ extern "C" {
CONFIG_BLE_MESH_TIME_SCENE_SERVER | \
CONFIG_BLE_MESH_LIGHTING_SERVER)
#define CONFIG_BLE_MESH_BLE_COEX_SUPPORT (CONFIG_BLE_MESH_SUPPORT_BLE_ADV | \
CONFIG_BLE_MESH_SUPPORT_BLE_SCAN)
#ifdef __cplusplus
}
#endif

View File

@ -29,18 +29,12 @@
/* Convert from 0.625ms units to interval(ms) */
#define ADV_SCAN_INT(val) ((val) * 5 / 8)
/* Window and Interval are equal for continuous scanning */
#define MESH_SCAN_INTERVAL 0x20
#define MESH_SCAN_WINDOW 0x20
/* Pre-5.0 controllers enforce a minimum interval of 100ms
* whereas 5.0+ controllers can go down to 20ms.
*/
#define ADV_INT_DEFAULT_MS 100
#define ADV_INT_FAST_MS 20
static const bt_mesh_addr_t *dev_addr;
static const uint8_t adv_type[] = {
[BLE_MESH_ADV_PROV] = BLE_MESH_DATA_MESH_PROV,
[BLE_MESH_ADV_DATA] = BLE_MESH_DATA_MESH_MESSAGE,
@ -595,207 +589,6 @@ uint16_t bt_mesh_get_stored_relay_count(void)
}
#endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void)
{
return dev_addr;
}
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static bool adv_flags_valid(struct net_buf_simple *buf)
{
uint8_t flags = 0U;
if (buf->len != 1U) {
BT_DBG("Unexpected adv flags length %d", buf->len);
return false;
}
flags = net_buf_simple_pull_u8(buf);
BT_DBG("Received adv pkt with flags: 0x%02x", flags);
/* Flags context will not be checked currently */
((void) flags);
return true;
}
static bool adv_service_uuid_valid(struct net_buf_simple *buf, uint16_t *uuid)
{
if (buf->len != 2U) {
BT_DBG("Length not match mesh service uuid");
return false;
}
*uuid = net_buf_simple_pull_le16(buf);
BT_DBG("Received adv pkt with service UUID: %d", *uuid);
if (*uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
*uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROV_VAL &&
bt_mesh_is_provisioner_en() == false) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROXY_VAL &&
!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
return false;
}
return true;
}
#define BLE_MESH_PROV_SRV_DATA_LEN 0x12
#define BLE_MESH_PROXY_SRV_DATA_LEN1 0x09
#define BLE_MESH_PROXY_SRV_DATA_LEN2 0x11
static void handle_adv_service_data(struct net_buf_simple *buf,
const bt_mesh_addr_t *addr,
uint16_t uuid, int8_t rssi)
{
uint16_t type = 0U;
if (!buf || !addr) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
type = net_buf_simple_pull_le16(buf);
if (type != uuid) {
BT_DBG("Invalid Mesh Service Data UUID 0x%04x", type);
return;
}
switch (type) {
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
case BLE_MESH_UUID_MESH_PROV_VAL:
if (bt_mesh_is_provisioner_en()) {
if (buf->len != BLE_MESH_PROV_SRV_DATA_LEN) {
BT_WARN("Invalid Mesh Prov Service Data length %d", buf->len);
return;
}
BT_DBG("Start to handle Mesh Prov Service Data");
bt_mesh_provisioner_prov_adv_recv(buf, addr, rssi);
}
break;
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_UUID_MESH_PROXY_VAL:
if (buf->len != BLE_MESH_PROXY_SRV_DATA_LEN1 &&
buf->len != BLE_MESH_PROXY_SRV_DATA_LEN2) {
BT_WARN("Invalid Mesh Proxy Service Data length %d", buf->len);
return;
}
BT_DBG("Start to handle Mesh Proxy Service Data");
bt_mesh_proxy_client_gatt_adv_recv(buf, addr, rssi);
break;
#endif
default:
break;
}
}
#endif
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, int8_t rssi,
uint8_t adv_type, struct net_buf_simple *buf)
{
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
uint16_t uuid = 0U;
#endif
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
return;
}
BT_DBG("scan, len %u: %s", buf->len, bt_hex(buf->data, buf->len));
dev_addr = addr;
while (buf->len > 1) {
struct net_buf_simple_state state;
uint8_t len, type;
len = net_buf_simple_pull_u8(buf);
/* Check for early termination */
if (len == 0U) {
return;
}
if (len > buf->len) {
BT_WARN("AD malformed");
return;
}
net_buf_simple_save(buf, &state);
type = net_buf_simple_pull_u8(buf);
buf->len = len - 1;
#if 0
/* TODO: Check with BLE Mesh BQB test cases */
if ((type == BLE_MESH_DATA_MESH_PROV || type == BLE_MESH_DATA_MESH_MESSAGE ||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
BT_DBG("%s, ignore BLE Mesh packet (type 0x%02x) with adv_type 0x%02x",
__func__, type, adv_type);
return;
}
#endif
switch (type) {
case BLE_MESH_DATA_MESH_MESSAGE:
bt_mesh_net_recv(buf, rssi, BLE_MESH_NET_IF_ADV);
break;
#if CONFIG_BLE_MESH_PB_ADV
case BLE_MESH_DATA_MESH_PROV:
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node()) {
bt_mesh_pb_adv_recv(buf);
}
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
bt_mesh_provisioner_pb_adv_recv(buf);
}
break;
#endif /* CONFIG_BLE_MESH_PB_ADV */
case BLE_MESH_DATA_MESH_BEACON:
bt_mesh_beacon_recv(buf, rssi);
break;
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_DATA_FLAGS:
if (!adv_flags_valid(buf)) {
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
return;
}
break;
case BLE_MESH_DATA_UUID16_ALL:
if (!adv_service_uuid_valid(buf, &uuid)) {
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
return;
}
break;
case BLE_MESH_DATA_SVC_DATA16:
handle_adv_service_data(buf, addr, uuid, rssi);
break;
#endif
default:
break;
}
net_buf_simple_restore(buf, &state);
net_buf_simple_pull(buf, len);
}
return;
}
void bt_mesh_adv_init(void)
{
#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
@ -918,77 +711,6 @@ void bt_mesh_adv_deinit(void)
}
#endif /* CONFIG_BLE_MESH_DEINIT */
int bt_mesh_scan_enable(void)
{
int err = 0;
struct bt_mesh_scan_param scan_param = {
.type = BLE_MESH_SCAN_PASSIVE,
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
#endif
.interval = MESH_SCAN_INTERVAL,
.window = MESH_SCAN_WINDOW,
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
};
BT_DBG("%s", __func__);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
return err;
}
return 0;
}
int bt_mesh_scan_disable(void)
{
int err = 0;
BT_DBG("%s", __func__);
err = bt_le_scan_stop();
if (err && err != -EALREADY) {
BT_ERR("stopping scan failed (err %d)", err);
return err;
}
return 0;
}
#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
int bt_mesh_scan_with_wl_enable(void)
{
int err = 0;
struct bt_mesh_scan_param scan_param = {
.type = BLE_MESH_SCAN_PASSIVE,
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
#endif
.interval = MESH_SCAN_INTERVAL,
.window = MESH_SCAN_WINDOW,
.scan_fil_policy = BLE_MESH_SP_ADV_WL,
};
BT_DBG("%s", __func__);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
return err;
}
return 0;
}
#endif /* CONFIG_BLE_MESH_TEST_USE_WHITE_LIST */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
static struct bt_mesh_adv *ble_adv_alloc(int id)
{
@ -1159,7 +881,7 @@ int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
buf = bt_mesh_ble_adv_create(BLE_MESH_ADV_BLE, 0U, K_NO_WAIT);
if (!buf) {
BT_ERR("Unable to allocate buffer");
BT_ERR("No empty ble adv buffer");
return -ENOBUFS;
}

View File

@ -41,9 +41,6 @@ enum bt_mesh_adv_type {
BLE_MESH_ADV_BLE,
};
typedef void (*bt_mesh_adv_func_t)(struct net_buf *buf, uint16_t duration,
int err, void *user_data);
struct bt_mesh_adv {
const struct bt_mesh_send_cb *cb;
void *cb_data;
@ -78,8 +75,6 @@ void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool);
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data);
const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void);
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout);
@ -93,12 +88,6 @@ void bt_mesh_adv_update(void);
void bt_mesh_adv_init(void);
void bt_mesh_adv_deinit(void);
int bt_mesh_scan_enable(void);
int bt_mesh_scan_disable(void);
int bt_mesh_scan_with_wl_enable(void);
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
const struct bt_mesh_ble_adv_data *data, uint8_t *index);

View File

@ -284,31 +284,21 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
{
struct net_buf_simple buf = {0};
bt_mesh_addr_t addr = {0};
uint8_t adv_type = 0U;
int8_t rssi = 0;
BT_DBG("%s, event %d", __func__, event);
if (event == BTA_DM_INQ_RES_EVT) {
/* TODO: How to process scan response here? */
/* TODO: How to process scan response here? PS: p_data->inq_res.scan_rsp_len */
addr.type = p_data->inq_res.ble_addr_type;
memcpy(addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN);
rssi = p_data->inq_res.rssi;
adv_type = p_data->inq_res.ble_evt_type;
/* scan rsp len: p_data->inq_res.scan_rsp_len */
struct net_buf_simple *buf = bt_mesh_alloc_buf(p_data->inq_res.adv_data_len);
if (!buf) {
BT_ERR("%s, Out of memory", __func__);
return;
}
net_buf_simple_add_mem(buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
net_buf_simple_init_with_data(&buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
if (bt_mesh_scan_dev_found_cb != NULL) {
bt_mesh_scan_dev_found_cb(&addr, rssi, adv_type, buf);
if (bt_mesh_scan_dev_found_cb) {
bt_mesh_scan_dev_found_cb(&addr, p_data->inq_res.rssi, p_data->inq_res.ble_evt_type, &buf);
}
bt_mesh_free(buf);
} else if (event == BTA_DM_INQ_CMPL_EVT) {
BT_INFO("Scan completed, number of scan response %d", p_data->inq_cmpl.num_resps);
} else {

View File

@ -11,6 +11,7 @@
#include "crypto.h"
#include "adv.h"
#include "scan.h"
#include "mesh.h"
#include "transport.h"
#include "access.h"

View File

@ -11,6 +11,7 @@
#include <errno.h>
#include "adv.h"
#include "scan.h"
#include "prov.h"
#include "beacon.h"
#include "lpn.h"

View File

@ -13,6 +13,7 @@
#include "crypto.h"
#include "adv.h"
#include "scan.h"
#include "mesh.h"
#include "lpn.h"
#include "friend.h"

View File

@ -387,21 +387,17 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
#endif
switch (event->type) {
case BLE_GAP_EVENT_DISC:
desc = &event->disc;
case BLE_GAP_EVENT_DISC: {
struct net_buf_simple buf = {0};
struct net_buf_simple *buf = bt_mesh_alloc_buf(desc->length_data);
if (!buf) {
BT_ERR("%s, Out of memory", __func__);
return 0;
}
net_buf_simple_add_mem(buf, desc->data, desc->length_data);
desc = &event->disc;
net_buf_simple_init_with_data(&buf, desc->data, desc->length_data);
if (bt_mesh_scan_dev_found_cb) {
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, buf);
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, &buf);
}
bt_mesh_free(buf);
break;
}
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_GAP_EVENT_CONNECT:

View File

@ -17,6 +17,7 @@
#include "crypto.h"
#include "adv.h"
#include "scan.h"
#include "mesh.h"
#include "access.h"
#include "settings.h"

View File

@ -0,0 +1,367 @@
/* Bluetooth Mesh */
/*
* Copyright (c) 2017 Intel Corporation
* Additional Copyright (c) 2020 Espressif Systems (Shanghai) PTE LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include "btc_ble_mesh_ble.h"
#include "mesh_config.h"
#include "mesh_trace.h"
#include "mesh_buf.h"
#include "mesh_uuid.h"
#include "scan.h"
#include "beacon.h"
#include "net.h"
#include "prov.h"
#include "proxy_client.h"
#include "proxy_server.h"
#include "provisioner_prov.h"
#include "mesh_bearer_adapt.h"
/* Scan Window and Interval are equal for continuous scanning */
#define SCAN_INTERVAL 0x20
#define SCAN_WINDOW 0x20
#define PROV_SVC_DATA_LEN 0x12
#define PROXY_SVC_DATA_LEN_NET_ID 0x09
#define PROXY_SVC_DATA_LEN_NODE_ID 0x11
#if CONFIG_BLE_MESH_PROVISIONER
static const bt_mesh_addr_t *unprov_dev_addr;
const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void)
{
return unprov_dev_addr;
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static bool adv_flags_valid(struct net_buf_simple *buf)
{
uint8_t flags = 0U;
if (buf->len != 1U) {
BT_DBG("Unexpected adv flags length %d", buf->len);
return false;
}
flags = net_buf_simple_pull_u8(buf);
BT_DBG("Received adv pkt with flags: 0x%02x", flags);
/* Flags context will not be checked currently */
ARG_UNUSED(flags);
return true;
}
static bool adv_service_uuid_valid(struct net_buf_simple *buf, uint16_t *uuid)
{
if (buf->len != 2U) {
BT_DBG("Length not match mesh service uuid");
return false;
}
*uuid = net_buf_simple_pull_le16(buf);
BT_DBG("Received adv pkt with service UUID: %d", *uuid);
if (*uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
*uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROV_VAL &&
bt_mesh_is_provisioner_en() == false) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROXY_VAL &&
!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
return false;
}
return true;
}
static void handle_adv_service_data(struct net_buf_simple *buf,
const bt_mesh_addr_t *addr,
uint16_t uuid, int8_t rssi)
{
uint16_t type = 0U;
if (!buf || !addr) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
type = net_buf_simple_pull_le16(buf);
if (type != uuid) {
BT_DBG("Invalid Mesh Service Data UUID 0x%04x", type);
return;
}
switch (type) {
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
case BLE_MESH_UUID_MESH_PROV_VAL:
if (bt_mesh_is_provisioner_en()) {
if (buf->len != PROV_SVC_DATA_LEN) {
BT_WARN("Invalid Mesh Prov Service Data length %d", buf->len);
return;
}
BT_DBG("Start to handle Mesh Prov Service Data");
bt_mesh_provisioner_prov_adv_recv(buf, addr, rssi);
}
break;
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_UUID_MESH_PROXY_VAL:
if (buf->len != PROXY_SVC_DATA_LEN_NET_ID &&
buf->len != PROXY_SVC_DATA_LEN_NODE_ID) {
BT_WARN("Invalid Mesh Proxy Service Data length %d", buf->len);
return;
}
BT_DBG("Start to handle Mesh Proxy Service Data");
bt_mesh_proxy_client_gatt_adv_recv(buf, addr, rssi);
break;
#endif
default:
break;
}
}
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
static bool ble_scan_en;
int bt_mesh_start_ble_scan(struct bt_mesh_ble_scan_param *param)
{
if (ble_scan_en == true) {
BT_WARN("%s, Already", __func__);
return -EALREADY;
}
ble_scan_en = true;
return 0;
}
int bt_mesh_stop_ble_scan(void)
{
if (ble_scan_en == false) {
BT_WARN("%s, Already", __func__);
return -EALREADY;
}
ble_scan_en = false;
return 0;
}
static void inline callback_ble_adv_pkt(const bt_mesh_addr_t *addr,
uint8_t adv_type, uint8_t data[],
uint16_t length, int8_t rssi)
{
if (ble_scan_en) {
bt_mesh_ble_scan_cb_evt_to_btc(addr, adv_type, data, length, rssi);
}
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
int8_t rssi, uint8_t adv_type,
struct net_buf_simple *buf)
{
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
uint16_t uuid = 0U;
#endif
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
uint8_t *adv_data = buf->data;
uint16_t adv_len = buf->len;
#endif
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
return;
}
BT_DBG("scan, len %u: %s", buf->len, bt_hex(buf->data, buf->len));
#if CONFIG_BLE_MESH_PROVISIONER
unprov_dev_addr = addr;
#endif
while (buf->len > 1) {
struct net_buf_simple_state state;
uint8_t len, type;
len = net_buf_simple_pull_u8(buf);
/* Check for early termination */
if (len == 0U) {
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
return;
}
if (len > buf->len) {
BT_DBG("AD malformed");
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
return;
}
net_buf_simple_save(buf, &state);
type = net_buf_simple_pull_u8(buf);
buf->len = len - 1;
#if 0
/* TODO: Check with BLE Mesh BQB test cases */
if ((type == BLE_MESH_DATA_MESH_PROV || type == BLE_MESH_DATA_MESH_MESSAGE ||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
BT_DBG("Ignore mesh packet (type 0x%02x) with adv_type 0x%02x", type, adv_type);
return;
}
#endif
switch (type) {
case BLE_MESH_DATA_MESH_MESSAGE:
bt_mesh_net_recv(buf, rssi, BLE_MESH_NET_IF_ADV);
break;
#if CONFIG_BLE_MESH_PB_ADV
case BLE_MESH_DATA_MESH_PROV:
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node()) {
bt_mesh_pb_adv_recv(buf);
}
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
bt_mesh_provisioner_pb_adv_recv(buf);
}
break;
#endif /* CONFIG_BLE_MESH_PB_ADV */
case BLE_MESH_DATA_MESH_BEACON:
bt_mesh_beacon_recv(buf, rssi);
break;
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_DATA_FLAGS:
if (!adv_flags_valid(buf)) {
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
return;
}
break;
case BLE_MESH_DATA_UUID16_ALL:
if (!adv_service_uuid_valid(buf, &uuid)) {
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
return;
}
break;
case BLE_MESH_DATA_SVC_DATA16:
handle_adv_service_data(buf, addr, uuid, rssi);
break;
#endif
default:
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
return;
}
net_buf_simple_restore(buf, &state);
net_buf_simple_pull(buf, len);
}
}
int bt_mesh_scan_enable(void)
{
int err = 0;
struct bt_mesh_scan_param scan_param = {
.type = BLE_MESH_SCAN_PASSIVE,
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
#endif
.interval = SCAN_INTERVAL,
.window = SCAN_WINDOW,
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
};
BT_DBG("%s", __func__);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
return err;
}
return 0;
}
int bt_mesh_scan_disable(void)
{
int err = 0;
BT_DBG("%s", __func__);
err = bt_le_scan_stop();
if (err && err != -EALREADY) {
BT_ERR("stopping scan failed (err %d)", err);
return err;
}
return 0;
}
#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
int bt_mesh_scan_with_wl_enable(void)
{
int err = 0;
struct bt_mesh_scan_param scan_param = {
.type = BLE_MESH_SCAN_PASSIVE,
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
#endif
.interval = SCAN_INTERVAL,
.window = SCAN_WINDOW,
.scan_fil_policy = BLE_MESH_SP_ADV_WL,
};
BT_DBG("%s", __func__);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
return err;
}
return 0;
}
#endif /* CONFIG_BLE_MESH_TEST_USE_WHITE_LIST */

View File

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

View File

@ -11,6 +11,7 @@
#include <errno.h>
#include "adv.h"
#include "scan.h"
#include "mesh.h"
#include "test.h"
#include "crypto.h"

View File

@ -0,0 +1,17 @@
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_MODEM_SLEEP=n
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_SUPPORT_BLE_ADV=y
CONFIG_BLE_MESH_SUPPORT_BLE_SCAN=y
CONFIG_BLE_MESH_FAST_PROV=y
CONFIG_BLE_MESH_PB_GATT=y
CONFIG_BLE_MESH_SETTINGS=y
CONFIG_BLE_MESH_CFG_CLI=y

View File

@ -0,0 +1,16 @@
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_MODEM_SLEEP=n
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_SUPPORT_BLE_ADV=y
CONFIG_BLE_MESH_NODE=y
CONFIG_BLE_MESH_PB_GATT=y
CONFIG_BLE_MESH_FRIEND=y
CONFIG_BLE_MESH_SETTINGS=y

View File

@ -0,0 +1,16 @@
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_MODEM_SLEEP=n
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_SUPPORT_BLE_SCAN=y
CONFIG_BLE_MESH_NODE=y
CONFIG_BLE_MESH_PB_GATT=y
CONFIG_BLE_MESH_FRIEND=y
CONFIG_BLE_MESH_SETTINGS=y

View File

@ -0,0 +1,16 @@
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_MODEM_SLEEP=n
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_SUPPORT_BLE_ADV=y
CONFIG_BLE_MESH_PROVISIONER=y
CONFIG_BLE_MESH_PB_GATT=y
CONFIG_BLE_MESH_SETTINGS=y
CONFIG_BLE_MESH_CFG_CLI=y
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y

View File

@ -0,0 +1,16 @@
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_MODEM_SLEEP=n
CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE=y
CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN=y
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
CONFIG_BLE_MESH=y
CONFIG_BLE_MESH_SUPPORT_BLE_SCAN=y
CONFIG_BLE_MESH_PROVISIONER=y
CONFIG_BLE_MESH_PB_GATT=y
CONFIG_BLE_MESH_SETTINGS=y
CONFIG_BLE_MESH_CFG_CLI=y
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y