fix(nimble): Add support for minimilistic build sdkconfig

This commit is contained in:
Rahul Tank
2025-05-19 12:41:40 +05:30
parent 375cc98772
commit 45352c459a
29 changed files with 224 additions and 54 deletions
@@ -26,6 +26,7 @@
#include "host/ble_gap.h"
#include "services/ans/ble_svc_ans.h"
#if MYNEWT_VAL(BLE_GATTS)
/* Max length of new alert info string */
#define BLE_SVC_ANS_INFO_STR_MAX_LEN 18
/* Max length of a new alert notification, max string length + 2 bytes
@@ -462,3 +463,4 @@ ble_svc_ans_init(void)
ble_svc_ans_new_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_NEW_ALERT_CAT);
ble_svc_ans_unr_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_UNR_ALERT_CAT);
}
#endif
@@ -26,6 +26,7 @@
#include "host/ble_gap.h"
#include "services/bas/ble_svc_bas.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_BAS_SERVICE
/* Characteristic value handles */
#if MYNEWT_VAL(BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE) > 0
static uint16_t ble_svc_bas_battery_handle;
@@ -125,3 +126,4 @@ ble_svc_bas_init(void)
rc = ble_gatts_add_svcs(ble_svc_bas_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -30,6 +30,7 @@
#include "console/console.h"
#include "esp_nimble_mem.h"
#if MYNEWT_VAL(BLE_GATTS)
/* ble uart attr read handle */
uint16_t g_bleuart_attr_read_handle;
@@ -202,3 +203,4 @@ bleuart_init(void)
console_buf = nimble_platform_mem_malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
SYSINIT_PANIC_ASSERT(console_buf != NULL);
}
#endif
+2 -1
View File
@@ -28,7 +28,7 @@
#include "time.h"
#include <sys/time.h>
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_CTS_SERVICE
struct ble_svc_cts_cfg cts_cfg = {0};
/* characteristic values */
@@ -277,3 +277,4 @@ ble_svc_cts_init(struct ble_svc_cts_cfg cfg)
rc = ble_gatts_add_svcs(ble_svc_cts_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -23,6 +23,7 @@
#include "host/ble_hs.h"
#include "services/dis/ble_svc_dis.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_DIS_SERVICE
/* Device information */
struct ble_svc_dis_data ble_svc_dis_data = {
.model_number = MYNEWT_VAL(BLE_SVC_DIS_MODEL_NUMBER_DEFAULT),
@@ -412,3 +413,4 @@ ble_svc_dis_init(void)
rc = ble_gatts_add_svcs(ble_svc_dis_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -25,6 +25,8 @@
#include "services/gap/ble_svc_gap.h"
#include "os/endian.h"
#if MYNEWT_VAL(BLE_GATTS)
#define PPCP_ENABLED \
MYNEWT_VAL(BLE_ROLE_PERIPHERAL) && \
(MYNEWT_VAL(BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL) || \
@@ -399,3 +401,4 @@ ble_svc_gap_deinit(void)
{
ble_gatts_free_svcs();
}
#endif
@@ -23,6 +23,7 @@
#include "host/ble_hs.h"
#include "services/gatt/ble_svc_gatt.h"
#if MYNEWT_VAL(BLE_GATTS)
#if MYNEWT_VAL(BLE_GATT_CACHING)
static uint16_t ble_svc_gatt_db_hash_handle;
static uint16_t ble_svc_gatt_client_supp_feature_handle;
@@ -255,3 +256,4 @@ ble_svc_gatt_deinit(void)
{
ble_gatts_free_svcs();
}
#endif
@@ -23,7 +23,9 @@
#include "sysinit/sysinit.h"
#include "syscfg/syscfg.h"
#if MYNEWT_VAL(BLE_SVC_HID_SERVICE)
#if MYNEWT_VAL(BLE_GATTS)
#include "host/ble_hs.h"
#include "host/ble_gap.h"
#include "services/hid/ble_svc_hid.h"
@@ -711,4 +713,5 @@ ble_svc_hid_init(void)
rc = ble_gatts_add_svcs(ble_svc_hid_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
#endif // CONFIG_BT_NIMBLE_HID_SERVICE
+2
View File
@@ -13,6 +13,7 @@
#include "host/ble_gap.h"
#include "services/hr/ble_svc_hr.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_HR_SERVICE
/* Characteristic values */
static uint8_t ble_svc_hr_measurement;
static uint16_t ble_svc_hr_body_sensor_loc;
@@ -231,3 +232,4 @@ ble_svc_hr_init(void)
ble_svc_hr_conn_handle[i] = -1;
}
}
#endif
@@ -13,6 +13,7 @@
#include "host/ble_gap.h"
#include "services/htp/ble_svc_htp.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_HTP_SERVICE
/* Characteristic values */
static uint16_t ble_svc_htp_temp_type;
static uint16_t ble_svc_htp_temp_msr_itvl;
@@ -289,3 +290,4 @@ ble_svc_htp_init(void)
memset(&conn_chr_subs, 0, sizeof(conn_chr_subs));
}
#endif
@@ -23,6 +23,7 @@
#include "host/ble_hs.h"
#include "services/ias/ble_svc_ias.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_IAS_SERVICE
/* Callback function */
static ble_svc_ias_event_fn *ble_svc_ias_cb_fn;
@@ -147,3 +148,4 @@ ble_svc_ias_init(void)
rc = ble_gatts_add_svcs(ble_svc_ias_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -23,6 +23,7 @@
#include "host/ble_hs.h"
#include "services/ipss/ble_svc_ipss.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_IPSS_SERVICE
static const struct ble_gatt_svc_def ble_svc_ipss_defs[] = {
{
/*** Service: GATT */
@@ -49,3 +50,4 @@ ble_svc_ipss_init(void)
rc = ble_gatts_add_svcs(ble_svc_ipss_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -23,6 +23,7 @@
#include "host/ble_hs.h"
#include "services/lls/ble_svc_lls.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_LLS_SERVICE
/* Callback function */
static ble_svc_lls_event_fn *ble_svc_lls_cb_fn;
@@ -192,3 +193,4 @@ ble_svc_lls_init(void)
rc = ble_gatts_add_svcs(ble_svc_lls_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -13,6 +13,7 @@
#include "host/ble_gap.h"
#include "services/prox/ble_svc_prox.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_PROX_SERVICE
/* Characteristic values */
static uint8_t ble_svc_prox_link_loss_alert;
static int8_t ble_svc_prox_alert;
@@ -261,3 +262,4 @@ ble_svc_prox_init(void)
ble_svc_prox_alert_conn[i] = false;
}
}
#endif
@@ -23,6 +23,7 @@
#include "host/ble_hs.h"
#include "services/sps/ble_svc_sps.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_SPS_SERVICE
static uint16_t ble_scan_itvl;
static uint16_t ble_scan_window;
static uint8_t ble_scan_refresh;
@@ -147,3 +148,4 @@ ble_svc_sps_init(uint16_t scan_itvl, uint16_t scan_window)
rc = ble_gatts_add_svcs(ble_svc_sps_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
@@ -30,6 +30,7 @@
*/
#include "../src/ble_hs_hci_priv.h"
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_TPS_SERVICE
int8_t ble_svc_tps_tx_power_level;
/* Access function */
@@ -105,3 +106,4 @@ ble_svc_tps_init(void)
rc = ble_gatts_add_svcs(ble_svc_tps_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
}
#endif
+19 -18
View File
@@ -43,37 +43,41 @@ struct ble_att_rx_dispatch_entry {
/** Dispatch table for incoming ATT commands. Must be ordered by op code. */
static const struct ble_att_rx_dispatch_entry ble_att_rx_dispatch[] = {
#if MYNEWT_VAL(BLE_GATTC)
{ BLE_ATT_OP_ERROR_RSP, ble_att_clt_rx_error },
{ BLE_ATT_OP_MTU_REQ, ble_att_svr_rx_mtu },
{ BLE_ATT_OP_MTU_RSP, ble_att_clt_rx_mtu },
{ BLE_ATT_OP_FIND_INFO_REQ, ble_att_svr_rx_find_info },
{ BLE_ATT_OP_FIND_INFO_RSP, ble_att_clt_rx_find_info },
{ BLE_ATT_OP_FIND_TYPE_VALUE_REQ, ble_att_svr_rx_find_type_value },
{ BLE_ATT_OP_FIND_TYPE_VALUE_RSP, ble_att_clt_rx_find_type_value },
{ BLE_ATT_OP_READ_TYPE_REQ, ble_att_svr_rx_read_type },
{ BLE_ATT_OP_READ_TYPE_RSP, ble_att_clt_rx_read_type },
{ BLE_ATT_OP_READ_REQ, ble_att_svr_rx_read },
{ BLE_ATT_OP_READ_RSP, ble_att_clt_rx_read },
{ BLE_ATT_OP_READ_BLOB_REQ, ble_att_svr_rx_read_blob },
{ BLE_ATT_OP_READ_BLOB_RSP, ble_att_clt_rx_read_blob },
{ BLE_ATT_OP_READ_MULT_REQ, ble_att_svr_rx_read_mult },
{ BLE_ATT_OP_READ_MULT_RSP, ble_att_clt_rx_read_mult },
{ BLE_ATT_OP_READ_GROUP_TYPE_REQ, ble_att_svr_rx_read_group_type },
{ BLE_ATT_OP_READ_GROUP_TYPE_RSP, ble_att_clt_rx_read_group_type },
{ BLE_ATT_OP_WRITE_REQ, ble_att_svr_rx_write },
{ BLE_ATT_OP_WRITE_RSP, ble_att_clt_rx_write },
{ BLE_ATT_OP_PREP_WRITE_REQ, ble_att_svr_rx_prep_write },
{ BLE_ATT_OP_PREP_WRITE_RSP, ble_att_clt_rx_prep_write },
{ BLE_ATT_OP_EXEC_WRITE_REQ, ble_att_svr_rx_exec_write },
{ BLE_ATT_OP_EXEC_WRITE_RSP, ble_att_clt_rx_exec_write },
{ BLE_ATT_OP_INDICATE_RSP, ble_att_clt_rx_indicate },
{ BLE_ATT_OP_READ_MULT_VAR_RSP, ble_att_clt_rx_read_mult_var },
#endif
#if MYNEWT_VAL(BLE_GATTS)
{ BLE_ATT_OP_MTU_REQ, ble_att_svr_rx_mtu },
{ BLE_ATT_OP_FIND_INFO_REQ, ble_att_svr_rx_find_info },
{ BLE_ATT_OP_FIND_TYPE_VALUE_REQ, ble_att_svr_rx_find_type_value },
{ BLE_ATT_OP_READ_TYPE_REQ, ble_att_svr_rx_read_type },
{ BLE_ATT_OP_READ_REQ, ble_att_svr_rx_read },
{ BLE_ATT_OP_READ_BLOB_REQ, ble_att_svr_rx_read_blob },
{ BLE_ATT_OP_READ_MULT_REQ, ble_att_svr_rx_read_mult },
{ BLE_ATT_OP_READ_GROUP_TYPE_REQ, ble_att_svr_rx_read_group_type },
{ BLE_ATT_OP_WRITE_REQ, ble_att_svr_rx_write },
{ BLE_ATT_OP_PREP_WRITE_REQ, ble_att_svr_rx_prep_write },
{ BLE_ATT_OP_EXEC_WRITE_REQ, ble_att_svr_rx_exec_write },
{ BLE_ATT_OP_NOTIFY_REQ, ble_att_svr_rx_notify },
{ BLE_ATT_OP_INDICATE_REQ, ble_att_svr_rx_indicate },
{ BLE_ATT_OP_INDICATE_RSP, ble_att_clt_rx_indicate },
{ BLE_ATT_OP_READ_MULT_VAR_REQ, ble_att_svr_rx_read_mult_var },
{ BLE_ATT_OP_READ_MULT_VAR_RSP, ble_att_clt_rx_read_mult_var },
{ BLE_ATT_OP_NOTIFY_MULTI_REQ, ble_att_svr_rx_notify_multi },
{ BLE_ATT_OP_WRITE_CMD, ble_att_svr_rx_write_no_rsp },
{ BLE_ATT_OP_SIGNED_WRITE_CMD, ble_att_svr_rx_signed_write },
#endif
};
#define BLE_ATT_RX_DISPATCH_SZ \
@@ -150,10 +154,6 @@ ble_att_rx_dispatch_entry_find(uint8_t op)
if (entry->bde_op == op) {
return entry;
}
if (entry->bde_op > op) {
break;
}
}
return NULL;
@@ -508,10 +508,11 @@ ble_att_rx_handle_unknown_request(uint8_t op, uint16_t conn_handle,
if (op & 0x40) {
return;
}
#if MYNEWT_VAL(BLE_GATTS)
os_mbuf_adj(*om, OS_MBUF_PKTLEN(*om));
ble_att_svr_tx_error_rsp(conn_handle, cid, *om, op, 0,
BLE_ATT_ERR_REQ_NOT_SUPPORTED);
#endif
*om = NULL;
}
+5
View File
@@ -32,6 +32,7 @@
#endif
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTC)
/*****************************************************************************
* $error response *
*****************************************************************************/
@@ -1001,6 +1002,8 @@ ble_att_clt_rx_exec_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **r
return 0;
}
#endif
/*****************************************************************************
* $handle value notification *
*****************************************************************************/
@@ -1079,6 +1082,7 @@ err:
return rc;
}
#if MYNEWT_VAL(BLE_GATTC)
int
ble_att_clt_rx_indicate(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
{
@@ -1122,3 +1126,4 @@ ble_att_clt_tx_notify_mult(uint16_t conn_handle, struct os_mbuf *txom)
}
#endif
#endif
+3
View File
@@ -28,6 +28,8 @@
#include "esp_nimble_mem.h"
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTS)
/**
* ATT server - Attribute Protocol
*
@@ -3523,3 +3525,4 @@ ble_att_svr_security_mode_1_level()
}
#endif
#endif
#endif
+18 -2
View File
@@ -1199,8 +1199,12 @@ ble_gap_master_connect_reattempt(uint16_t conn_handle)
ble_l2cap_sig_conn_broken(conn_handle, BLE_ERR_CONN_ESTABLISHMENT);
ble_sm_connection_broken(conn_handle);
ble_gatts_connection_broken(conn_handle);
ble_gattc_connection_broken(conn_handle);
#if MYNEWT_VAL(BLE_GATTS)
ble_gatts_connection_broken(conn_handle);
#endif
#if MYNEWT_VAL(BLE_GATTC)
ble_gattc_connection_broken(conn_handle);
#endif
ble_hs_flow_connection_broken(conn_handle);;
rc = ble_hs_atomic_conn_delete(conn_handle);
@@ -1583,8 +1587,14 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason)
*/
ble_l2cap_sig_conn_broken(conn_handle, reason);
ble_sm_connection_broken(conn_handle);
#if MYNEWT_VAL(BLE_GATTS)
ble_gatts_connection_broken(conn_handle);
#endif
#if MYNEWT_VAL(BLE_GATTC)
ble_gattc_connection_broken(conn_handle);
#endif
#if MYNEWT_VAL(BLE_GATT_CACHING)
ble_gattc_cache_conn_broken(conn_handle);
#endif
@@ -8484,6 +8494,7 @@ ble_gap_enc_event(uint16_t conn_handle, int status,
/* If encryption succeeded and encryption has been restored for bonded device,
* notify gatt server so it has chance to send notification/indication if needed.
*/
#if MYNEWT_VAL(BLE_GATTS)
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
#if MYNEWT_VAL(BLE_GATT_CACHING)
@@ -8491,17 +8502,22 @@ ble_gap_enc_event(uint16_t conn_handle, int status,
#endif
return;
}
#endif
/* If this is fresh pairing and bonding has been established,
* notify gatt server about that so previous subscriptions (before bonding)
* can be stored.
*/
#if MYNEWT_VAL(BLE_GATTS)
if (bonded) {
ble_gatts_bonding_established(conn_handle);
#if MYNEWT_VAL(BLE_GATT_CACHING)
ble_gattc_cache_conn_bonding_established(conn_handle);
#endif
}
#endif
#endif
}
+70 -6
View File
@@ -66,6 +66,7 @@
#endif
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTC)
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
@@ -74,6 +75,7 @@
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
#endif
/*****************************************************************************
* $definitions / declarations *
*****************************************************************************/
@@ -85,6 +87,7 @@
#define BLE_GATTC_UNRESPONSIVE_TIMEOUT_MS 30000 /* ms */
#define BLE_GATT_OP_NONE UINT8_MAX
#define BLE_GATT_OP_MTU 0
#define BLE_GATT_OP_DISC_ALL_SVCS 1
#define BLE_GATT_OP_DISC_SVC_UUID 2
@@ -231,6 +234,7 @@ struct ble_gattc_proc {
};
};
#if MYNEWT_VAL(BLE_GATTC_PROC_PREEMPTION_PROTECT)
static struct ble_gattc_proc_list temp_proc_list;
#endif
@@ -242,6 +246,8 @@ STAILQ_HEAD(ble_gattc_proc_list, ble_gattc_proc);
*/
typedef void ble_gattc_err_fn(struct ble_gattc_proc *proc, int status,
uint16_t att_handle);
#if MYNEWT_VAL(BLE_GATTC)
static ble_gattc_err_fn ble_gattc_mtu_err;
static ble_gattc_err_fn ble_gattc_disc_all_svcs_err;
static ble_gattc_err_fn ble_gattc_disc_svc_uuid_err;
@@ -257,9 +263,14 @@ static ble_gattc_err_fn ble_gattc_read_mult_var_err;
static ble_gattc_err_fn ble_gattc_write_err;
static ble_gattc_err_fn ble_gattc_write_long_err;
static ble_gattc_err_fn ble_gattc_write_reliable_err;
#endif
#if MYNEWT_VAL(BLE_GATTS)
static ble_gattc_err_fn ble_gatts_indicate_err;
#endif
static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_CNT] = {
#if MYNEWT_VAL(BLE_GATTC)
[BLE_GATT_OP_MTU] = ble_gattc_mtu_err,
[BLE_GATT_OP_DISC_ALL_SVCS] = ble_gattc_disc_all_svcs_err,
[BLE_GATT_OP_DISC_SVC_UUID] = ble_gattc_disc_svc_uuid_err,
@@ -275,9 +286,13 @@ static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_CNT] = {
[BLE_GATT_OP_WRITE] = ble_gattc_write_err,
[BLE_GATT_OP_WRITE_LONG] = ble_gattc_write_long_err,
[BLE_GATT_OP_WRITE_RELIABLE] = ble_gattc_write_reliable_err,
#endif
#if MYNEWT_VAL(BLE_GATTS)
[BLE_GATT_OP_INDICATE] = ble_gatts_indicate_err,
#endif
};
#if MYNEWT_VAL(BLE_GATTC)
/**
* Resume functions - these handle periodic retries of procedures that have
* stalled due to memory exhaustion.
@@ -435,6 +450,7 @@ static const struct ble_gattc_rx_exec_entry {
{ BLE_GATT_OP_WRITE_RELIABLE, ble_gattc_write_reliable_rx_exec },
};
#endif
static os_membuf_t ble_gattc_proc_mem[
OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_GATT_MAX_PROCS),
sizeof (struct ble_gattc_proc))
@@ -445,6 +461,7 @@ static struct os_mempool ble_gattc_proc_pool;
/* The list of active GATT client procedures. */
static struct ble_gattc_proc_list ble_gattc_procs;
#if MYNEWT_VAL(BLE_GATTC)
/* The time when we should attempt to resume stalled procedures, in OS ticks.
* A value of 0 indicates no stalled procedures.
*/
@@ -497,6 +514,7 @@ STATS_NAME_END(ble_gattc_stats)
/*****************************************************************************
* $debug *
*****************************************************************************/
#endif
static void
ble_gattc_dbg_assert_proc_not_inserted(struct ble_gattc_proc *proc)
@@ -514,6 +532,7 @@ ble_gattc_dbg_assert_proc_not_inserted(struct ble_gattc_proc *proc)
#endif
}
/*****************************************************************************
* $log *
*****************************************************************************/
@@ -524,6 +543,7 @@ ble_gattc_log_proc_init(const char *name)
BLE_HS_LOG(INFO, "GATT procedure initiated: %s", name);
}
#if MYNEWT_VAL(BLE_GATTC)
static void
ble_gattc_log_uuid(const ble_uuid_t *uuid)
{
@@ -662,6 +682,7 @@ ble_gattc_log_write_reliable(struct ble_gattc_proc *proc)
}
BLE_HS_LOG(INFO, "\n");
}
#endif
static void
ble_gattc_log_notify(uint16_t att_handle)
@@ -670,6 +691,8 @@ ble_gattc_log_notify(uint16_t att_handle)
BLE_HS_LOG(INFO, "att_handle=%d\n", att_handle);
}
#if MYNEWT_VAL(BLE_GATTC)
static void
ble_gattc_log_multi_notify(struct ble_gatt_notif * tuples, uint16_t num)
{
@@ -679,6 +702,7 @@ ble_gattc_log_multi_notify(struct ble_gatt_notif * tuples, uint16_t num)
}
}
#endif
static void
ble_gattc_log_indicate(uint16_t att_handle)
{
@@ -686,6 +710,7 @@ ble_gattc_log_indicate(uint16_t att_handle)
BLE_HS_LOG(INFO, "att_handle=%d\n", att_handle);
}
#if MYNEWT_VAL(BLE_GATTC)
/*****************************************************************************
* $rx entry *
*****************************************************************************/
@@ -714,7 +739,7 @@ ble_gattc_rx_entry_find(uint8_t op, const void *rx_entries, int num_entries)
/*****************************************************************************
* $proc *
*****************************************************************************/
#endif
/**
* Allocates a proc entry.
*
@@ -733,6 +758,7 @@ ble_gattc_proc_alloc(void)
return proc;
}
static void
ble_gattc_proc_prepare(struct ble_gattc_proc *proc, uint16_t conn_handle, uint8_t op)
{
@@ -803,6 +829,7 @@ ble_gattc_proc_set_exp_timer(struct ble_gattc_proc *proc)
ble_npl_time_ms_to_ticks32(BLE_GATTC_UNRESPONSIVE_TIMEOUT_MS);
}
#if MYNEWT_VAL(BLE_GATTC)
static void
ble_gattc_proc_set_resume_timer(struct ble_gattc_proc *proc)
{
@@ -822,6 +849,8 @@ ble_gattc_proc_set_resume_timer(struct ble_gattc_proc *proc)
}
}
#endif
static void
ble_gattc_process_status(struct ble_gattc_proc *proc, int status)
{
@@ -841,6 +870,7 @@ ble_gattc_process_status(struct ble_gattc_proc *proc, int status)
}
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Processes the return code that results from an attempt to resume a
* procedure. If the resume attempt failed due to memory exhaustion at a lower
@@ -866,6 +896,7 @@ ble_gattc_process_resume_status(struct ble_gattc_proc *proc, int status)
/*****************************************************************************
* $util *
*****************************************************************************/
#endif
/**
* Retrieves the error dispatch entry with the specified op code.
@@ -877,6 +908,7 @@ ble_gattc_err_dispatch_get(uint8_t op)
return ble_gattc_err_dispatch[op];
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Retrieves the error dispatch entry with the specified op code.
*/
@@ -894,6 +926,7 @@ ble_gattc_tmo_dispatch_get(uint8_t op)
return ble_gattc_tmo_dispatch[op];
}
#endif
typedef int ble_gattc_match_fn(struct ble_gattc_proc *proc, void *arg);
struct ble_gattc_criteria_conn_op {
@@ -930,6 +963,7 @@ ble_gattc_proc_matches_conn_op(struct ble_gattc_proc *proc, void *arg)
return 1;
}
#if MYNEWT_VAL(BLE_GATTC)
static int
ble_gattc_proc_matches_conn_cid_op(struct ble_gattc_proc *proc, void *arg)
{
@@ -1008,6 +1042,8 @@ ble_gattc_proc_matches_conn_rx_entry(struct ble_gattc_proc *proc, void *arg)
return (criteria->matching_rx_entry != NULL);
}
#endif
static void
ble_gattc_extract(ble_gattc_match_fn *cb, void *arg, int max_procs,
struct ble_gattc_proc_list *dst_list)
@@ -1080,6 +1116,7 @@ ble_gattc_extract(ble_gattc_match_fn *cb, void *arg, int max_procs,
ble_hs_unlock();
}
#if MYNEWT_VAL(BLE_GATTC)
static struct ble_gattc_proc *
ble_gattc_extract_one(ble_gattc_match_fn *cb, void *arg)
{
@@ -1089,6 +1126,8 @@ ble_gattc_extract_one(ble_gattc_match_fn *cb, void *arg)
return STAILQ_FIRST(&dst_list);
}
#endif
static void
ble_gattc_extract_by_conn_op(uint16_t conn_handle, uint8_t op, int max_procs,
struct ble_gattc_proc_list *dst_list)
@@ -1101,6 +1140,8 @@ ble_gattc_extract_by_conn_op(uint16_t conn_handle, uint8_t op, int max_procs,
ble_gattc_extract(ble_gattc_proc_matches_conn_op, &criteria, max_procs, dst_list);
}
#if MYNEWT_VAL(BLE_GATTC)
static void
ble_gattc_extract_by_conn_cid_op(uint16_t conn_handle, uint16_t psm, uint8_t op,
int max_procs,
@@ -1195,7 +1236,7 @@ ble_gattc_extract_with_rx_entry(uint16_t conn_handle, uint16_t cid,
(conn_handle), (cid), (rx_entries), \
sizeof (rx_entries) / sizeof (rx_entries)[0], \
(const void **)(out_rx_entry))
#endif
/**
* Causes all GATT procedures matching the specified criteria to fail with the
@@ -1225,6 +1266,7 @@ ble_gattc_fail_procs(uint16_t conn_handle, uint8_t op, int status)
}
}
#if MYNEWT_VAL(BLE_GATTC)
static void
ble_gattc_resume_procs(void)
{
@@ -5008,6 +5050,8 @@ static int ble_gatts_check_conn_aware(uint16_t conn_handle, bool *aware) {
}
#endif
#endif
int
ble_gatts_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
struct os_mbuf *txom)
@@ -5074,6 +5118,7 @@ done:
return rc;
}
#if MYNEWT_VAL(BLE_GATTC)
int
ble_gatts_notify_multiple_custom(uint16_t conn_handle,
size_t chr_count,
@@ -5195,6 +5240,7 @@ ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
{
return ble_gatts_notify_custom(conn_handle, chr_val_handle, txom);
}
#endif
int
ble_gatts_notify(uint16_t conn_handle, uint16_t chr_val_handle)
@@ -5210,6 +5256,7 @@ ble_gatts_notify(uint16_t conn_handle, uint16_t chr_val_handle)
return rc;
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Deprecated. Should not be used. Use ble_gatts_notify instead.
*/
@@ -5219,10 +5266,12 @@ ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle)
return ble_gatts_notify(conn_handle, chr_val_handle);
}
#endif
/*****************************************************************************
* $indicate *
*****************************************************************************/
#if MYNEWT_VAL(BLE_GATTS)
/**
* Handles an incoming ATT error response for the specified indication proc.
* A device should never send an error in response to an indication. If this
@@ -5252,7 +5301,9 @@ ble_gatts_indicate_err(struct ble_gattc_proc *proc, int status,
/* Send the next indication if one is pending. */
ble_gatts_send_next_indicate(proc->conn_handle);
}
#endif
#if MYNEWT_VAL(BLE_GATTC)
static void
ble_gatts_indicate_tmo(struct ble_gattc_proc *proc)
{
@@ -5270,24 +5321,28 @@ ble_gatts_indicate_tmo(struct ble_gattc_proc *proc)
static void
ble_gatts_indicate_rx_rsp(struct ble_gattc_proc *proc)
{
int rc;
ble_gattc_dbg_assert_proc_not_inserted(proc);
#if MYNEWT_VAL(BLE_GATTS)
int rc;
rc = ble_gatts_rx_indicate_ack(proc->conn_handle,
proc->indicate.chr_val_handle);
if (rc != 0) {
return;
}
#endif
/* Tell the application about the received acknowledgment. */
ble_gap_notify_tx_event(BLE_HS_EDONE, proc->conn_handle,
proc->indicate.chr_val_handle, 1);
#if MYNEWT_VAL(BLE_GATTS)
/* Send the next indication if one is pending. */
ble_gatts_send_next_indicate(proc->conn_handle);
#endif
}
#endif
/**
* Causes the indication in progress for the specified connection (if any) to
* fail with a status code of BLE_HS_ENOTCONN;
@@ -5388,6 +5443,7 @@ done:
return rc;
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Deprecated. Should not be used. Use ble_gatts_indicate_custom instead.
*/
@@ -5397,6 +5453,8 @@ ble_gattc_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle,
{
return ble_gatts_indicate_custom(conn_handle, chr_val_handle, txom);
}
#endif
int
ble_gatts_indicate(uint16_t conn_handle, uint16_t chr_val_handle)
@@ -5404,6 +5462,8 @@ ble_gatts_indicate(uint16_t conn_handle, uint16_t chr_val_handle)
return ble_gatts_indicate_custom(conn_handle, chr_val_handle, NULL);
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Deprecated. Should not be used. Use ble_gatts_indicate instead.
*/
@@ -5780,6 +5840,7 @@ ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, uint16_t cid, int status)
}
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Dispatches an incoming ATT handle-value-confirmation to the appropriate
* active GATT procedure.
@@ -5800,6 +5861,7 @@ ble_gatts_rx_indicate_rsp(uint16_t conn_handle, uint16_t cid)
ble_gattc_process_status(proc, BLE_HS_EDONE);
}
}
#endif
/*****************************************************************************
* $misc *
@@ -5840,6 +5902,8 @@ ble_gattc_any_jobs(void)
return !STAILQ_EMPTY(&ble_gattc_procs);
}
#endif
int
ble_gattc_init(void)
{
+3
View File
@@ -27,6 +27,7 @@
#include "ble_hs_priv.h"
#include "esp_nimble_mem.h"
#if MYNEWT_VAL(BLE_GATTS)
static uint8_t perm_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE ;
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
@@ -3337,3 +3338,5 @@ ble_gatts_init(void)
return 0;
}
#endif
+13 -2
View File
@@ -40,7 +40,7 @@
MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT))
static void ble_hs_event_rx_hci_ev(struct ble_npl_event *ev);
#if NIMBLE_BLE_CONNECT
#if NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_GATTS)
static void ble_hs_event_tx_notify(struct ble_npl_event *ev);
#endif
static void ble_hs_event_reset(struct ble_npl_event *ev);
@@ -432,9 +432,10 @@ ble_hs_timer_exp(struct ble_npl_event *ev)
switch (ble_hs_sync_state) {
case BLE_HS_SYNC_STATE_GOOD:
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTC)
ticks_until_next = ble_gattc_timer();
ble_hs_timer_sched(ticks_until_next);
#endif
ticks_until_next = ble_l2cap_sig_timer();
ble_hs_timer_sched(ticks_until_next);
@@ -547,12 +548,14 @@ ble_hs_event_rx_hci_ev(struct ble_npl_event *ev)
}
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTS)
static void
ble_hs_event_tx_notify(struct ble_npl_event *ev)
{
ble_gatts_tx_notifications();
}
#endif
#endif
static void
ble_hs_event_rx_data(struct ble_npl_event *ev)
@@ -688,10 +691,12 @@ ble_hs_start(void)
ble_npl_callout_init(&ble_hs_timer, ble_hs_evq, ble_hs_timer_exp, NULL);
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTS)
rc = ble_gatts_start();
if (rc != 0) {
return rc;
}
#endif
#endif
ble_hs_sync();
@@ -783,8 +788,10 @@ ble_hs_init(void)
ble_hs_enabled_state = BLE_HS_ENABLED_STATE_OFF;
#if NIMBLE_BLE_CONNECT
#if MYNEWT_VAL(BLE_GATTS)
ble_npl_event_init(&ble_hs_ev_tx_notifications, ble_hs_event_tx_notify,
NULL);
#endif
#endif
ble_npl_event_init(&ble_hs_ev_reset, ble_hs_event_reset, NULL);
ble_npl_event_init(&ble_hs_ev_start_stage1, ble_hs_event_start_stage1,
@@ -815,8 +822,10 @@ ble_hs_init(void)
rc = ble_att_init();
SYSINIT_PANIC_ASSERT(rc == 0);
#if MYNEWT_VAL(BLE_GATTS)
rc = ble_att_svr_init();
SYSINIT_PANIC_ASSERT(rc == 0);
#endif
rc = ble_gattc_init();
SYSINIT_PANIC_ASSERT(rc == 0);
@@ -826,8 +835,10 @@ ble_hs_init(void)
SYSINIT_PANIC_ASSERT(rc == 0);
#endif
#if MYNEWT_VAL(BLE_GATTS)
rc = ble_gatts_init();
SYSINIT_PANIC_ASSERT(rc == 0);
#endif
#endif
ble_hs_stop_init();
+14 -5
View File
@@ -45,9 +45,15 @@ ble_hs_conn_can_alloc(void)
return 0;
#endif
return ble_hs_conn_pool.mp_num_free >= 1 &&
ble_l2cap_chan_pool.mp_num_free >= BLE_HS_CONN_MIN_CHANS &&
ble_gatts_conn_can_alloc();
#if MYNEWT_VAL(BLE_GATTS)
return ble_hs_conn_pool.mp_num_free >= 1 &&
ble_l2cap_chan_pool.mp_num_free >= BLE_HS_CONN_MIN_CHANS &&
ble_gatts_conn_can_alloc();
#else
return ble_hs_conn_pool.mp_num_free >= 1 &&
ble_l2cap_chan_pool.mp_num_free >= BLE_HS_CONN_MIN_CHANS;
#endif
}
struct ble_l2cap_chan *
@@ -187,11 +193,12 @@ ble_hs_conn_alloc(uint16_t conn_handle)
if (rc != 0) {
goto err;
}
#if MYNEWT_VAL(BLE_GATTS)
rc = ble_gatts_conn_init(&conn->bhc_gatt_svr);
if (rc != 0) {
goto err;
}
#endif
STAILQ_INIT(&conn->bhc_tx_q);
STAILQ_INIT(&conn->att_tx_q);
@@ -245,7 +252,9 @@ ble_hs_conn_free(struct ble_hs_conn *conn)
return;
}
#if MYNEWT_VAL(BLE_GATTS)
ble_att_svr_prep_clear(&conn->bhc_att_svr.basc_prep_list);
#endif
while ((chan = SLIST_FIRST(&conn->bhc_channels)) != NULL) {
ble_hs_conn_delete_chan(conn, chan);
@@ -543,7 +552,7 @@ ble_hs_conn_timer(void)
}
#endif
#if BLE_HS_ATT_SVR_QUEUED_WRITE_TMO
#if BLE_HS_ATT_SVR_QUEUED_WRITE_TMO && MYNEWT_VAL(BLE_GATTS)
/* Check each connection's rx queued write timer. If too much
* time passes after a prep write is received, the queue is
* cleared.
+4
View File
@@ -33,6 +33,7 @@
#define BLE_HCI_CMD_TIMEOUT_MS 2000
#if MYNEWT_VAL(BLE_ERR_CHECK)
/* HCI ERROR */
#define BLE_ERR_UNKNOWN_HCI_CMD 0x01
#define BLE_ERR_UNK_CONN_ID 0x02
@@ -256,6 +257,7 @@ static void esp_hci_err_to_name(int error_code, uint16_t *opcode)
return;
}
#endif
static struct ble_npl_mutex ble_hs_hci_mutex;
static struct ble_npl_sem ble_hs_hci_sem;
@@ -581,7 +583,9 @@ done:
}
ble_hs_hci_unlock();
#if MYNEWT_VAL(BLE_ERR_CHECK)
esp_hci_err_to_name(rc, &opcode);
#endif
return rc;
}
+6 -2
View File
@@ -289,8 +289,12 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
ev->reason, ev->status);
ble_l2cap_sig_conn_broken(ev->conn_handle, BLE_ERR_CONN_ESTABLISHMENT);
ble_sm_connection_broken(ev->conn_handle);
ble_gatts_connection_broken(ev->conn_handle);
ble_gattc_connection_broken(ev->conn_handle);
#if MYNEWT_VAL(BLE_GATTS)
ble_gatts_connection_broken(ev->conn_handle);
#endif
#if MYNEWT_VAL(BLE_GATTC)
ble_gattc_connection_broken(ev->conn_handle);
#endif
ble_hs_flow_connection_broken(ev->conn_handle);;
#if MYNEWT_VAL(BLE_GATT_CACHING)
ble_gattc_cache_conn_broken(ev->conn_handle);
+10 -12
View File
@@ -32,14 +32,12 @@
#if MYNEWT_VAL(BLE_CRYPTO_STACK_MBEDTLS)
#include "mbedtls/aes.h"
#if MYNEWT_VAL(BLE_SM_SC)
#include "mbedtls/cipher.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/cmac.h"
#include "mbedtls/ecdh.h"
#include "mbedtls/ecp.h"
#endif
#else
#include "tinycrypt/aes.h"
@@ -240,16 +238,6 @@ done:
return rc;
}
#if MYNEWT_VAL(BLE_SM_SC)
static void
ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
{
BLE_HS_LOG(DEBUG, " %s=", name);
ble_hs_log_flat_buf(buf, len);
BLE_HS_LOG(DEBUG, "\n");
}
/**
* Cypher based Message Authentication Code (CMAC) with AES 128 bit
*
@@ -321,6 +309,16 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
}
#endif
#if MYNEWT_VAL(BLE_SM_SC)
static void
ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
{
BLE_HS_LOG(DEBUG, " %s=", name);
ble_hs_log_flat_buf(buf, len);
BLE_HS_LOG(DEBUG, "\n");
}
int
ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
uint8_t z, uint8_t *out_enc_data)
+2 -1
View File
@@ -27,7 +27,6 @@
* use the store/config package. For a RAM-only BLE store,
* use store/config and set BLE_STORE_CONFIG_PERSIST to 0.
*/
#include <inttypes.h>
#include <string.h>
@@ -36,6 +35,7 @@
#include "host/ble_hs.h"
#include "store/ram/ble_store_ram.h"
#if !MYNEWT_VAL(BLE_USED_IN_IDF)
#if MYNEWT_VAL(BLE_STORE_MAX_BONDS)
static struct ble_store_value_sec
ble_store_ram_our_secs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
@@ -787,3 +787,4 @@ ble_store_ram_init(void)
ble_store_ram_num_eads = 0;
#endif
}
#endif //Not used in IDF
+23 -5
View File
@@ -109,6 +109,17 @@ static const char *TAG = "Timer";
struct os_mempool ble_freertos_ev_pool;
static os_membuf_t *ble_freertos_ev_buf = NULL;
#else
struct os_mempool ble_freertos_ev_pool;
static os_membuf_t ble_freertos_ev_buf[
OS_MEMPOOL_SIZE(BLE_TOTAL_EV_COUNT, sizeof (struct ble_npl_event_freertos))
];
#endif
#if CONFIG_BT_CONTROLLER_ENABLED
struct os_mempool ble_freertos_evq_pool;
static os_membuf_t *ble_freertos_evq_buf = NULL;
@@ -123,11 +134,6 @@ static os_membuf_t *ble_freertos_mutex_buf = NULL;
#else
struct os_mempool ble_freertos_ev_pool;
static os_membuf_t ble_freertos_ev_buf[
OS_MEMPOOL_SIZE(BLE_TOTAL_EV_COUNT, sizeof (struct ble_npl_event_freertos))
];
struct os_mempool ble_freertos_evq_pool;
static os_membuf_t ble_freertos_evq_buf[
OS_MEMPOOL_SIZE(BLE_TOTAL_EVQ_COUNT, sizeof (struct ble_npl_eventq_freertos))
@@ -1148,6 +1154,9 @@ int npl_freertos_mempool_init(void)
if(!ble_freertos_ev_buf) {
goto _error;
}
#endif
#if CONFIG_BT_CONTROLLER_ENABLED
ble_freertos_evq_buf = malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_EVQ_COUNT, sizeof (struct ble_npl_eventq_freertos)) * sizeof(os_membuf_t));
if(!ble_freertos_evq_buf) {
goto _error;
@@ -1208,6 +1217,12 @@ _error:
free(ble_freertos_ev_buf);
ble_freertos_ev_buf = NULL;
}
#else
BLE_LL_ASSERT(rc == 0);
return rc;
#endif
#if CONFIG_BT_CONTROLLER_ENABLED
if(ble_freertos_evq_buf) {
free(ble_freertos_evq_buf);
ble_freertos_evq_buf = NULL;
@@ -1239,6 +1254,9 @@ void npl_freertos_mempool_deinit(void)
free(ble_freertos_ev_buf);
ble_freertos_ev_buf = NULL;
}
#endif
#if CONFIG_BT_CONTROLLER_ENABLED
if(ble_freertos_evq_buf) {
free(ble_freertos_evq_buf);
ble_freertos_evq_buf = NULL;