From b8499910c5bbe87665646728654a1ae762681f3d Mon Sep 17 00:00:00 2001 From: Abhinav Kudnar Date: Thu, 16 May 2024 16:51:52 +0530 Subject: [PATCH] feat(nimble): Added API to get resolve ADV data --- nimble/host/include/host/ble_esp_gap.h | 14 ++++++++++++++ nimble/host/src/ble_gap.c | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/nimble/host/include/host/ble_esp_gap.h b/nimble/host/include/host/ble_esp_gap.h index 8ad7de9c9..b9fe46bb9 100644 --- a/nimble/host/include/host/ble_esp_gap.h +++ b/nimble/host/include/host/ble_esp_gap.h @@ -49,6 +49,20 @@ int ble_gap_host_check_status(void); int ble_gap_dev_authorization(uint16_t conn_handle, bool authorized); +/** + * This API is called to get ADV data for a specific type. + + * + * @param adv_data Pointer of ADV data (unsigned 8 bit integer) which to be resolved. + * @param adv_type Finding ADV data type. + * @param adv_data_len Total length of Advertising data. + * @param length Return the length of ADV data not including type. + * + * @return Pointer (unsigned 8 bit integer) of type specific ADV data. + */ +uint8_t* +ble_resolve_adv_data(const uint8_t *adv_data, uint8_t adv_type, uint8_t adv_data_len , uint8_t * length); + #ifdef __cplusplus } #endif diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index b2b33036d..c1b0c5251 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -728,6 +728,22 @@ ble_gap_set_prefered_le_phy(uint16_t conn_handle, uint8_t tx_phys_mask, &cmd, sizeof(cmd), NULL, 0); } +uint8_t* ble_resolve_adv_data(const uint8_t *adv_data, uint8_t adv_type, uint8_t adv_data_len , uint8_t * length) +{ + int rc = 0; + const struct ble_hs_adv_field *fields; + const uint8_t *data; + + rc = ble_hs_adv_find_field(adv_type, adv_data, adv_data_len, &fields); /*Fill adv field*/ + + if (rc == 0) { + *length = fields->length -1 ; /* minus length of type*/ + data = fields->value; /* Type specific adv data*/ + return (uint8_t*)data; + } + + return NULL; +} /***************************************************************************** * $misc * *****************************************************************************/