You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/28 00:30:26 UTC

[GitHub] foldl closed pull request #273: 0 is a possible value for conn_handle.

foldl closed pull request #273: 0 is a possible value for conn_handle.
URL: https://github.com/apache/mynewt-nimble/pull/273
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/mesh/src/mesh_priv.h b/nimble/host/mesh/src/mesh_priv.h
index 0a26c903..a5c3f98b 100644
--- a/nimble/host/mesh/src/mesh_priv.h
+++ b/nimble/host/mesh/src/mesh_priv.h
@@ -33,6 +33,9 @@ struct bt_mesh_net;
 #define OP_LIGHT_LIGHTNESS_SET		BT_MESH_MODEL_OP_2(0x82, 0x4c)
 #define OP_LIGHT_LIGHTNESS_SET_UNACK	BT_MESH_MODEL_OP_2(0x82, 0x4d)
 
+#define INVALID_CONN_HANDLE           (0xFFFFu)
+#define IS_VALID_CONN_HANDLE(handle)  ((handle) != INVALID_CONN_HANDLE)
+
 bool bt_mesh_is_provisioned(void);
 
 #endif
diff --git a/nimble/host/mesh/src/prov.c b/nimble/host/mesh/src/prov.c
index 94eb6eba..01e9c8dc 100644
--- a/nimble/host/mesh/src/prov.c
+++ b/nimble/host/mesh/src/prov.c
@@ -176,7 +176,13 @@ static struct os_mbuf *rx_buf;
 
 #define PROV_BUF(len) NET_BUF_SIMPLE(PROV_BUF_HEADROOM + len)
 
-static struct prov_link link;
+static struct prov_link link =
+	{
+#if (MYNEWT_VAL(BLE_MESH_PB_GATT))
+		.conn_handle = INVALID_CONN_HANDLE,
+#endif
+		0
+	};
 
 static const struct bt_mesh_prov *prov;
 
@@ -245,6 +251,7 @@ static void reset_link(void)
 	}
 
 #if (MYNEWT_VAL(BLE_MESH_PB_GATT))
+	link.conn_handle = INVALID_CONN_HANDLE;
 	link.rx.buf = bt_mesh_proxy_get_buf();
 #else
 	net_buf_simple_init(rx_buf, 0);
@@ -449,7 +456,7 @@ static int prov_send_adv(struct os_mbuf *msg)
 #if (MYNEWT_VAL(BLE_MESH_PB_GATT))
 static int prov_send_gatt(struct os_mbuf *msg)
 {
-	if (!link.conn_handle) {
+	if (!IS_VALID_CONN_HANDLE(link.conn_handle)) {
 		BT_ERR("No connection handle!?");
 		return -ENOTCONN;
 	}
@@ -461,7 +468,7 @@ static int prov_send_gatt(struct os_mbuf *msg)
 static inline int prov_send(struct os_mbuf *buf)
 {
 #if (MYNEWT_VAL(BLE_MESH_PB_GATT))
-	if (link.conn_handle) {
+	if (IS_VALID_CONN_HANDLE(link.conn_handle)) {
 		return prov_send_gatt(buf);
 	}
 #endif
@@ -1011,7 +1018,7 @@ static void prov_random(const u8_t *data)
 static inline bool is_pb_gatt(void)
 {
 #if MYNEWT_VAL(BLE_MESH_PB_GATT)
-	return !!link.conn_handle;
+	return IS_VALID_CONN_HANDLE(link.conn_handle);
 #else
 	return false;
 #endif
@@ -1130,7 +1137,7 @@ static const struct {
 static void close_link(u8_t err, u8_t reason)
 {
 #if (MYNEWT_VAL(BLE_MESH_PB_GATT))
-	if (link.conn_handle) {
+	if (IS_VALID_CONN_HANDLE(link.conn_handle)) {
 		bt_mesh_pb_gatt_close(link.conn_handle);
 		return;
 	}
@@ -1389,7 +1396,7 @@ static void gen_prov_start(struct prov_rx *rx, struct os_mbuf *buf)
 		gen_prov_ack_send(rx->xact_id);
 		return;
 	}
-	
+
 	trailing_space = OS_MBUF_TRAILINGSPACE(link.rx.buf);
 
 	link.rx.buf->om_len = net_buf_simple_pull_be16(buf);
@@ -1572,6 +1579,8 @@ int bt_mesh_pb_gatt_close(uint16_t conn_handle)
 		atomic_set_bit(link.flags, LOCAL_PUB_KEY);
 	}
 
+	link.conn_handle = INVALID_CONN_HANDLE;
+
 	return 0;
 }
 #endif /* MYNEWT_VAL(BLE_MESH_PB_GATT) */
diff --git a/nimble/host/mesh/src/proxy.c b/nimble/host/mesh/src/proxy.c
index 03cd081b..cdde8dd3 100644
--- a/nimble/host/mesh/src/proxy.c
+++ b/nimble/host/mesh/src/proxy.c
@@ -417,7 +417,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(clients); i++) {
-		if (clients[i].conn_handle) {
+		if (IS_VALID_CONN_HANDLE(clients[i].conn_handle)) {
 			beacon_send(clients[i].conn_handle, sub);
 		}
 	}
@@ -607,7 +607,7 @@ static void proxy_connected(uint16_t conn_handle)
 	}
 
 	for (client = NULL, i = 0; i < ARRAY_SIZE(clients); i++) {
-		if (!clients[i].conn_handle) {
+		if (!IS_VALID_CONN_HANDLE(clients[i].conn_handle)) {
 			client = &clients[i];
 			break;
 		}
@@ -641,7 +641,7 @@ static void proxy_disconnected(uint16_t conn_handle, int reason)
 				bt_mesh_pb_gatt_close(conn_handle);
 			}
 
-			client->conn_handle = 0;
+			client->conn_handle = INVALID_CONN_HANDLE;
 			break;
 		}
 	}
@@ -693,7 +693,7 @@ int bt_mesh_proxy_prov_enable(void)
 	prov_fast_adv = true;
 
 	for (i = 0; i < ARRAY_SIZE(clients); i++) {
-		if (clients[i].conn_handle) {
+		if (IS_VALID_CONN_HANDLE(clients[i].conn_handle)) {
 			clients[i].filter_type = PROV;
 		}
 	}
@@ -765,7 +765,7 @@ int bt_mesh_proxy_gatt_enable(void)
 	gatt_svc = MESH_GATT_PROXY;
 
 	for (i = 0; i < ARRAY_SIZE(clients); i++) {
-		if (clients[i].conn_handle) {
+		if (IS_VALID_CONN_HANDLE(clients[i].conn_handle)) {
 			clients[i].filter_type = WHITELIST;
 		}
 	}
@@ -877,7 +877,7 @@ bool bt_mesh_proxy_relay(struct os_mbuf *buf, u16_t dst)
 		struct bt_mesh_proxy_client *client = &clients[i];
 		struct os_mbuf *msg;
 
-		if (!client->conn_handle) {
+		if (!IS_VALID_CONN_HANDLE(client->conn_handle)) {
 			continue;
 		}
 
@@ -1383,6 +1383,7 @@ int bt_mesh_proxy_init(void)
 		k_work_init(&clients[i].send_beacons, proxy_send_beacons);
 #endif
 		clients[i].buf = NET_BUF_SIMPLE(CLIENT_BUF_SIZE);
+		clients[i].conn_handle = INVALID_CONN_HANDLE;
 	}
 
 	resolve_svc_handles();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services