Skip to content

Commit 43c759d

Browse files
committed
nimble/host: Compile ATT, GATT, L2CAP and SM files if NIMBLE_BLE_CONNECT
ATT, GATT, L2CAP and SM are used only when connection is established, there's no need to compile them otherwise.
1 parent 3a9d1d8 commit 43c759d

18 files changed

+92
-15
lines changed

nimble/host/services/gap/src/ble_svc_gap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static char ble_svc_gap_name[BLE_SVC_GAP_NAME_MAX_LEN + 1] =
4141
MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME);
4242
static uint16_t ble_svc_gap_appearance = MYNEWT_VAL(BLE_SVC_GAP_APPEARANCE);
4343

44+
#if NIMBLE_BLE_CONNECT
4445
static int
4546
ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
4647
struct ble_gatt_access_ctxt *ctxt, void *arg);
@@ -239,6 +240,7 @@ ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
239240
return BLE_ATT_ERR_UNLIKELY;
240241
}
241242
}
243+
#endif
242244

243245
const char *
244246
ble_svc_gap_device_name(void)
@@ -285,14 +287,18 @@ ble_svc_gap_set_chr_changed_cb(ble_svc_gap_chr_changed_fn *cb)
285287
void
286288
ble_svc_gap_init(void)
287289
{
290+
#if NIMBLE_BLE_CONNECT
288291
int rc;
292+
#endif
289293

290294
/* Ensure this function only gets called by sysinit. */
291295
SYSINIT_ASSERT_ACTIVE();
292296

297+
#if NIMBLE_BLE_CONNECT
293298
rc = ble_gatts_count_cfg(ble_svc_gap_defs);
294299
SYSINIT_PANIC_ASSERT(rc == 0);
295300

296301
rc = ble_gatts_add_svcs(ble_svc_gap_defs);
297302
SYSINIT_PANIC_ASSERT(rc == 0);
303+
#endif
298304
}

nimble/host/src/ble_att.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <errno.h>
2222
#include "ble_hs_priv.h"
2323

24+
#if NIMBLE_BLE_CONNECT
2425
static uint16_t ble_att_preferred_mtu_val;
2526

2627
/** Dispatch table for incoming ATT requests. Sorted by op code. */
@@ -587,3 +588,5 @@ ble_att_init(void)
587588

588589
return 0;
589590
}
591+
592+
#endif

nimble/host/src/ble_att_clt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "host/ble_uuid.h"
2727
#include "ble_hs_priv.h"
2828

29+
#if NIMBLE_BLE_CONNECT
2930
/*****************************************************************************
3031
* $error response *
3132
*****************************************************************************/
@@ -954,3 +955,5 @@ ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
954955
ble_gattc_rx_indicate_rsp(conn_handle);
955956
return 0;
956957
}
958+
959+
#endif

nimble/host/src/ble_att_cmd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "host/ble_uuid.h"
2727
#include "ble_hs_priv.h"
2828

29+
#if NIMBLE_BLE_CONNECT
2930
void *
3031
ble_att_cmd_prepare(uint8_t opcode, size_t len, struct os_mbuf *txom)
3132
{
@@ -634,3 +635,5 @@ ble_att_indicate_rsp_write(void *payload, int len)
634635
ble_att_init_write(BLE_ATT_OP_INDICATE_RSP, payload,
635636
BLE_ATT_INDICATE_RSP_SZ, len);
636637
}
638+
639+
#endif

nimble/host/src/ble_att_svr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "host/ble_uuid.h"
2626
#include "ble_hs_priv.h"
2727

28+
#if NIMBLE_BLE_CONNECT
2829
/**
2930
* ATT server - Attribute Protocol
3031
*
@@ -2727,3 +2728,5 @@ ble_att_svr_init(void)
27272728

27282729
return 0;
27292730
}
2731+
2732+
#endif

nimble/host/src/ble_gattc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "host/ble_gap.h"
6161
#include "ble_hs_priv.h"
6262

63+
#if NIMBLE_BLE_CONNECT
6364
/*****************************************************************************
6465
* $definitions / declarations *
6566
*****************************************************************************/
@@ -4804,3 +4805,5 @@ ble_gattc_init(void)
48044805

48054806
return 0;
48064807
}
4808+
4809+
#endif

nimble/host/src/ble_gatts_lcl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "nimble/ble.h"
2525
#include "ble_hs_priv.h"
2626

27+
#if NIMBLE_BLE_CONNECT
2728
static const ble_uuid_t *uuid_ccc =
2829
BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16);
2930

@@ -209,3 +210,4 @@ ble_gatts_show_local(void)
209210
ble_gatts_lcl_svc_foreach(ble_gatt_show_local_svc, NULL);
210211
}
211212

213+
#endif

nimble/host/src/ble_hs.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
3737

3838
static void ble_hs_event_rx_hci_ev(struct ble_npl_event *ev);
39+
#if NIMBLE_BLE_CONNECT
3940
static void ble_hs_event_tx_notify(struct ble_npl_event *ev);
41+
#endif
4042
static void ble_hs_event_reset(struct ble_npl_event *ev);
4143
static void ble_hs_event_start_stage1(struct ble_npl_event *ev);
4244
static void ble_hs_event_start_stage2(struct ble_npl_event *ev);
@@ -401,12 +403,10 @@ ble_hs_timer_exp(struct ble_npl_event *ev)
401403

402404
switch (ble_hs_sync_state) {
403405
case BLE_HS_SYNC_STATE_GOOD:
406+
#if NIMBLE_BLE_CONNECT
404407
ticks_until_next = ble_gattc_timer();
405408
ble_hs_timer_sched(ticks_until_next);
406409

407-
ticks_until_next = ble_gap_timer();
408-
ble_hs_timer_sched(ticks_until_next);
409-
410410
ticks_until_next = ble_l2cap_sig_timer();
411411
ble_hs_timer_sched(ticks_until_next);
412412

@@ -415,6 +415,11 @@ ble_hs_timer_exp(struct ble_npl_event *ev)
415415

416416
ticks_until_next = ble_hs_conn_timer();
417417
ble_hs_timer_sched(ticks_until_next);
418+
#endif
419+
420+
ticks_until_next = ble_gap_timer();
421+
ble_hs_timer_sched(ticks_until_next);
422+
418423
break;
419424

420425
case BLE_HS_SYNC_STATE_BAD:
@@ -509,11 +514,13 @@ ble_hs_event_rx_hci_ev(struct ble_npl_event *ev)
509514
ble_hs_hci_evt_process(hci_ev);
510515
}
511516

517+
#if NIMBLE_BLE_CONNECT
512518
static void
513519
ble_hs_event_tx_notify(struct ble_npl_event *ev)
514520
{
515521
ble_gatts_tx_notifications();
516522
}
523+
#endif
517524

518525
static void
519526
ble_hs_event_rx_data(struct ble_npl_event *ev)
@@ -646,11 +653,12 @@ ble_hs_start(void)
646653

647654
ble_npl_callout_init(&ble_hs_timer, ble_hs_evq, ble_hs_timer_exp, NULL);
648655

656+
#if NIMBLE_BLE_CONNECT
649657
rc = ble_gatts_start();
650658
if (rc != 0) {
651659
return rc;
652660
}
653-
661+
#endif
654662
ble_hs_sync();
655663

656664
return 0;
@@ -723,8 +731,10 @@ ble_hs_init(void)
723731
ble_hs_reset_reason = 0;
724732
ble_hs_enabled_state = BLE_HS_ENABLED_STATE_OFF;
725733

734+
#if NIMBLE_BLE_CONNECT
726735
ble_npl_event_init(&ble_hs_ev_tx_notifications, ble_hs_event_tx_notify,
727736
NULL);
737+
#endif
728738
ble_npl_event_init(&ble_hs_ev_reset, ble_hs_event_reset, NULL);
729739
ble_npl_event_init(&ble_hs_ev_start_stage1, ble_hs_event_start_stage1,
730740
NULL);
@@ -741,6 +751,7 @@ ble_hs_init(void)
741751
SYSINIT_PANIC_ASSERT(rc == 0);
742752
#endif
743753

754+
#if NIMBLE_BLE_CONNECT
744755
rc = ble_l2cap_init();
745756
SYSINIT_PANIC_ASSERT(rc == 0);
746757

@@ -750,14 +761,14 @@ ble_hs_init(void)
750761
rc = ble_att_svr_init();
751762
SYSINIT_PANIC_ASSERT(rc == 0);
752763

753-
rc = ble_gap_init();
754-
SYSINIT_PANIC_ASSERT(rc == 0);
755-
756764
rc = ble_gattc_init();
757765
SYSINIT_PANIC_ASSERT(rc == 0);
758766

759767
rc = ble_gatts_init();
760768
SYSINIT_PANIC_ASSERT(rc == 0);
769+
#endif
770+
rc = ble_gap_init();
771+
SYSINIT_PANIC_ASSERT(rc == 0);
761772

762773
ble_hs_stop_init();
763774

nimble/host/src/ble_hs_hci_evt.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,27 @@ _Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
3232

3333
typedef int ble_hs_hci_evt_fn(uint8_t event_code, const void *data,
3434
unsigned int len);
35-
static ble_hs_hci_evt_fn ble_hs_hci_evt_disconn_complete;
36-
static ble_hs_hci_evt_fn ble_hs_hci_evt_encrypt_change;
3735
static ble_hs_hci_evt_fn ble_hs_hci_evt_hw_error;
3836
static ble_hs_hci_evt_fn ble_hs_hci_evt_num_completed_pkts;
37+
#if NIMBLE_BLE_CONNECT
38+
static ble_hs_hci_evt_fn ble_hs_hci_evt_disconn_complete;
39+
static ble_hs_hci_evt_fn ble_hs_hci_evt_encrypt_change;
3940
static ble_hs_hci_evt_fn ble_hs_hci_evt_enc_key_refresh;
41+
#endif
4042
static ble_hs_hci_evt_fn ble_hs_hci_evt_le_meta;
4143

4244
typedef int ble_hs_hci_evt_le_fn(uint8_t subevent, const void *data,
4345
unsigned int len);
44-
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_complete;
4546
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_adv_rpt;
47+
#if NIMBLE_BLE_CONNECT
48+
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_complete;
4649
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_upd_complete;
4750
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_lt_key_req;
4851
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_parm_req;
49-
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_dir_adv_rpt;
5052
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_phy_update_complete;
53+
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_enh_conn_complete;
54+
#endif
55+
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_dir_adv_rpt;
5156
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_ext_adv_rpt;
5257
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_rd_rem_used_feat_complete;
5358
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_scan_timeout;
@@ -56,7 +61,6 @@ static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_estab;
5661
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_rpt;
5762
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_lost;
5863
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_scan_req_rcvd;
59-
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_enh_conn_complete;
6064
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_transfer;
6165

6266
/* Statistics */
@@ -79,24 +83,32 @@ struct ble_hs_hci_evt_dispatch_entry {
7983
static const struct ble_hs_hci_evt_dispatch_entry ble_hs_hci_evt_dispatch[] = {
8084
{ BLE_HCI_EVCODE_LE_META, ble_hs_hci_evt_le_meta },
8185
{ BLE_HCI_EVCODE_NUM_COMP_PKTS, ble_hs_hci_evt_num_completed_pkts },
86+
#if NIMBLE_BLE_CONNECT
8287
{ BLE_HCI_EVCODE_DISCONN_CMP, ble_hs_hci_evt_disconn_complete },
8388
{ BLE_HCI_EVCODE_ENCRYPT_CHG, ble_hs_hci_evt_encrypt_change },
8489
{ BLE_HCI_EVCODE_ENC_KEY_REFRESH, ble_hs_hci_evt_enc_key_refresh },
90+
#endif
8591
{ BLE_HCI_EVCODE_HW_ERROR, ble_hs_hci_evt_hw_error },
8692
};
8793

8894
#define BLE_HS_HCI_EVT_DISPATCH_SZ \
8995
(sizeof ble_hs_hci_evt_dispatch / sizeof ble_hs_hci_evt_dispatch[0])
9096

9197
static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = {
98+
#if NIMBLE_BLE_CONNECT
9299
[BLE_HCI_LE_SUBEV_CONN_COMPLETE] = ble_hs_hci_evt_le_conn_complete,
100+
#endif
93101
[BLE_HCI_LE_SUBEV_ADV_RPT] = ble_hs_hci_evt_le_adv_rpt,
102+
#if NIMBLE_BLE_CONNECT
94103
[BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE] = ble_hs_hci_evt_le_conn_upd_complete,
95104
[BLE_HCI_LE_SUBEV_LT_KEY_REQ] = ble_hs_hci_evt_le_lt_key_req,
96105
[BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ] = ble_hs_hci_evt_le_conn_parm_req,
97106
[BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE] = ble_hs_hci_evt_le_enh_conn_complete,
107+
#endif
98108
[BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT] = ble_hs_hci_evt_le_dir_adv_rpt,
109+
#if NIMBLE_BLE_CONNECT
99110
[BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE] = ble_hs_hci_evt_le_phy_update_complete,
111+
#endif
100112
[BLE_HCI_LE_SUBEV_EXT_ADV_RPT] = ble_hs_hci_evt_le_ext_adv_rpt,
101113
[BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_ESTAB] = ble_hs_hci_evt_le_periodic_adv_sync_estab,
102114
[BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT] = ble_hs_hci_evt_le_periodic_adv_rpt,
@@ -137,6 +149,7 @@ ble_hs_hci_evt_le_dispatch_find(uint8_t event_code)
137149
return ble_hs_hci_evt_le_dispatch[event_code];
138150
}
139151

152+
#if NIMBLE_BLE_CONNECT
140153
static int
141154
ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
142155
unsigned int len)
@@ -180,7 +193,7 @@ ble_hs_hci_evt_encrypt_change(uint8_t event_code, const void *data,
180193

181194
return 0;
182195
}
183-
196+
#endif
184197
static int
185198
ble_hs_hci_evt_hw_error(uint8_t event_code, const void *data, unsigned int len)
186199
{
@@ -195,6 +208,7 @@ ble_hs_hci_evt_hw_error(uint8_t event_code, const void *data, unsigned int len)
195208
return 0;
196209
}
197210

211+
#if NIMBLE_BLE_CONNECT
198212
static int
199213
ble_hs_hci_evt_enc_key_refresh(uint8_t event_code, const void *data,
200214
unsigned int len)
@@ -209,6 +223,7 @@ ble_hs_hci_evt_enc_key_refresh(uint8_t event_code, const void *data,
209223

210224
return 0;
211225
}
226+
#endif
212227

213228
static int
214229
ble_hs_hci_evt_num_completed_pkts(uint8_t event_code, const void *data,
@@ -270,6 +285,7 @@ ble_hs_hci_evt_le_meta(uint8_t event_code, const void *data, unsigned int len)
270285
static struct ble_gap_conn_complete pend_conn_complete;
271286
#endif
272287

288+
#if NIMBLE_BLE_CONNECT
273289
static int
274290
ble_hs_hci_evt_le_enh_conn_complete(uint8_t subevent, const void *data,
275291
unsigned int len)
@@ -301,7 +317,6 @@ ble_hs_hci_evt_le_enh_conn_complete(uint8_t subevent, const void *data,
301317
evt.connection_handle = BLE_HS_CONN_HANDLE_NONE;
302318
#endif
303319
}
304-
305320
#if MYNEWT_VAL(BLE_EXT_ADV)
306321
if (evt.status == BLE_ERR_DIR_ADV_TMO ||
307322
evt.role == BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
@@ -355,6 +370,7 @@ ble_hs_hci_evt_le_conn_complete(uint8_t subevent, const void *data,
355370
#endif
356371
return ble_gap_rx_conn_complete(&evt, 0);
357372
}
373+
#endif
358374

359375
static int
360376
ble_hs_hci_evt_le_adv_rpt_first_pass(const void *data, unsigned int len)
@@ -697,6 +713,7 @@ ble_hs_hci_evt_le_scan_req_rcvd(uint8_t subevent, const void *data,
697713
return 0;
698714
}
699715

716+
#if NIMBLE_BLE_CONNECT
700717
static int
701718
ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, const void *data,
702719
unsigned int len)
@@ -775,6 +792,7 @@ ble_hs_hci_evt_le_phy_update_complete(uint8_t subevent, const void *data,
775792

776793
return 0;
777794
}
795+
#endif
778796

779797
int
780798
ble_hs_hci_evt_process(const struct ble_hci_ev *ev)
@@ -811,6 +829,7 @@ ble_hs_hci_evt_process(const struct ble_hci_ev *ev)
811829
int
812830
ble_hs_hci_evt_acl_process(struct os_mbuf *om)
813831
{
832+
#if NIMBLE_BLE_CONNECT
814833
struct hci_data_hdr hci_hdr;
815834
struct ble_hs_conn *conn;
816835
ble_l2cap_rx_fn *rx_cb;
@@ -881,4 +900,7 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
881900
err:
882901
os_mbuf_free_chain(om);
883902
return rc;
903+
#else
904+
return BLE_HS_ENOTSUP;
905+
#endif
884906
}

nimble/host/src/ble_l2cap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ble_hs_priv.h"
2727
#include "ble_l2cap_coc_priv.h"
2828

29+
#if NIMBLE_BLE_CONNECT
2930
_Static_assert(sizeof (struct ble_l2cap_hdr) == BLE_L2CAP_HDR_SZ,
3031
"struct ble_l2cap_hdr must be 4 bytes");
3132

@@ -504,3 +505,5 @@ ble_l2cap_init(void)
504505

505506
return 0;
506507
}
508+
509+
#endif

0 commit comments

Comments
 (0)