mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-08 02:00:06 +00:00
nimble/mesh: Improve proxy handling when using BLE_EXT_ADV
When using multiadvertising feature, mesh can more precisly say when remote connects to the proxy server. It is valuable when Node is using additional advertising instances for other purposes than mesh.
This commit is contained in:
@@ -206,6 +206,20 @@ static inline struct os_mbuf * NET_BUF_SIMPLE(uint16_t size)
|
||||
#define K_NO_WAIT (0)
|
||||
#define K_FOREVER (-1)
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
#define BT_MESH_ADV_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES))
|
||||
|
||||
#if MYNEWT_VAL(BLE_MESH_PROXY)
|
||||
/* Note that BLE_MULTI_ADV_INSTANCES contains number of additional instances.
|
||||
* Instance 0 is always there
|
||||
*/
|
||||
#if MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) < 1
|
||||
#error "Mesh needs at least BLE_MULTI_ADV_INSTANCES set to 1"
|
||||
#endif
|
||||
#define BT_MESH_ADV_GATT_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) - 1)
|
||||
#endif /* BLE_MESH_PROXY */
|
||||
#endif /* BLE_EXT_ADV */
|
||||
|
||||
/* This is by purpose */
|
||||
static inline void net_buf_simple_init(struct os_mbuf *buf,
|
||||
size_t reserve_head)
|
||||
|
||||
@@ -29,20 +29,6 @@
|
||||
|
||||
#define BT_DBG_ENABLED (MYNEWT_VAL(BLE_MESH_DEBUG))
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
#define BT_MESH_ADV_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES))
|
||||
|
||||
#if MYNEWT_VAL(BLE_MESH_PROXY)
|
||||
/* Note that BLE_MULTI_ADV_INSTANCES contains number of additional instances.
|
||||
* Instance 0 is always there
|
||||
*/
|
||||
#if MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) < 1
|
||||
#error "Mesh needs at least BLE_MULTI_ADV_INSTANCES set to 1"
|
||||
#endif
|
||||
#define BT_MESH_ADV_GATT_INST (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) - 1)
|
||||
#endif /* BLE_MESH_PROXY */
|
||||
#endif /* BLE_EXT_ADV */
|
||||
|
||||
extern u8_t g_mesh_addr_type;
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
|
||||
@@ -654,10 +654,7 @@ static void proxy_connected(uint16_t conn_handle)
|
||||
static void proxy_disconnected(uint16_t conn_handle, int reason)
|
||||
{
|
||||
int i;
|
||||
|
||||
BT_INFO("conn_handle %d reason %d", conn_handle, reason);
|
||||
|
||||
conn_count--;
|
||||
bool disconnected = false;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(clients); i++) {
|
||||
struct bt_mesh_proxy_client *client = &clients[i];
|
||||
@@ -670,11 +667,16 @@ static void proxy_disconnected(uint16_t conn_handle, int reason)
|
||||
|
||||
k_delayed_work_cancel(&client->sar_timer);
|
||||
client->conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||
conn_count--;
|
||||
disconnected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bt_mesh_adv_update();
|
||||
if (disconnected) {
|
||||
BT_INFO("conn_handle %d reason %d", conn_handle, reason);
|
||||
bt_mesh_adv_update();
|
||||
}
|
||||
}
|
||||
|
||||
struct os_mbuf *bt_mesh_proxy_get_buf(void)
|
||||
@@ -1353,12 +1355,39 @@ void bt_mesh_proxy_adv_stop(void)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ble_mesh_proxy_gap_event(struct ble_gap_event *event, void *arg)
|
||||
static void ble_mesh_handle_connect(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
/* When EXT ADV is enabled then mesh proxy is connected
|
||||
* when proxy advertising instance is completed.
|
||||
* Therefore no need to handle BLE_GAP_EVENT_CONNECT
|
||||
*/
|
||||
if (event->type == BLE_GAP_EVENT_ADV_COMPLETE) {
|
||||
/* Reason 0 means advertising has been completed because
|
||||
* connection has been established
|
||||
*/
|
||||
if (event->adv_complete.reason != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->adv_complete.instance != BT_MESH_ADV_GATT_INST) {
|
||||
return;
|
||||
}
|
||||
|
||||
proxy_connected(event->adv_complete.conn_handle);
|
||||
}
|
||||
#else
|
||||
if (event->type == BLE_GAP_EVENT_CONNECT) {
|
||||
proxy_connected(event->connect.conn_handle);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int ble_mesh_proxy_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
if ((event->type == BLE_GAP_EVENT_CONNECT) ||
|
||||
(event->type == BLE_GAP_EVENT_ADV_COMPLETE)) {
|
||||
ble_mesh_handle_connect(event, arg);
|
||||
} else if (event->type == BLE_GAP_EVENT_DISCONNECT) {
|
||||
proxy_disconnected(event->disconnect.conn.conn_handle,
|
||||
event->disconnect.reason);
|
||||
|
||||
Reference in New Issue
Block a user