From 492f02b67cc2cd7d1779cc6a064ee1757e8d53e9 Mon Sep 17 00:00:00 2001 From: Roshan Date: Tue, 12 Dec 2023 14:37:08 +0530 Subject: [PATCH] nimble/gatts: Modify client supported features READ --- nimble/host/include/host/ble_gatt.h | 19 +++++++++++++ nimble/host/services/gatt/src/ble_svc_gatt.c | 10 +++++-- nimble/host/src/ble_gatts.c | 29 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/nimble/host/include/host/ble_gatt.h b/nimble/host/include/host/ble_gatt.h index cd17cc26c0..0f811e7330 100644 --- a/nimble/host/include/host/ble_gatt.h +++ b/nimble/host/include/host/ble_gatt.h @@ -1096,6 +1096,25 @@ int ble_gatts_start(void); int ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om); +/** + * Gets Client Supported Features for specified connection. + * + * @param conn_handle Connection handle identifying connection for + * which Client Supported Features should be saved + * @param out_supported_feat Client supported features to be returned. + * + * @return 0 on success; + * BLE_HS_ENOTCONN if no matching connection + * was found + * BLE_HS_EINVAL if supplied buffer is empty or + * if any Client Supported Feature was + * attempted to be disabled. + * A BLE host core return code on unexpected + * error. + * + */ +int ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat, uint8_t len); + #ifdef __cplusplus } #endif diff --git a/nimble/host/services/gatt/src/ble_svc_gatt.c b/nimble/host/services/gatt/src/ble_svc_gatt.c index 5dcc4fa29c..d3262e17bc 100644 --- a/nimble/host/services/gatt/src/ble_svc_gatt.c +++ b/nimble/host/services/gatt/src/ble_svc_gatt.c @@ -100,10 +100,14 @@ static int ble_svc_gatt_cl_sup_feat_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { + uint8_t supported_feat; + int rc; + if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) { - uint8_t supported_feat = - (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0) << 1 | - (MYNEWT_VAL(BLE_ATT_SVR_NOTIFY_MULTI) == 1) << 2; + rc = ble_gatts_peer_cl_sup_feat_get(conn_handle, &supported_feat, 1); + if (rc != 0) { + return BLE_ATT_ERR_UNLIKELY; + } os_mbuf_append(ctxt->om, &supported_feat, sizeof(supported_feat)); return 0; } diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index ce5f1709e0..2f95b70e35 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -1580,6 +1580,35 @@ ble_gatts_chr_updated(uint16_t chr_val_handle) } } +int +ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat, uint8_t len) +{ + struct ble_hs_conn *conn; + int rc = 0; + + if (out_supported_feat == NULL) { + return BLE_HS_EINVAL; + } + + ble_hs_lock(); + conn = ble_hs_conn_find(conn_handle); + if (conn == NULL) { + rc = BLE_HS_ENOTCONN; + goto done; + } + + if (BLE_GATT_CHR_CLI_SUP_FEAT_SZ < len) { + len = BLE_GATT_CHR_CLI_SUP_FEAT_SZ; + } + + memcpy(out_supported_feat, conn->bhc_gatt_svr.peer_cl_sup_feat, + sizeof(uint8_t) * len); + +done: + ble_hs_unlock(); + return rc; +} + int ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om) {