mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-06 05:14:45 +00:00
Dynamic service addition/deletion
This commit is contained in:
committed by
Abhinav Kudnar
parent
5c00c6444e
commit
84d4edcaa4
@@ -31,7 +31,7 @@
|
||||
#include "host/ble_att.h"
|
||||
#include "host/ble_uuid.h"
|
||||
#include "host/ble_esp_gatt.h"
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -919,6 +919,18 @@ struct ble_gatt_register_ctxt {
|
||||
typedef void ble_gatt_register_fn(struct ble_gatt_register_ctxt *ctxt,
|
||||
void *arg);
|
||||
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
struct ble_gatts_clt_cfg {
|
||||
STAILQ_ENTRY(ble_gatts_clt_cfg) next;
|
||||
uint16_t chr_val_handle;
|
||||
uint8_t flags;
|
||||
uint8_t allowed;
|
||||
};
|
||||
|
||||
/** A cached array of handles for the configurable characteristics. */
|
||||
STAILQ_HEAD(ble_gatts_clt_cfg_list, ble_gatts_clt_cfg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Queues a set of service definitions for registration. All services queued
|
||||
* in this manner get registered when ble_gatts_start() is called.
|
||||
@@ -933,6 +945,31 @@ typedef void ble_gatt_register_fn(struct ble_gatt_register_ctxt *ctxt,
|
||||
*/
|
||||
int ble_gatts_add_svcs(const struct ble_gatt_svc_def *svcs);
|
||||
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
/**
|
||||
* Adds a set of services for registration. All services added
|
||||
* in this manner get registered immidietely.
|
||||
*
|
||||
* @param svcs An array of service definitions to queue for
|
||||
* registration. This array must be
|
||||
* terminated with an entry whose 'type'
|
||||
* equals 0.
|
||||
*
|
||||
* @return 0 on success;
|
||||
* BLE_HS_ENOMEM on heap exhaustion.
|
||||
*/
|
||||
int ble_gatts_add_dynamic_svcs(const struct ble_gatt_svc_def *svcs);
|
||||
/**
|
||||
* Deletes a service with corresponding uuid. All services deleted
|
||||
* in this manner will be deleted immidietely.
|
||||
*
|
||||
* @param uuid uuid of the service to be deleted.
|
||||
*
|
||||
* @return 0 on success;
|
||||
* BLE_HS_ENOENT on invalid uuid.
|
||||
*/
|
||||
int ble_gatts_delete_svc(const ble_uuid_t *uuid);
|
||||
#endif
|
||||
/**
|
||||
* Set visibility of local GATT service. Invisible services are not removed
|
||||
* from database but are not discoverable by peer devices. Service Changed
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "host/ble_att.h"
|
||||
#include "host/ble_uuid.h"
|
||||
#include "nimble/nimble_npl.h"
|
||||
#include "syscfg/syscfg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -145,6 +146,10 @@ int ble_att_svr_register(const ble_uuid_t *uuid, uint8_t flags,
|
||||
uint8_t min_key_size, uint16_t *handle_id,
|
||||
ble_att_svr_access_fn *cb, void *cb_arg);
|
||||
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
int ble_att_svr_deregister(uint16_t start_handle, uint16_t end_group_handle);
|
||||
#endif
|
||||
|
||||
struct ble_att_svr_entry {
|
||||
STAILQ_ENTRY(ble_att_svr_entry) ha_next;
|
||||
|
||||
|
||||
@@ -69,6 +69,12 @@ ble_att_svr_entry_alloc(void)
|
||||
struct ble_att_svr_entry *entry;
|
||||
|
||||
entry = os_memblock_get(&ble_att_svr_entry_pool);
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
/* if dynamic services are enabled, try to allocate from heap */
|
||||
if (entry == NULL) {
|
||||
entry = nimble_platform_mem_malloc(sizeof *entry);
|
||||
}
|
||||
#endif
|
||||
if (entry != NULL) {
|
||||
memset(entry, 0, sizeof *entry);
|
||||
}
|
||||
@@ -79,7 +85,16 @@ ble_att_svr_entry_alloc(void)
|
||||
static void
|
||||
ble_att_svr_entry_free(struct ble_att_svr_entry *entry)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
if (os_memblock_from(&ble_att_svr_entry_pool, entry)) {
|
||||
os_memblock_put(&ble_att_svr_entry_pool, entry);
|
||||
}
|
||||
else {
|
||||
nimble_platform_mem_free(entry);
|
||||
}
|
||||
#else
|
||||
os_memblock_put(&ble_att_svr_entry_pool, entry);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,6 +149,27 @@ ble_att_svr_register(const ble_uuid_t *uuid, uint8_t flags,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
/**
|
||||
* Deregister a host attribute with the BLE stack.
|
||||
*
|
||||
* @param start_handle Start handle of the service entry
|
||||
* @param end_group_handle End group handle of the service entry
|
||||
*
|
||||
* @return 0 on success, non-zero error code on failure.
|
||||
*/
|
||||
int ble_att_svr_deregister(uint16_t start_handle, uint16_t end_group_handle) {
|
||||
uint16_t idx;
|
||||
struct ble_att_svr_entry *entry;
|
||||
for (idx = start_handle; idx <= end_group_handle; idx++) {
|
||||
entry = ble_att_svr_find_by_handle(idx);
|
||||
STAILQ_REMOVE(&ble_att_svr_list, entry, ble_att_svr_entry, ha_next);
|
||||
ble_att_svr_entry_free(entry);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t
|
||||
ble_att_svr_prev_handle(void)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,11 @@ extern STATS_SECT_DECL(ble_gatts_stats) ble_gatts_stats;
|
||||
typedef uint8_t ble_gatts_conn_flags;
|
||||
|
||||
struct ble_gatts_conn {
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
struct ble_gatts_clt_cfg_list clt_cfgs;
|
||||
#else
|
||||
struct ble_gatts_clt_cfg *clt_cfgs;
|
||||
#endif
|
||||
int num_clt_cfgs;
|
||||
|
||||
uint16_t indicate_val_handle;
|
||||
|
||||
+641
-2
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user