diff --git a/nimble/host/include/host/ble_hs.h b/nimble/host/include/host/ble_hs.h index 677b16dcb..9e42a3265 100644 --- a/nimble/host/include/host/ble_hs.h +++ b/nimble/host/include/host/ble_hs.h @@ -247,6 +247,15 @@ struct ble_hs_cfg { */ unsigned sm_keypress:1; + /** @brief Enable/Disable Enhanced ATT Support + * + * Primarily used to enable EATT behaviour; denotes the number of eatt + * channels. Set to 0 to disable eatt. + * + * Default value is CONFIG_BT_NIMBLE_EATT_CHAN_NUM. + */ + uint8_t eatt; + /** @brief Security Manager Local Key Distribution Mask */ uint8_t sm_our_key_dist; diff --git a/nimble/host/services/dis/include/services/dis/ble_svc_dis.h b/nimble/host/services/dis/include/services/dis/ble_svc_dis.h index d9ae55d42..b4fa3bced 100644 --- a/nimble/host/services/dis/include/services/dis/ble_svc_dis.h +++ b/nimble/host/services/dis/include/services/dis/ble_svc_dis.h @@ -46,12 +46,12 @@ #define BLE_SVC_DIS_CHR_UUID16_PNP_ID 0x2A50 #define BLE_SVC_DIS_CHR_UUID16_UDI 0x2BFF -#if MYNEWT_VAL(BLE_SVC_DIS_INCLUDED) -/** One PTS Case requires this DIS to be included. */ +/* One PTS Case requires DIS to be included. + * The UUID below is randomly chosen. + */ static const ble_uuid128_t ble_svc_dis_include_uuid = BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12, 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0xFF); -#endif /** * Structure holding data for the main characteristics @@ -123,6 +123,11 @@ extern struct ble_svc_dis_data ble_svc_dis_data; */ void ble_svc_dis_init(void); +/** + * Service initialisation as an included service. + */ +void ble_svc_dis_included_init(void); + const char *ble_svc_dis_model_number(void); int ble_svc_dis_model_number_set(const char *value); const char *ble_svc_dis_serial_number(void); diff --git a/nimble/host/services/dis/src/ble_svc_dis.c b/nimble/host/services/dis/src/ble_svc_dis.c index 1c9ffe267..2cb3f51bf 100644 --- a/nimble/host/services/dis/src/ble_svc_dis.c +++ b/nimble/host/services/dis/src/ble_svc_dis.c @@ -53,11 +53,7 @@ ble_svc_dis_access(uint16_t conn_handle, uint16_t attr_handle, static const struct ble_gatt_svc_def ble_svc_dis_defs[] = { { /*** Service: Device Information Service (DIS). */ -#if !MYNEWT_VAL(BLE_SVC_DIS_INCLUDED) .type = BLE_GATT_SVC_TYPE_PRIMARY, -#else - .type = BLE_GATT_SVC_TYPE_SECONDARY, -#endif .uuid = BLE_UUID16_DECLARE(BLE_SVC_DIS_UUID16), .characteristics = (struct ble_gatt_chr_def[]) { { #if (MYNEWT_VAL(BLE_SVC_DIS_MODEL_NUMBER_READ_PERM) >= 0) @@ -144,7 +140,6 @@ static const struct ble_gatt_svc_def ble_svc_dis_defs[] = { }, }; -#if MYNEWT_VAL(BLE_SVC_DIS_INCLUDED) const struct ble_gatt_svc_def *included_services[] = {ble_svc_dis_defs, NULL}; const struct ble_gatt_svc_def ble_svc_dis_include_def[] = { { @@ -153,7 +148,6 @@ const struct ble_gatt_svc_def ble_svc_dis_include_def[] = { .includes = included_services, } }; -#endif /** * Simple read access callback for the device information service @@ -386,6 +380,21 @@ ble_svc_dis_pnp_id_set(const char *value) return 0; } +void +ble_svc_dis_included_init(void) +{ + int rc; + + SYSINIT_ASSERT_ACTIVE(); + + rc = ble_gatts_count_cfg(ble_svc_dis_include_def); + SYSINIT_PANIC_ASSERT(rc == 0); + + rc = ble_gatts_add_svcs(ble_svc_dis_include_def); + SYSINIT_PANIC_ASSERT(rc == 0); +} + + /** * Initialize the DIS package. */ @@ -397,15 +406,9 @@ ble_svc_dis_init(void) /* Ensure this function only gets called by sysinit. */ SYSINIT_ASSERT_ACTIVE(); -#if !MYNEWT_VAL(BLE_SVC_DIS_INCLUDED) - const struct ble_gatt_svc_def * defs = ble_svc_dis_defs; -#else - const struct ble_gatt_svc_def * defs = ble_svc_dis_include_def; -#endif - - rc = ble_gatts_count_cfg(defs); + rc = ble_gatts_count_cfg(ble_svc_dis_defs); SYSINIT_PANIC_ASSERT(rc == 0); - rc = ble_gatts_add_svcs(defs); + rc = ble_gatts_add_svcs(ble_svc_dis_defs); SYSINIT_PANIC_ASSERT(rc == 0); } diff --git a/nimble/host/services/gatt/src/ble_svc_gatt.c b/nimble/host/services/gatt/src/ble_svc_gatt.c index 9061ad327..05890dbfe 100644 --- a/nimble/host/services/gatt/src/ble_svc_gatt.c +++ b/nimble/host/services/gatt/src/ble_svc_gatt.c @@ -233,11 +233,11 @@ ble_svc_gatt_init(void) rc = ble_gatts_add_svcs(ble_svc_gatt_defs); SYSINIT_PANIC_ASSERT(rc == 0); - if (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0) { + if (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 && ble_hs_cfg.eatt) { ble_svc_gatt_local_srv_sup_feat |= (1 << BLE_SVC_GATT_SRV_SUP_FEAT_EATT_BIT); } - if (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0) { + if (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 && ble_hs_cfg.eatt) { ble_svc_gatt_local_cl_sup_feat |= (1 << BLE_SVC_GATT_CLI_SUP_FEAT_EATT_BIT); } diff --git a/nimble/host/src/ble_att.c b/nimble/host/src/ble_att.c index 2f6c7f564..08e37dd23 100644 --- a/nimble/host/src/ble_att.c +++ b/nimble/host/src/ble_att.c @@ -474,7 +474,7 @@ ble_att_chan_mtu(const struct ble_l2cap_chan *chan) uint16_t mtu; #if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 - if (chan->psm == BLE_EATT_PSM) { + if (ble_hs_cfg.eatt && chan->psm == BLE_EATT_PSM) { /* The ATT_MTU for the Enhanced ATT bearer shall be set to the minimum of the * MTU field values of the two devices. Reference: * Core v5.4 Vol 3 Part G 5.3.1 ATT_MTU diff --git a/nimble/host/src/ble_att_clt.c b/nimble/host/src/ble_att_clt.c index dd11a9a5c..db793bb66 100644 --- a/nimble/host/src/ble_att_clt.c +++ b/nimble/host/src/ble_att_clt.c @@ -123,7 +123,7 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom) mtu = 0; #if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 - if (cid != BLE_L2CAP_CID_ATT) { + if (ble_hs_cfg.eatt && cid != BLE_L2CAP_CID_ATT) { return BLE_HS_ENOTSUP; } #endif diff --git a/nimble/host/src/ble_att_cmd.c b/nimble/host/src/ble_att_cmd.c index 8be203178..1bdce8c3c 100644 --- a/nimble/host/src/ble_att_cmd.c +++ b/nimble/host/src/ble_att_cmd.c @@ -101,7 +101,7 @@ ble_att_tx(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txom) int rc; #if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 - if (cid != BLE_L2CAP_CID_ATT) { + if (ble_hs_cfg.eatt && cid != BLE_L2CAP_CID_ATT) { return ble_eatt_tx(conn_handle, cid, txom); } #endif diff --git a/nimble/host/src/ble_att_svr.c b/nimble/host/src/ble_att_svr.c index 06859174b..3c362e72c 100644 --- a/nimble/host/src/ble_att_svr.c +++ b/nimble/host/src/ble_att_svr.c @@ -1476,8 +1476,10 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rx struct ble_att_read_type_req *req; uint16_t start_handle, end_handle; +#if MYNEWT_VAL(BLE_GATT_CACHING) struct ble_hs_conn *conn; struct ble_hs_conn_addrs addrs; +#endif struct os_mbuf *txom; uint16_t err_handle; uint16_t pktlen; @@ -2385,10 +2387,14 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, uint16_t cid, struct os_mbuf * int ble_att_svr_rx_signed_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom) { -#if !MYNEWT_VAL(BLE_ATT_SVR_SIGNED_WRITE) || MYNEWT_VAL(BLE_EATT_CHAN_NUM) +#if !MYNEWT_VAL(BLE_ATT_SVR_SIGNED_WRITE) return BLE_HS_ENOTSUP; #endif + if (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 && ble_hs_cfg.eatt) { + return BLE_HS_ENOTSUP; + } + struct ble_att_signed_write_cmd *req; struct ble_store_value_sec value_sec; struct ble_store_key_sec key_sec; diff --git a/nimble/host/src/ble_eatt.c b/nimble/host/src/ble_eatt.c index 3e27ae5c1..1bbf02ac8 100644 --- a/nimble/host/src/ble_eatt.c +++ b/nimble/host/src/ble_eatt.c @@ -442,6 +442,10 @@ ble_eatt_gap_event(struct ble_gap_event *event, void *arg) return 0; } + if (ble_hs_cfg.eatt == 0) { + return 0; + } + /* Don't try to connect if already connected */ if (ble_eatt_find_by_conn_handle(event->enc_change.conn_handle)) { return 0; @@ -553,7 +557,7 @@ ble_eatt_start(uint16_t conn_handle) return; } - for (int i = 0; i < MYNEWT_VAL(BLE_EATT_CHAN_NUM); i++) { + for (int i = 0; i < ble_hs_cfg.eatt; i++) { eatt = ble_eatt_alloc(); if (!eatt) { return; diff --git a/nimble/host/src/ble_gattc.c b/nimble/host/src/ble_gattc.c index d822b5bb4..835bacef8 100644 --- a/nimble/host/src/ble_gattc.c +++ b/nimble/host/src/ble_gattc.c @@ -763,7 +763,7 @@ ble_gattc_proc_free(struct ble_gattc_proc *proc) } #if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 - if (proc->cid != BLE_L2CAP_CID_ATT) { + if (ble_hs_cfg.eatt && proc->cid != BLE_L2CAP_CID_ATT) { ble_eatt_release_chan(proc->conn_handle, proc->op); } #endif diff --git a/nimble/host/src/ble_hs_cfg.c b/nimble/host/src/ble_hs_cfg.c index b3cf33c74..ef12d88d6 100644 --- a/nimble/host/src/ble_hs_cfg.c +++ b/nimble/host/src/ble_hs_cfg.c @@ -31,4 +31,5 @@ struct ble_hs_cfg ble_hs_cfg = { .sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS), .sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST), .sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST), + .eatt = MYNEWT_VAL(BLE_EATT_CHAN_NUM), };