Skip to content

Commit

Permalink
feat(nimble): Added support for Enhanced ATT or ATT over Enhanced L2C…
Browse files Browse the repository at this point in the history
…AP Credit Based Flow Control Mode
  • Loading branch information
SumeetSingh19 committed May 17, 2024
1 parent 1a6060f commit f265e50
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ if(CONFIG_BT_ENABLED)
"host/nimble/nimble/nimble/host/store/config/src/ble_store_nvs.c"
"host/nimble/nimble/nimble/host/src/ble_gattc_cache.c"
"host/nimble/nimble/nimble/host/src/ble_gattc_cache_conn.c"
"host/nimble/nimble/nimble/host/src/ble_eatt.c"
)

if(CONFIG_BT_CONTROLLER_DISABLED AND CONFIG_BT_NIMBLE_TRANSPORT_UART)
Expand Down
7 changes: 7 additions & 0 deletions components/bt/host/nimble/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,10 @@ menu "Host-controller Transport"
help
UART HCI CTS pin
endmenu

config BT_NIMBLE_EATT_CHAN_NUM
int "Maximum number of EATT channels"
default 0
depends on BT_NIMBLE_ENABLED
help
Defines the number of channels EATT bearers can use
2 changes: 1 addition & 1 deletion components/bt/host/nimble/nimble
Submodule nimble updated 46 files
+8 −1 nimble/host/include/host/ble_att.h
+26 −0 nimble/host/include/host/ble_gap.h
+26 −0 nimble/host/include/host/ble_gatt.h
+3 −0 nimble/host/pkg.yml
+1 −1 nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h
+12 −0 nimble/host/services/gatt/src/ble_svc_gatt.c
+162 −19 nimble/host/src/ble_att.c
+106 −69 nimble/host/src/ble_att_clt.c
+46 −8 nimble/host/src/ble_att_cmd.c
+22 −2 nimble/host/src/ble_att_cmd_priv.h
+61 −51 nimble/host/src/ble_att_priv.h
+130 −79 nimble/host/src/ble_att_svr.c
+601 −0 nimble/host/src/ble_eatt.c
+58 −0 nimble/host/src/ble_eatt_priv.h
+21 −0 nimble/host/src/ble_gap.c
+1 −0 nimble/host/src/ble_gap_priv.h
+21 −19 nimble/host/src/ble_gatt_priv.h
+325 −104 nimble/host/src/ble_gattc.c
+6 −2 nimble/host/src/ble_hs.c
+1 −0 nimble/host/src/ble_hs_conn.c
+6 −0 nimble/host/src/ble_hs_conn_priv.h
+1 −0 nimble/host/src/ble_hs_priv.h
+1 −1 nimble/host/src/ble_l2cap_coc.c
+37 −0 nimble/host/syscfg.yml
+36 −17 nimble/host/test/src/ble_att_clt_test.c
+14 −13 nimble/host/test/src/ble_att_svr_test.c
+36 −0 nimble/host/test/src/ble_gatt_conn_test.c
+17 −15 nimble/host/test/src/ble_gatt_disc_c_test.c
+13 −11 nimble/host/test/src/ble_gatt_disc_d_test.c
+26 −26 nimble/host/test/src/ble_gatt_disc_s_test.c
+19 −18 nimble/host/test/src/ble_gatt_find_s_test.c
+23 −21 nimble/host/test/src/ble_gatt_read_test.c
+37 −36 nimble/host/test/src/ble_gatt_write_test.c
+5 −4 nimble/host/test/src/ble_hs_test_util.c
+4 −2 nimble/host/test/src/ble_hs_test_util.h
+1 −0 nimble/host/test/syscfg.yml
+4 −0 nimble/include/nimble/nimble_opt_auto.h
+7 −0 porting/examples/linux/include/logcfg/logcfg.h
+24 −0 porting/examples/linux/include/syscfg/syscfg.h
+7 −0 porting/examples/linux_blemesh/include/logcfg/logcfg.h
+24 −0 porting/examples/linux_blemesh/include/syscfg/syscfg.h
+4 −0 porting/examples/nuttx/include/syscfg/syscfg.h
+7 −0 porting/nimble/include/logcfg/logcfg.h
+24 −0 porting/nimble/include/syscfg/syscfg.h
+7 −0 porting/npl/riot/include/logcfg/logcfg.h
+24 −0 porting/npl/riot/include/syscfg/syscfg.h
62 changes: 61 additions & 1 deletion components/bt/host/nimble/port/include/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@
#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1)
#endif

#ifndef MYNEWT_VAL_BLE_ATT_SVR_NOTIFY_MULTI
#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY_MULTI (1)
#endif

#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE
#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1)
#endif
Expand All @@ -567,6 +571,10 @@
#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1)
#endif

#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_MULT_VAR
#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT_VAR (1)
#endif

#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE
#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1)
#endif
Expand All @@ -583,6 +591,40 @@
#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1)
#endif

#ifndef MYNEWT_VAL_BLE_EATT_CHAN_NUM
#define MYNEWT_VAL_BLE_EATT_CHAN_NUM (CONFIG_BT_NIMBLE_EATT_CHAN_NUM)
#endif

#ifndef MYNEWT_VAL_BLE_EATT_LOG_LVL
#define MYNEWT_VAL_BLE_EATT_LOG_LVL (1)
#endif

#ifndef MYNEWT_VAL_BLE_EATT_LOG_MOD
#define MYNEWT_VAL_BLE_EATT_LOG_MOD (27)
#endif

#ifndef MYNEWT_VAL_BLE_EATT_MTU
#define MYNEWT_VAL_BLE_EATT_MTU (128)
#endif

#ifndef MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES
#if CONFIG_BT_NIMBLE_EATT_CHAN_NUM
#define MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES_EATT (2)
#else
#define MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES_EATT (0)
#endif //CONFIG_BT_NIMBLE_EATT_CHAN_NUM

#if MYNEWT_VAL_BLE_ATT_SVR_NOTIFY_MULTI
#define MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES_NOTIFY_MULTI (4)
#else
#define MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES_NOTIFY_MULTI (0)
#endif //MYNEWT_VAL_BLE_ATT_SVR_NOTIFY_MULTI
#define MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES ( \
MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES_EATT | \
MYNEWT_VAL_BLE_CLIENT_SUPPORTED_FEATURES_NOTIFY_MULTI \
)
#endif //MYNEWT_VAL_CLIENT_SUPPORTED_FEATURES

#ifndef MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE
#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1)
#endif
Expand Down Expand Up @@ -623,6 +665,10 @@
#define MYNEWT_VAL_BLE_GATT_NOTIFY (1)
#endif

#ifndef MYNEWT_VAL_BLE_GATT_MULTI_NOTIFY
#define MYNEWT_VAL_BLE_GATT_MULTI_NOTIFY (1)
#endif

#ifndef MYNEWT_VAL_BLE_GATT_READ
#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#endif
Expand Down Expand Up @@ -749,16 +795,26 @@
#define MYNEWT_VAL_BLE_HS_SYSINIT_STAGE (200)
#endif

#if CONFIG_BT_NIMBLE_EATT_CHAN_NUM
#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (CONFIG_BT_NIMBLE_EATT_CHAN_NUM)
#else
#ifndef CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM
#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (2)
#else
#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM
#endif
#endif //CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM
#endif //CONFIG_BT_NIMBLE_EATT_CHAN_NUM

#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MPS
#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE-8)
#endif

#if CONFIG_BT_NIMBLE_EATT_CHAN_NUM
#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (1)
#else
#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (0)
#endif

#ifndef MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS
#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1)
#endif
Expand All @@ -772,8 +828,12 @@
#endif

#ifndef MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS
#ifdef CONFIG_BT_NIMBLE_EATT_CHAN_NUM
#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (CONFIG_BT_NIMBLE_EATT_CHAN_NUM)
#else
#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1)
#endif
#endif

#ifndef MYNEWT_VAL_BLE_MESH
#ifdef CONFIG_BT_NIMBLE_MESH
Expand Down
4 changes: 4 additions & 0 deletions components/bt/porting/nimble/include/nimble/nimble_opt_auto.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ extern "C" {
#define NIMBLE_BLE_ATT_CLT_INDICATE \
(MYNEWT_VAL(BLE_GATT_INDICATE))

#undef NIMBLE_BLE_ATT_CLT_MULTI_NOTIFY
#define NIMBLE_BLE_ATT_CLT_MULTI_NOTIFY \
(MYNEWT_VAL(BLE_GATT_MULTI_NOTIFY))

/** Security manager settings. */

#undef NIMBLE_BLE_SM
Expand Down
79 changes: 74 additions & 5 deletions examples/bluetooth/nimble/blecent/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#endif
#endif

/*** The UUID of the service containing the subscribable characterstic ***/
/*** The UUID of the service containing the subscribable characteristic ***/
static const ble_uuid_t * remote_svc_uuid =
BLE_UUID128_DECLARE(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
Expand All @@ -62,6 +62,11 @@ static const char *tag = "NimBLE_BLE_CENT";
static int blecent_gap_event(struct ble_gap_event *event, void *arg);
static uint8_t peer_addr[6];

#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
static uint16_t cids[MYNEWT_VAL(BLE_EATT_CHAN_NUM)];
static uint16_t bearers;
#endif

void ble_store_config_init(void);

/**
Expand Down Expand Up @@ -203,7 +208,7 @@ blecent_custom_gatt_operations(const struct peer* peer)
remote_chr_uuid,
BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16));
if (dsc == NULL) {
MODLOG_DFLT(ERROR, "Error: Peer lacks a CCCD for the subscribable characterstic\n");
MODLOG_DFLT(ERROR, "Error: Peer lacks a CCCD for the subscribable characteristic\n");
goto err;
}

Expand Down Expand Up @@ -687,7 +692,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}

/* An advertisment report was received during GAP discovery. */
/* An advertisement report was received during GAP discovery. */
print_adv_fields(&fields);

/* Try to connect to the advertiser if it looks interesting. */
Expand Down Expand Up @@ -773,6 +778,14 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
/* Forget about peer. */
peer_delete(event->disconnect.conn.conn_handle);

#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
/* Reset EATT config */
bearers = 0;
for (int i = 0; i < MYNEWT_VAL(BLE_EATT_CHAN_NUM); i++) {
cids[i] = 0;
}
#endif

/* Resume scanning. */
blecent_scan();
return 0;
Expand All @@ -789,14 +802,16 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
assert(rc == 0);
print_conn_desc(&desc);
#if !MYNEWT_VAL(BLE_EATT_CHAN_NUM)
#if CONFIG_EXAMPLE_ENCRYPTION
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
rc = peer_disc_all(event->enc_change.conn_handle,
blecent_on_disc_complete, NULL);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif
return 0;

Expand Down Expand Up @@ -840,7 +855,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)

#if CONFIG_EXAMPLE_EXTENDED_ADV
case BLE_GAP_EVENT_EXT_DISC:
/* An advertisment report was received during GAP discovery. */
/* An advertisement report was received during GAP discovery. */
ext_print_adv_report(&event->disc);

blecent_connect_if_interesting(&event->disc);
Expand Down Expand Up @@ -868,6 +883,52 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
event->pathloss_threshold.zone_entered);
return 0;
#endif

#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
case BLE_GAP_EVENT_EATT:
int i;
MODLOG_DFLT(INFO, "EATT %s : conn_handle=%d cid=%d",
event->eatt.status ? "disconnected" : "connected",
event->eatt.conn_handle,
event->eatt.cid);
if (event->eatt.status) {
/* Remove CID from the list of saved CIDs */
for (i = 0; i < bearers; i++) {
if (cids[i] == event->eatt.cid) {
break;
}
}
while (i < (bearers - 1)) {
cids[i] = cids[i + 1];
i += 1;
}
cids[i] = 0;

/* Now Abort */
return 0;
}
cids[bearers] = event->eatt.cid;
bearers += 1;
if (bearers != MYNEWT_VAL(BLE_EATT_CHAN_NUM)) {
/* Wait until all EATT bearers are connected before proceeding */
return 0;
}
/* Set the default bearer to use for further procedures */
rc = ble_att_set_default_bearer_using_cid(event->eatt.conn_handle, cids[0]);
if (rc != 0) {
MODLOG_DFLT(INFO, "Cannot set default EATT bearer, rc = %d\n", rc);
return rc;
}

/* Perform service discovery */
rc = peer_disc_all(event->eatt.conn_handle,
blecent_on_disc_complete, NULL);
if(rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
return 0;
default:
return 0;
}
Expand All @@ -888,6 +949,7 @@ blecent_on_sync(void)
rc = ble_hs_util_ensure_addr(0);
assert(rc == 0);


#if !CONFIG_EXAMPLE_INIT_DEINIT_LOOP
/* Begin scanning for a peripheral to connect to. */
blecent_scan();
Expand Down Expand Up @@ -979,4 +1041,11 @@ app_main(void)
stack_init_deinit();
#endif

#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
bearers = 0;
for (int i = 0; i < MYNEWT_VAL(BLE_EATT_CHAN_NUM); i++) {
cids[i] = 0;
}
#endif

}
38 changes: 37 additions & 1 deletion examples/bluetooth/nimble/bleprph/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ static uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
static uint8_t own_addr_type;
#endif

#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
static uint16_t cids[MYNEWT_VAL(BLE_EATT_CHAN_NUM)];
static uint16_t bearers;
#endif

void ble_store_config_init(void);

/**
Expand Down Expand Up @@ -416,13 +421,37 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
event->transmit_power.delta);
return 0;

case BLE_GAP_EVENT_PATHLOSS_THRESHOLD:
case BLE_GAP_EVENT_PATHLOSS_THRESHOLD:
MODLOG_DFLT(INFO, "Pathloss threshold event : conn_handle=%d current path loss=%d "
"zone_entered =%d",
event->pathloss_threshold.conn_handle,
event->pathloss_threshold.current_path_loss,
event->pathloss_threshold.zone_entered);
return 0;
#endif
#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
case BLE_GAP_EVENT_EATT:
MODLOG_DFLT(INFO, "EATT %s : conn_handle=%d cid=%d",
event->eatt.status ? "disconnected" : "connected",
event->eatt.conn_handle,
event->eatt.cid);
if (event->eatt.status) {
/* Abort if disconnected */
return 0;
}
cids[bearers] = event->eatt.cid;
bearers += 1;
if (bearers != MYNEWT_VAL(BLE_EATT_CHAN_NUM)) {
/* Wait until all EATT bearers are connected before proceeding */
return 0;
}
/* Set the default bearer to use for further procedures */
rc = ble_att_set_default_bearer_using_cid(event->eatt.conn_handle, cids[0]);
if (rc != 0) {
MODLOG_DFLT(INFO, "Cannot set default EATT bearer, rc = %d\n", rc);
return rc;
}
return 0;
#endif
}

Expand Down Expand Up @@ -566,4 +595,11 @@ app_main(void)
if (rc != ESP_OK) {
ESP_LOGE(tag, "scli_init() failed");
}

#if MYNEWT_VAL(BLE_EATT_CHAN_NUM)
bearers = 0;
for (int i = 0; i < MYNEWT_VAL(BLE_EATT_CHAN_NUM); i++) {
cids[i] = 0;
}
#endif
}

0 comments on commit f265e50

Please sign in to comment.