fix(nimble): Address compilation issues in nimble examples

This commit is contained in:
Rahul Tank
2025-10-13 10:50:19 +05:30
parent 7a9eee11fd
commit f18519da4e
33 changed files with 171 additions and 32 deletions
+1 -1
View File
@@ -568,7 +568,7 @@ menu "BLE 5.x Features"
config BT_NIMBLE_EXT_SCAN
bool "Enable extended scanning"
depends on BT_NIMBLE_50_FEATURE_SUPPORT && BT_NIMBLE_ROLE_OBSERVER
depends on BT_NIMBLE_50_FEATURE_SUPPORT
default y
help
Enable this option to do extended scanning.
@@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_log.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_SVC_GAP_TAG "ble_svc_gap"
/**
* Stub implementations for GAP service APIs.
* These are compiled when CONFIG_BT_NIMBLE_GAP_SERVICE is disabled.
*/
static inline void ble_svc_gap_init(void)
{
ESP_LOGE(BLE_SVC_GAP_TAG, "GAP service not enabled. Enable CONFIG_BT_NIMBLE_GAP_SERVICE to use this API.");
}
static inline int ble_svc_gap_device_name_set(const char *name)
{
(void)name;
ESP_LOGE(BLE_SVC_GAP_TAG, "GAP service not enabled. Enable CONFIG_BT_NIMBLE_GAP_SERVICE to use this API.");
return -1;
}
static inline const char *ble_svc_gap_device_name(void)
{
ESP_LOGE(BLE_SVC_GAP_TAG, "GAP service not enabled. Enable CONFIG_BT_NIMBLE_GAP_SERVICE to use this API.");
return NULL;
}
static inline int ble_svc_gap_device_appearance_set(uint16_t appearance)
{
ESP_LOGE(BLE_SVC_GAP_TAG, "GAP service not enabled. Enable CONFIG_BT_NIMBLE_GAP_SERVICE to use this API.");
return -1;
}
static inline int ble_svc_gap_device_key_material_set(uint8_t *session_key, uint8_t *iv)
{
ESP_LOGE(BLE_SVC_GAP_TAG, "GAP service not enabled. Enable CONFIG_BT_NIMBLE_GAP_SERVICE to use this API.");
return -1;
}
#ifdef __cplusplus
}
#endif
@@ -1793,9 +1793,11 @@
#endif
/*** @apache-mynewt-nimble/nimble/host/services/gap */
#ifdef CONFIG_BT_NIMBLE_GAP_SERVICE
#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE
#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE
#endif
#endif
#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM
#if CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE_PERM
@@ -1808,10 +1810,12 @@
#endif //CONFIG_BT_NIMBLE_SVC_GAP_APPEAR_WRITE_PERM
#endif //MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM
#ifdef CONFIG_BT_NIMBLE_GAP_SERVICE
#ifndef MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION
#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION \
CONFIG_BT_NIMBLE_SVC_GAP_CENT_ADDR_RESOLUTION
#endif
#endif
#ifndef CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME
#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME "nimble"
@@ -1819,9 +1823,11 @@
#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME
#endif
#ifdef CONFIG_BT_NIMBLE_GAP_SERVICE
#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH
#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN // According to the specification, the maximum length should be 248
#endif
#endif
#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM
#if CONFIG_BT_NIMBLE_SVC_GAP_NAME_WRITE_PERM
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -534,6 +534,7 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg)
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init(cfg);
if (rc != 0) {
ESP_LOGE(TAG, "Error initializing GATT server");
@@ -552,6 +553,7 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg)
resp_data.name_len = strlen(ble_svc_gap_device_name());
resp_data.name_is_complete = 1;
}
#endif
/* Set manufacturer data if protocomm_ble_mfg_data points to valid data */
if (protocomm_ble_mfg_data != NULL) {
@@ -78,12 +78,14 @@ void app_main(void) {
return;
}
#if CONFIG_BT_NIMBLE_GAP_SERVICE
/* GAP service initialization */
rc = gap_init();
if (rc != 0) {
ESP_LOGE(TAG, "failed to initialize GAP service, error code: %d", rc);
return;
}
#endif
/* NimBLE host configuration initialization */
nimble_host_config_init();
@@ -82,12 +82,14 @@ void app_main(void) {
return;
}
#if CONFIG_BT_NIMBLE_GAP_SERVICE
/* GAP service initialization */
rc = gap_init();
if (rc != 0) {
ESP_LOGE(TAG, "failed to initialize GAP service, error code: %d", rc);
return;
}
#endif
/* NimBLE host configuration initialization */
nimble_host_config_init();
@@ -251,6 +251,7 @@ int gap_init(void) {
/* Local variables */
int rc = 0;
/* Initialize GAP service */
ble_svc_gap_init();
@@ -109,12 +109,14 @@ void app_main(void) {
return;
}
#if CONFIG_BT_NIMBLE_GAP_SERVICE
/* GAP service initialization */
rc = gap_init();
if (rc != 0) {
ESP_LOGE(TAG, "failed to initialize GAP service, error code: %d", rc);
return;
}
#endif
/* GATT server initialization */
rc = gatt_svc_init();
@@ -118,12 +118,14 @@ void app_main(void) {
return;
}
#if CONFIG_BT_NIMBLE_GAP_SERVICE
/* GAP service initialization */
rc = gap_init();
if (rc != 0) {
ESP_LOGE(TAG, "failed to initialize GAP service, error code: %d", rc);
return;
}
#endif
/* GATT server initialization */
rc = gatt_svc_init();
@@ -44,6 +44,7 @@ void printtime(struct ble_svc_cts_curr_time ctime) {
ESP_LOGI(tag, "fractions : %d\n", ctime.et_256.fractions_256);
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Application callback. Called when the read of the cts current time
* characteristic has completed.
@@ -137,6 +138,7 @@ ble_cts_cent_on_disc_complete(const struct peer *peer, int status, void *arg)
*/
ble_cts_cent_read_time(peer);
}
#endif
/**
* Initiates the GAP general discovery procedure.
@@ -434,6 +436,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#else
#if MYNEWT_VAL(BLE_GATTC)
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
ble_cts_cent_on_disc_complete, NULL);
@@ -441,6 +444,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
} else {
@@ -485,6 +489,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#else
#if MYNEWT_VAL(BLE_GATTC)
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
ble_cts_cent_on_disc_complete, NULL);
@@ -492,6 +497,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
return 0;
@@ -28,7 +28,6 @@ static uint8_t ext_adv_pattern_1[] = {
static const char *tag = "NimBLE_CTS_PRPH";
static const char *device_name = "ble_cts_prph";
static int ble_cts_prph_gap_event(struct ble_gap_event *event, void *arg);
static uint8_t ble_cts_prph_addr_type;
@@ -274,8 +273,6 @@ void ble_cts_prph_host_task(void *param)
void app_main(void)
{
int rc;
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -302,12 +299,15 @@ void app_main(void)
ble_hs_cfg.sm_sc = 1;
ble_hs_cfg.sm_mitm = 1;
#if MYNEWT_VAL(BLE_GATTS)
int rc;
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name */
rc = ble_svc_gap_device_name_set(device_name);
assert(rc == 0);
#endif
/* Start the task */
nimble_port_freertos_init(ble_cts_prph_host_task);
@@ -280,12 +280,14 @@ app_main(void)
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("ble-dynamic-service");
assert(rc == 0);
#endif
nimble_port_freertos_init(dynamic_service_host_task);
@@ -22,7 +22,10 @@ static struct km_peer kmp[CONFIG_BT_NIMBLE_MAX_CONNECTIONS + 1] = {0};
static const char *tag = "ENC_ADV_DATA_CENT";
static int enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg);
#if MYNEWT_VAL(BLE_GATTC)
static int mtu_def = 512;
#endif
void ble_store_config_init(void);
@@ -37,6 +40,7 @@ enc_adv_data_find_peer(const uint8_t *peer_addr)
return -1;
}
#if MYNEWT_VAL(BLE_GATTC)
static int
enc_adv_data_set_km_exist(const uint8_t *peer_addr)
{
@@ -47,6 +51,7 @@ enc_adv_data_set_km_exist(const uint8_t *peer_addr)
kmp[ind].key_material_exist = true;
return 0;
}
#endif
static bool
enc_adv_data_check_km_exist(const uint8_t *peer_addr)
@@ -60,6 +65,7 @@ enc_adv_data_check_km_exist(const uint8_t *peer_addr)
return kmp[ind].key_material_exist;
}
#if MYNEWT_VAL(BLE_GATTC)
/**
* Application callback. Called when the read has completed.
*/
@@ -175,6 +181,7 @@ enc_adv_data_cent_on_disc_complete(const struct peer *peer, int status, void *ar
enc_adv_data_cent_read(peer);
}
}
#endif
/**
* Initiates the GAP general discovery procedure.
@@ -444,6 +451,7 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg)
print_conn_desc(&desc);
MODLOG_DFLT(INFO, "");
#if MYNEWT_VAL(BLE_GATTC)
rc = ble_att_set_preferred_mtu(mtu_def);
if (rc != 0) {
ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc);
@@ -453,6 +461,7 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg)
if (rc != 0) {
ESP_LOGE(tag, "Failed to negotiate MTU; rc = %d", rc);
}
#endif
/* Remember peer. */
rc = peer_add(event->connect.conn_handle);
@@ -511,12 +520,14 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg)
assert(rc == 0);
print_conn_desc(&desc);
#if MYNEWT_VAL(BLE_GATTC)
/* Perform service discovery */
rc = peer_disc_all(event->enc_change.conn_handle,
enc_adv_data_cent_on_disc_complete, NULL);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
}
#endif
return 0;
case BLE_GAP_EVENT_NOTIFY_RX:
@@ -413,15 +413,16 @@ app_main(void)
ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ID;
#endif
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("enc_adv_data_prph");
assert(rc == 0);
#endif
/* Set the session key and initialization vector */
rc = ble_svc_gap_device_key_material_set(km.session_key, km.iv);
assert(rc == 0);
@@ -20,6 +20,8 @@ static int ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg);
void ble_store_config_init(void);
static void ble_htp_cent_scan(void);
#if MYNEWT_VAL(BLE_GATTC)
/**
* Application callback. Called when the attempt to subscribe to notifications
* for the HTP intermediate temperature characteristic has completed.
@@ -255,7 +257,7 @@ ble_htp_cent_on_disc_complete(const struct peer *peer, int status, void *arg)
*/
ble_htp_cent_read_write_subscribe(peer);
}
#endif
/**
* Initiates the GAP general discovery procedure.
*/
@@ -548,6 +550,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#else
#if MYNEWT_VAL(BLE_GATTC)
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
ble_htp_cent_on_disc_complete, NULL);
@@ -555,6 +558,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
} else {
@@ -599,6 +603,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#else
#if MYNEWT_VAL(BLE_GATTC)
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
ble_htp_cent_on_disc_complete, NULL);
@@ -606,6 +611,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
return 0;
@@ -201,6 +201,8 @@ ble_htp_prph_tx_htp_reset(void)
static void
ble_htp_prph_tx(TimerHandle_t ev)
{
#if CONFIG_BT_NIMBLE_HTP_SERVICE
int rc;
float temp;
@@ -222,6 +224,7 @@ ble_htp_prph_tx(TimerHandle_t ev)
} else {
MODLOG_DFLT(INFO, "Error in sending notification");
}
#endif
ble_htp_prph_tx_htp_reset();
}
@@ -259,7 +262,9 @@ ble_htp_prph_gap_event(struct ble_gap_event *event, void *arg)
#endif
ble_htp_prph_tx_htp_stop();
#if CONFIG_BT_NIMBLE_HTP_SERVICE
ble_svc_htp_on_disconnect(event->disconnect.conn.conn_handle);
#endif
break;
case BLE_GAP_EVENT_ADV_COMPLETE:
@@ -276,7 +281,9 @@ ble_htp_prph_gap_event(struct ble_gap_event *event, void *arg)
"val_handle=%d\n",
event->subscribe.cur_notify, event->subscribe.attr_handle);
#if CONFIG_BT_NIMBLE_HTP_SERVICE
ble_svc_htp_subscribe(event->subscribe.conn_handle, event->subscribe.attr_handle);
#endif
if (event->subscribe.cur_notify) {
ble_htp_prph_tx_htp_reset();
@@ -336,8 +343,6 @@ void ble_htp_prph_host_task(void *param)
void app_main(void)
{
int rc;
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -368,12 +373,15 @@ void app_main(void)
ble_htp_prph_tx_timer = xTimerCreate("ble_htp_prph_tx_timer", pdMS_TO_TICKS(1000), pdTRUE,
(void *)0, ble_htp_prph_tx);
#if MYNEWT_VAL(BLE_GATTS)
int rc;
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name */
rc = ble_svc_gap_device_name_set(device_name);
assert(rc == 0);
#endif
/* Start the task */
nimble_port_freertos_init(ble_htp_prph_host_task);
@@ -133,7 +133,6 @@ bleprph_advertise(void)
{
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
/**
@@ -160,6 +159,7 @@ bleprph_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
const char *name;
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
@@ -459,8 +459,6 @@ void ble_multi_adv_host_task(void *param)
void
app_main(void)
{
int rc;
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -495,6 +493,8 @@ app_main(void)
ble_instance_cb[i].cb = NULL;
}
#if MYNEWT_VAL(BLE_GATTS)
int rc;
rc = gatt_svr_init();
assert(rc == 0);
@@ -502,6 +502,7 @@ app_main(void)
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-multi-adv");
assert(rc == 0);
#endif
#endif
/* XXX Need to have template for store */
@@ -461,12 +461,16 @@ app_main(void)
rc = peer_init(BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM);
assert(rc == 0);
#endif
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name. We will act as both central and peripheral. */
rc = ble_svc_gap_device_name_set("esp-ble-role-coex");
assert(rc == 0);
rc = gatt_svr_init();
assert(rc == 0);
#endif
/* XXX Need to have template for store */
ble_store_config_init();
@@ -287,12 +287,14 @@ app_main(void)
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("esp-multi-conn");
assert(rc == 0);
#endif
/* XXX Need to have template for store */
ble_store_config_init();
@@ -24,6 +24,7 @@ static void blecent_scan(void);
static uint8_t s_current_phy;
void ble_store_config_init(void);
#if MYNEWT_VAL(BLE_GATTC)
/**
* Performs GATT operation against the specified peer:
* 1. Reads the Supported LE PHY characteristic.
@@ -167,6 +168,7 @@ blecent_on_disc_complete(const struct peer *peer, int status, void *arg)
blecent_read(peer);
}
#endif
/* Set default LE PHY before establishing connection */
void set_default_le_phy(uint8_t tx_phys_mask, uint8_t rx_phys_mask)
@@ -388,6 +390,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#if MYNEWT_VAL(BLE_GATTC)
/* Perform service discovery. */
rc = peer_disc_all(event->connect.conn_handle,
blecent_on_disc_complete, NULL);
@@ -395,6 +398,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
} else {
/* Connection attempt failed; resume scanning. */
MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n",
@@ -342,8 +342,10 @@ app_main(void)
ble_hs_cfg.sm_their_key_dist = 1;
#endif
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init_le_phy();
assert(rc == 0);
#endif
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("bleprph-phy");
@@ -33,6 +33,7 @@ void ble_store_config_init(void);
static void ble_prox_cent_scan(void);
static int ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg);
#if MYNEWT_VAL(BLE_GATTC)
static int
ble_prox_cent_on_read(uint16_t conn_handle,
const struct ble_gatt_error *error,
@@ -172,6 +173,7 @@ ble_prox_cent_on_disc_complete(const struct peer *peer, int status, void *arg)
*/
ble_prox_cent_read_write_subscribe(peer);
}
#endif
/**
* Initiates the GAP general discovery procedure.
@@ -480,6 +482,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#else
#if MYNEWT_VAL(BLE_GATTC)
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
ble_prox_cent_on_disc_complete, NULL);
@@ -487,6 +490,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
} else {
@@ -547,6 +551,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#else
#if MYNEWT_VAL(BLE_GATTC)
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
ble_prox_cent_on_disc_complete, NULL);
@@ -554,6 +559,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
return 0;
@@ -656,6 +662,7 @@ ble_prox_cent_path_loss_task(void *pvParameters)
path_loss = 0;
}
#if MYNEWT_VAL(BLE_GATTC)
rc = ble_gattc_write_no_rsp_flat(i, conn_peer[i].val_handle,
&path_loss, sizeof(path_loss));
if (rc != 0) {
@@ -664,6 +671,7 @@ ble_prox_cent_path_loss_task(void *pvParameters)
} else {
MODLOG_DFLT(INFO, "Write to alert level characteristis done");
}
#endif
}
}
}
@@ -743,7 +751,6 @@ app_main(void)
/* Initialize a task to keep checking path loss of the link */
ble_prox_cent_init();
for (int i = 0; i <= MYNEWT_VAL(BLE_MAX_CONNECTIONS); i++) {
disconn_peer[i].addr = NULL;
disconn_peer[i].link_lost = true;
@@ -270,8 +270,6 @@ void ble_prox_prph_host_task(void *param)
void app_main(void)
{
int rc;
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -286,9 +284,10 @@ void app_main(void)
return;
}
#if CONFIG_BT_NIMBLE_PROX_SERVICE
/* Initialize a task to keep checking path loss of the link */
ble_svc_prox_init();
#endif
/* Initialize the NimBLE host configuration */
ble_hs_cfg.sync_cb = ble_prox_prph_on_sync;
ble_hs_cfg.reset_cb = ble_prox_prph_on_reset;
@@ -301,6 +300,7 @@ void app_main(void)
ble_hs_cfg.sm_sc = 1;
ble_hs_cfg.sm_mitm = 1;
int rc;
/* Set the default device name */
rc = ble_svc_gap_device_name_set(device_name);
assert(rc == 0);
@@ -26,6 +26,7 @@ uint16_t attribute_handle[CONFIG_BT_NIMBLE_MAX_CONNECTIONS + 1];
static void ble_spp_client_scan(void);
static ble_addr_t connected_addr[CONFIG_BT_NIMBLE_MAX_CONNECTIONS + 1];
#if MYNEWT_VAL(BLE_GATTC)
static void ble_spp_client_write_subscribe(const struct peer *peer)
{
uint8_t value[2];
@@ -90,7 +91,6 @@ ble_spp_client_set_handle(const struct peer *peer)
value, sizeof(value), NULL, NULL);
}
/**
* Called when service discovery of the specified peer has completed.
*/
@@ -119,6 +119,7 @@ ble_spp_client_on_disc_complete(const struct peer *peer, int status, void *arg)
ble_spp_client_scan();
#endif
}
#endif
/**
* Initiates the GAP general discovery procedure.
@@ -306,6 +307,7 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
#if MYNEWT_VAL(BLE_GATTC)
/* Perform service discovery. */
rc = peer_disc_all(event->connect.conn_handle,
ble_spp_client_on_disc_complete, NULL);
@@ -313,6 +315,7 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
} else {
/* Connection attempt failed; resume scanning. */
MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n",
@@ -421,12 +424,14 @@ void ble_client_uart_task(void *pvParameters)
uart_read_bytes(UART_NUM_0, temp, event.size, portMAX_DELAY);
for ( i = 0; i <= CONFIG_BT_NIMBLE_MAX_CONNECTIONS; i++) {
if (attribute_handle[i] != 0) {
#if MYNEWT_VAL(BLE_GATTC)
rc = ble_gattc_write_flat(i, attribute_handle[i], temp, event.size, NULL, NULL);
if (rc == 0) {
ESP_LOGI(tag, "Write in uart task success!");
} else {
ESP_LOGI(tag, "Error in writing characteristic rc=%d", rc);
}
#endif
vTaskDelay(10);
}
}
@@ -63,7 +63,6 @@ ble_spp_server_advertise(void)
{
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
/**
@@ -90,6 +89,7 @@ ble_spp_server_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
const char *name;
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
@@ -412,8 +412,6 @@ static void ble_spp_uart_init(void)
void
app_main(void)
{
int rc;
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -459,6 +457,8 @@ app_main(void)
ble_hs_cfg.sm_their_key_dist = 1;
#endif
#if MYNEWT_VAL(BLE_GATTS)
int rc;
/* Register custom service */
rc = gatt_svr_init();
assert(rc == 0);
@@ -466,6 +466,7 @@ app_main(void)
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-ble-spp-svr");
assert(rc == 0);
#endif
/* XXX Need to have template for store */
ble_store_config_init();
@@ -293,12 +293,14 @@ void app_main(void)
/* name, period/time, auto reload, timer ID, callback */
blehr_tx_timer = xTimerCreate("blehr_tx_timer", pdMS_TO_TICKS(1000), pdTRUE, (void *)0, blehr_tx_hrate);
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name */
rc = ble_svc_gap_device_name_set(device_name);
assert(rc == 0);
#endif
/* Start the task */
nimble_port_freertos_init(blehr_host_task);
@@ -131,7 +131,6 @@ bleprph_advertise(void)
{
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
/**
@@ -158,6 +157,7 @@ bleprph_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
const char *name;
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
@@ -528,12 +528,14 @@ app_main(void)
ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ID;
#endif
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-bleprph");
assert(rc == 0);
#endif
/* XXX Need to have template for store */
ble_store_config_init();
@@ -311,7 +311,6 @@ bleprph_advertise(void)
{
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
/**
@@ -338,6 +337,7 @@ bleprph_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
const char *name;
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
@@ -525,8 +525,6 @@ void bleprph_host_task(void *param)
void
app_main(void)
{
int rc;
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -550,12 +548,15 @@ app_main(void)
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
#if MYNEWT_VAL(BLE_GATTS)
int rc;
rc = gatt_svr_init();
assert(rc == 0);
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-bleprph");
assert(rc == 0);
#endif
/* XXX Need to have template for store */
ble_store_config_init();
@@ -167,7 +167,6 @@ bleprph_advertise(void)
{
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;
/**
@@ -194,6 +193,7 @@ bleprph_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
const char *name;
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
@@ -620,6 +620,7 @@ app_main(void)
ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ID;
#endif
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
@@ -627,6 +628,7 @@ app_main(void)
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-bleprph");
assert(rc == 0);
#endif
#endif
/* XXX Need to have template for store */
@@ -945,6 +945,7 @@ app_main(void)
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
assert(rc == 0);
#endif
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("gattc-throughput");
assert(rc == 0);
@@ -26,10 +26,10 @@ static uint8_t ext_adv_pattern[] = {
};
static uint8_t s_current_phy;
#else
static const char *device_name = "nimble_prph";
#endif
static const char *device_name = "nimble_prph";
#define NOTIFY_THROUGHPUT_PAYLOAD 495
#define MIN_REQUIRED_MBUF 2 /* Assuming payload of 500Bytes and each mbuf can take 292Bytes. */
#define PREFERRED_MTU_VALUE 512
@@ -509,10 +509,10 @@ void app_main(void)
/* Initialize Notify Task */
xTaskCreate(notify_task, "notify_task", 4096, NULL, 10, NULL);
#if MYNEWT_VAL(BLE_GATTS)
rc = gatt_svr_init();
assert(rc == 0);
#if !(CONFIG_EXAMPLE_EXTENDED_ADV)
/* Set the default device name */
rc = ble_svc_gap_device_name_set(device_name);
assert(rc == 0);