mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ble_mesh: stack: Add proxy server connect and disconnect event
This commit is contained in:
parent
34a610c2c7
commit
c49b5b2409
@ -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_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_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_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 */
|
||||
@ -1459,6 +1461,19 @@ 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_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
|
||||
*/
|
||||
|
@ -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 */
|
||||
|
||||
#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)
|
||||
{
|
||||
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_filter_status_cb(btc_ble_mesh_proxy_client_filter_status_recv_cb);
|
||||
#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,
|
||||
(struct bt_mesh_comp *)arg->mesh_init.comp);
|
||||
/* Give the semaphore when BLE Mesh initialization is finished. */
|
||||
|
@ -159,6 +159,23 @@ static void proxy_sar_timeout(struct k_work *work)
|
||||
}
|
||||
|
||||
#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 */
|
||||
static int next_idx;
|
||||
|
||||
@ -605,6 +622,10 @@ static void proxy_connected(struct bt_mesh_conn *conn, uint8_t err)
|
||||
client->filter_type = NONE;
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
||||
(void)memset(client->filter, 0, sizeof(client->filter));
|
||||
|
||||
if (proxy_server_connect_cb) {
|
||||
proxy_server_connect_cb(conn->handle);
|
||||
}
|
||||
#endif
|
||||
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];
|
||||
|
||||
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) &&
|
||||
client->filter_type == PROV) {
|
||||
bt_mesh_pb_gatt_close(conn);
|
||||
|
@ -38,6 +38,9 @@ extern "C" {
|
||||
#define DEVICE_NAME_SIZE (BLE_MESH_GAP_ADV_MAX_LEN - 2)
|
||||
#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_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_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_disable(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user