mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 11:17:20 +02:00
Merge branch 'feature/add_proxy_conn_and_disconn_event_v4.4' into 'release/v4.4'
ble_mesh: stack: Add proxy server connect and disconnect event (v4.4) See merge request espressif/esp-idf!16993
This commit is contained in:
@ -877,6 +877,8 @@ typedef enum {
|
|||||||
ESP_BLE_MESH_PROXY_CLIENT_SET_FILTER_TYPE_COMP_EVT, /*!< Proxy Client set filter type completion event */
|
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_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_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT, /*!< Proxy Client remove filter address completion event */
|
||||||
|
ESP_BLE_MESH_PROXY_SERVER_CONNECTED_EVT, /*!< Proxy Server establishes connection successfully event */
|
||||||
|
ESP_BLE_MESH_PROXY_SERVER_DISCONNECTED_EVT, /*!< Proxy Server terminates connection successfully event */
|
||||||
ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT, /*!< Local model subscribes group address 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_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 */
|
ESP_BLE_MESH_DEINIT_MESH_COMP_EVT, /*!< De-initialize BLE Mesh stack completion event */
|
||||||
@ -1459,6 +1461,19 @@ typedef union {
|
|||||||
uint8_t conn_handle; /*!< Proxy connection handle */
|
uint8_t conn_handle; /*!< Proxy connection handle */
|
||||||
uint16_t net_idx; /*!< Corresponding NetKey Index */
|
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 */
|
} proxy_client_remove_filter_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT */
|
||||||
|
/**
|
||||||
|
* @brief ESP_BLE_MESH_PROXY_SERVER_CONNECTED_EVT
|
||||||
|
*/
|
||||||
|
struct ble_mesh_proxy_server_connected_param {
|
||||||
|
uint8_t conn_handle; /*!< Proxy connection handle */
|
||||||
|
} proxy_server_connected; /*!< Event parameter of ESP_BLE_MESH_PROXY_SERVER_CONNECTED_EVT */
|
||||||
|
/**
|
||||||
|
* @brief ESP_BLE_MESH_PROXY_SERVER_DISCONNECTED_EVT
|
||||||
|
*/
|
||||||
|
struct ble_mesh_proxy_server_disconnected_param {
|
||||||
|
uint8_t conn_handle; /*!< Proxy connection handle */
|
||||||
|
uint8_t reason; /*!< Proxy disconnect reason */
|
||||||
|
} proxy_server_disconnected; /*!< Event parameter of ESP_BLE_MESH_PROXY_SERVER_DISCONNECTED_EVT */
|
||||||
/**
|
/**
|
||||||
* @brief ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT
|
* @brief ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT
|
||||||
*/
|
*/
|
||||||
|
@ -1002,6 +1002,41 @@ static void btc_ble_mesh_proxy_client_filter_status_recv_cb(uint8_t conn_handle,
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||||
|
|
||||||
|
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||||
|
static void btc_ble_mesh_proxy_server_connect_cb(uint8_t conn_handle)
|
||||||
|
{
|
||||||
|
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
|
||||||
|
|
||||||
|
if (conn_handle >= BLE_MESH_MAX_CONN) {
|
||||||
|
BT_ERR("%s, Invalid parameter", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BT_DBG("%s", __func__);
|
||||||
|
|
||||||
|
mesh_param.proxy_server_connected.conn_handle = conn_handle;
|
||||||
|
|
||||||
|
btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_SERVER_CONNECTED_EVT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btc_ble_mesh_proxy_server_disconnect_cb(uint8_t conn_handle, uint8_t reason)
|
||||||
|
{
|
||||||
|
esp_ble_mesh_prov_cb_param_t mesh_param = {0};
|
||||||
|
|
||||||
|
if (conn_handle >= BLE_MESH_MAX_CONN) {
|
||||||
|
BT_ERR("%s, Invalid parameter", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BT_DBG("%s", __func__);
|
||||||
|
|
||||||
|
mesh_param.proxy_server_disconnected.conn_handle = conn_handle;
|
||||||
|
mesh_param.proxy_server_disconnected.reason = reason;
|
||||||
|
|
||||||
|
btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_SERVER_DISCONNECTED_EVT);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||||
|
|
||||||
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
|
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
|
||||||
{
|
{
|
||||||
if (!bt_mesh_is_initialized()) {
|
if (!bt_mesh_is_initialized()) {
|
||||||
@ -1769,6 +1804,10 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
|
|||||||
bt_mesh_proxy_client_set_disconn_cb(btc_ble_mesh_proxy_client_disconnect_cb);
|
bt_mesh_proxy_client_set_disconn_cb(btc_ble_mesh_proxy_client_disconnect_cb);
|
||||||
bt_mesh_proxy_client_set_filter_status_cb(btc_ble_mesh_proxy_client_filter_status_recv_cb);
|
bt_mesh_proxy_client_set_filter_status_cb(btc_ble_mesh_proxy_client_filter_status_recv_cb);
|
||||||
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||||
|
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||||
|
bt_mesh_proxy_server_set_conn_cb(btc_ble_mesh_proxy_server_connect_cb);
|
||||||
|
bt_mesh_proxy_server_set_disconn_cb(btc_ble_mesh_proxy_server_disconnect_cb);
|
||||||
|
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||||
int err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_init.prov,
|
int err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_init.prov,
|
||||||
(struct bt_mesh_comp *)arg->mesh_init.comp);
|
(struct bt_mesh_comp *)arg->mesh_init.comp);
|
||||||
/* Give the semaphore when BLE Mesh initialization is finished. */
|
/* Give the semaphore when BLE Mesh initialization is finished. */
|
||||||
|
@ -539,7 +539,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
|
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
|
||||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL) {
|
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL &&
|
||||||
|
bt_mesh_gattc_info[i].wr_desc_done) {
|
||||||
len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn,
|
len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn,
|
||||||
notif_data, notif_len);
|
notif_data, notif_len);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
|
@ -159,6 +159,23 @@ static void proxy_sar_timeout(struct k_work *work)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||||
|
/**
|
||||||
|
* The following callbacks are used to notify proper information
|
||||||
|
* to the application layer.
|
||||||
|
*/
|
||||||
|
static proxy_server_connect_cb_t proxy_server_connect_cb;
|
||||||
|
static proxy_server_disconnect_cb_t proxy_server_disconnect_cb;
|
||||||
|
|
||||||
|
void bt_mesh_proxy_server_set_conn_cb(proxy_server_connect_cb_t cb)
|
||||||
|
{
|
||||||
|
proxy_server_connect_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bt_mesh_proxy_server_set_disconn_cb(proxy_server_disconnect_cb_t cb)
|
||||||
|
{
|
||||||
|
proxy_server_disconnect_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
/* Next subnet in queue to be advertised */
|
/* Next subnet in queue to be advertised */
|
||||||
static int next_idx;
|
static int next_idx;
|
||||||
|
|
||||||
@ -605,6 +622,10 @@ static void proxy_connected(struct bt_mesh_conn *conn, uint8_t err)
|
|||||||
client->filter_type = NONE;
|
client->filter_type = NONE;
|
||||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||||
(void)memset(client->filter, 0, sizeof(client->filter));
|
(void)memset(client->filter, 0, sizeof(client->filter));
|
||||||
|
|
||||||
|
if (proxy_server_connect_cb) {
|
||||||
|
proxy_server_connect_cb(conn->handle);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
net_buf_simple_reset(&client->buf);
|
net_buf_simple_reset(&client->buf);
|
||||||
}
|
}
|
||||||
@ -621,6 +642,11 @@ static void proxy_disconnected(struct bt_mesh_conn *conn, uint8_t reason)
|
|||||||
struct bt_mesh_proxy_client *client = &clients[i];
|
struct bt_mesh_proxy_client *client = &clients[i];
|
||||||
|
|
||||||
if (client->conn == conn) {
|
if (client->conn == conn) {
|
||||||
|
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||||
|
if (proxy_server_disconnect_cb) {
|
||||||
|
proxy_server_disconnect_cb(conn->handle, reason);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
||||||
client->filter_type == PROV) {
|
client->filter_type == PROV) {
|
||||||
bt_mesh_pb_gatt_close(conn);
|
bt_mesh_pb_gatt_close(conn);
|
||||||
|
@ -38,6 +38,9 @@ extern "C" {
|
|||||||
#define DEVICE_NAME_SIZE (BLE_MESH_GAP_ADV_MAX_LEN - 2)
|
#define DEVICE_NAME_SIZE (BLE_MESH_GAP_ADV_MAX_LEN - 2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef void (*proxy_server_connect_cb_t)(uint8_t conn_handle);
|
||||||
|
typedef void (*proxy_server_disconnect_cb_t)(uint8_t conn_handle, uint8_t reason);
|
||||||
|
|
||||||
int bt_mesh_set_device_name(const char *name);
|
int bt_mesh_set_device_name(const char *name);
|
||||||
|
|
||||||
int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, uint8_t type,
|
int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, uint8_t type,
|
||||||
@ -46,6 +49,9 @@ int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, uint8_t type,
|
|||||||
int bt_mesh_proxy_server_prov_enable(void);
|
int bt_mesh_proxy_server_prov_enable(void);
|
||||||
int bt_mesh_proxy_server_prov_disable(bool disconnect);
|
int bt_mesh_proxy_server_prov_disable(bool disconnect);
|
||||||
|
|
||||||
|
void bt_mesh_proxy_server_set_conn_cb(proxy_server_connect_cb_t cb);
|
||||||
|
void bt_mesh_proxy_server_set_disconn_cb(proxy_server_disconnect_cb_t cb);
|
||||||
|
|
||||||
int bt_mesh_proxy_server_gatt_enable(void);
|
int bt_mesh_proxy_server_gatt_enable(void);
|
||||||
int bt_mesh_proxy_server_gatt_disable(void);
|
int bt_mesh_proxy_server_gatt_disable(void);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user