You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2022/04/19 14:07:53 UTC

[mynewt-nimble] branch master updated: host/mesh: fix clients array indexing in proxy_srv

This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 534afc8c host/mesh: fix clients array indexing in proxy_srv
534afc8c is described below

commit 534afc8c481619a54b465da2043c86403ad369b7
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Tue Apr 19 12:22:25 2022 +0200

    host/mesh: fix clients array indexing in proxy_srv
    
    In proxy_srv clients were indexed using wrong handle values. Now each
    client has its own handle that is always initialized and is not
    connected with connection handle.
---
 nimble/host/mesh/src/proxy_msg.h |  1 +
 nimble/host/mesh/src/proxy_srv.c | 28 ++++++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/nimble/host/mesh/src/proxy_msg.h b/nimble/host/mesh/src/proxy_msg.h
index 349ebcdf..dabe7e80 100644
--- a/nimble/host/mesh/src/proxy_msg.h
+++ b/nimble/host/mesh/src/proxy_msg.h
@@ -45,6 +45,7 @@ struct bt_mesh_proxy_role {
 
 struct bt_mesh_proxy_client {
 	struct bt_mesh_proxy_role *cli;
+	uint16_t conn_handle;
 	uint16_t filter[MYNEWT_VAL(BLE_MESH_PROXY_FILTER_SIZE)];
 	enum __packed {
 		NONE,
diff --git a/nimble/host/mesh/src/proxy_srv.c b/nimble/host/mesh/src/proxy_srv.c
index f26a079c..65a5af78 100644
--- a/nimble/host/mesh/src/proxy_srv.c
+++ b/nimble/host/mesh/src/proxy_srv.c
@@ -62,7 +62,27 @@ static int conn_count;
 
 struct bt_mesh_proxy_client *find_client(uint16_t conn_handle)
 {
-	return &clients[conn_handle];
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(clients); i++) {
+		if (clients[i].conn_handle == conn_handle) {
+			return &clients[i];
+		}
+	}
+	return NULL;
+}
+
+static struct bt_mesh_proxy_client *get_client(uint16_t conn_handle)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(clients); i++) {
+		if (clients[i].conn_handle == 0xffff) {
+			clients[i].conn_handle = conn_handle;
+			return &clients[i];
+		}
+	}
+	return NULL;
 }
 
 /* Next subnet in queue to be advertised */
@@ -811,7 +831,8 @@ static void gatt_connected(uint16_t conn_handle)
 
 	conn_count++;
 
-	client = find_client(conn_handle);
+	client = get_client(conn_handle);
+	assert(client);
 
 	client->filter_type = NONE;
 	(void)memset(client->filter, 0, sizeof(client->filter));
@@ -844,6 +865,8 @@ static void gatt_disconnected(struct ble_gap_conn_desc conn, uint8_t reason)
 		bt_mesh_proxy_role_cleanup(client->cli);
 		client->cli = NULL;
 	}
+
+	client->conn_handle = 0xffff;
 }
 
 void notify_complete(void)
@@ -970,6 +993,7 @@ int bt_mesh_proxy_init(void)
 #if (MYNEWT_VAL(BLE_MESH_GATT_PROXY))
 		k_work_init(&clients[i].send_beacons, proxy_send_beacons);
 #endif
+		clients[i].conn_handle = 0xffff;
 	}
 
 	resolve_svc_handles();