feat(nimble): Added ways to enable/disable some menuconfig options at runtime

This commit is contained in:
Sumeet Singh
2024-11-05 21:30:36 +05:30
committed by Rahul Tank
parent 40b997c65a
commit 65f05a1d02
11 changed files with 53 additions and 25 deletions
+9
View File
@@ -329,6 +329,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;
@@ -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);
+17 -14
View File
@@ -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);
}
+2 -2
View File
@@ -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);
}
+1 -1
View File
@@ -475,7 +475,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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -100,7 +100,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
+7 -1
View File
@@ -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;
@@ -2390,10 +2392,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;
+5 -1
View File
@@ -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;
+1 -1
View File
@@ -764,7 +764,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
+1
View File
@@ -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),
};