Skip to content

Commit ae31a0e

Browse files
nimble/host: Add method for retrieving configuration values of CCCD
This metod allows reading configuration flags of Client Characteristic Configuration Descriptor for specified characteristic.
1 parent 852986e commit ae31a0e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

nimble/host/include/host/ble_gatt.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ struct ble_hs_cfg;
185185

186186
/** @} */
187187

188+
/**
189+
* @defgroup ble_gatts_clt_cfg Client Characteristic Configuration Descriptor (CCCD) Flags Types
190+
* @{
191+
*/
192+
193+
/** GATT Client Charactaristic Configuration Flag: Notify. */
194+
#define BLE_GATT_CCCD_NOTIFY 0x01
195+
196+
/** GATT Client Charactaristic Configuration Flag: Indicate. */
197+
#define BLE_GATT_CCCD_INDICATE 0x02
198+
199+
/** @} */
200+
188201
/*** @client. */
189202
/** Represents a GATT error. */
190203
struct ble_gatt_error {
@@ -1214,6 +1227,24 @@ int ble_gatts_start(void);
12141227
*/
12151228
int ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat, uint8_t len);
12161229

1230+
/**
1231+
* Reads configuration values from Client Characteristic Configuration
1232+
* Descriptor for specified characteristic.
1233+
*
1234+
* @param conn_handle Connection handle identifying the connection
1235+
* to which CCC instance is related.
1236+
* @param chr_val_handle The value handle of characteristic.
1237+
* @param cccd_value Configuration value of CCC.
1238+
*
1239+
* @return 0 on success;
1240+
* BLE_HS_ENOTCONN if no matching connection
1241+
* was found
1242+
* BLE_HS_ENOENT if descriptor could not be found.
1243+
*
1244+
*/
1245+
int ble_gatts_read_cccd(uint16_t conn_handle, uint16_t chr_val_handle,
1246+
uint8_t *cccd_value);
1247+
12171248
#ifdef __cplusplus
12181249
}
12191250
#endif

nimble/host/src/ble_gatts.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,33 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
737737
return 0;
738738
}
739739

740+
int
741+
ble_gatts_read_cccd(uint16_t conn_handle, uint16_t chr_val_handle,
742+
uint8_t *cccd_value)
743+
{
744+
struct ble_gatts_clt_cfg *clt_cfg;
745+
struct ble_hs_conn *conn;
746+
747+
ble_hs_lock();
748+
749+
conn = ble_hs_conn_find(conn_handle);
750+
if (conn == NULL) {
751+
return BLE_HS_ENOTCONN;
752+
}
753+
754+
clt_cfg = ble_gatts_clt_cfg_find(conn->bhc_gatt_svr.clt_cfgs,
755+
chr_val_handle);
756+
if (clt_cfg == NULL) {
757+
return BLE_HS_ENOENT;
758+
}
759+
760+
*cccd_value = clt_cfg->flags;
761+
762+
ble_hs_unlock();
763+
764+
return 0;
765+
}
766+
740767
int
741768
ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle,
742769
uint8_t op, uint16_t offset, struct os_mbuf **om,

0 commit comments

Comments
 (0)