Added API to get current stack operation status

This commit is contained in:
Rahul Tank
2024-02-29 16:23:47 +05:30
committed by Abhinav Kudnar
parent e2ec7a3dea
commit 8bcef4e241
5 changed files with 136 additions and 1 deletions
+21
View File
@@ -11,6 +11,19 @@
extern "C" {
#endif
enum gap_status {
BLE_GAP_STATUS_ADV = 0,
BLE_GAP_STATUS_EXT_ADV,
BLE_GAP_STATUS_SCAN,
BLE_GAP_STATUS_CONN,
BLE_GAP_STATUS_PAIRED,
BLE_GAP_STATUS_GATTS,
BLE_GAP_STATUS_HOST_PRIVACY,
BLE_GAP_STATUS_PERIODIC,
};
typedef enum gap_status gap_status_t;
#define BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_ADV_ADDR 0
#define BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID 1
#define BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE 2
@@ -91,6 +104,14 @@ int ble_gap_wl_tx_clear(void);
*/
int ble_gap_wl_read_size(uint8_t *size);
/**
* This API gives the current status of various stack operations
*
* @return 0 on success; nonzero bits indicating different
* operations as per enum gap_status.
*/
int ble_gap_host_check_status(void);
#if MYNEWT_VAL(BLE_HCI_VS)
#if MYNEWT_VAL(BLE_POWER_CONTROL)
+6
View File
@@ -1394,6 +1394,12 @@ int ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_
#if MYNEWT_VAL(BLE_GATT_CACHING)
int ble_gatts_calculate_hash(uint8_t *out_hash_key);
#endif
/**
* Returns the current number of configured characteristics
*/
int ble_gatts_get_cfgable_chrs(void);
#ifdef __cplusplus
}
#endif
+102
View File
@@ -31,6 +31,9 @@
#include "ble_gattc_cache_priv.h"
#endif
#include "host/ble_hs_pvcy.h"
#include "host/util/util.h"
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
@@ -7792,3 +7795,102 @@ ble_gap_deinit(void)
{
ble_npl_mutex_deinit(&preempt_done_mutex);
}
int
ble_gap_host_check_status(void)
{
int status = 0;
uint16_t conn_handle = 0;
#if MYNEWT_VAL(BLE_PERIODIC_ADV)
uint16_t sync_handle = 0;
#endif
struct ble_hs_conn *conn;
ble_addr_t oldest_peer_id_addr[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
int num_peers;
/* Stop Advertising */
#if MYNEWT_VAL(BLE_EXT_ADV)
int i;
for (i=0; i< BLE_ADV_INSTANCES; i++) {
if (ble_gap_ext_adv_active(i)) {
BLE_HS_LOG(ERROR, "Ext adv in progress for instance %d \n", i);
status |= BIT(BLE_GAP_STATUS_EXT_ADV);
break;
}
}
#else
if (ble_gap_adv_active_instance(0)) {
BLE_HS_LOG(ERROR, "Gap Advertising is active \n");
status |= BIT(BLE_GAP_STATUS_ADV);
}
#endif
/* Stop scanning */
if (ble_gap_disc_active()) {
BLE_HS_LOG(ERROR, "Scanning in progress \n");
status |= BIT(BLE_GAP_STATUS_SCAN);
}
/* Terminate links */
for (conn_handle=0; conn_handle<50; conn_handle++) {
ble_hs_lock();
conn = ble_hs_conn_find(conn_handle);
ble_hs_unlock();
if (conn != NULL) {
BLE_HS_LOG(ERROR, "Connection exists \n");
status |= BIT(BLE_GAP_STATUS_CONN);
break;
}
}
/* Check for paired devices*/
ble_store_util_bonded_peers(&oldest_peer_id_addr[0],
&num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
if (num_peers) {
BLE_HS_LOG(ERROR, "Unpaired device exists\n");
status |= BIT(BLE_GAP_STATUS_PAIRED);
}
/* gatts reset */
if (ble_gatts_get_cfgable_chrs()) {
BLE_HS_LOG(ERROR, "Gatt reset not done \n");
status |= BIT(BLE_GAP_STATUS_GATTS);
}
/* Check if privacy is disabled */
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
extern int is_ble_hs_resolv_enabled(void);
if (is_ble_hs_resolv_enabled()) {
BLE_HS_LOG(ERROR, "Host based Privacy not disabled \n");
status |= BIT(BLE_GAP_STATUS_HOST_PRIVACY);
}
#endif
/* Periodic adv termination */
#if MYNEWT_VAL(BLE_PERIODIC_ADV)
struct ble_hs_periodic_sync *psync;
for (sync_handle=0; sync_handle<50; sync_handle++) {
ble_hs_lock();
psync = ble_hs_periodic_sync_find_by_handle(sync_handle);
ble_hs_unlock();
if (psync) {
BLE_HS_LOG(ERROR, "Periodic adv not disabled \n");
status |= BIT(BLE_GAP_STATUS_PERIODIC);
break;
}
}
#endif
return status;
}
+6
View File
@@ -3149,6 +3149,12 @@ ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs)
return 0;
}
int
ble_gatts_get_cfgable_chrs(void)
{
return ble_gatts_num_cfgable_chrs;
}
void
ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb, void *arg)
{
+1 -1
View File
@@ -327,7 +327,7 @@ ble_rpa_replace_peer_params_with_rl(uint8_t *peer_addr, uint8_t *addr_type,
*
* @return uint8_t
*/
static uint8_t
uint8_t
is_ble_hs_resolv_enabled(void)
{
return g_ble_hs_resolv_data.addr_res_enabled;