Skip to content

Commit

Permalink
ble: provide stubs in the ble header and include it unconditionally
Browse files Browse the repository at this point in the history
This simplifies the callers and keeps the interface together, rather
than defining local stubs in ad-hoc files.
  • Loading branch information
jgriffiths committed Jan 6, 2025
1 parent d971575 commit e49eb81
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 2 additions & 0 deletions main/ble/ble.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ble.h"
#ifdef CONFIG_BT_ENABLED
#include "../button_events.h"
#include "../gui.h"
#include "../jade_assert.h"
Expand Down Expand Up @@ -880,3 +881,4 @@ bool ble_remove_all_devices(void)

return retval;
}
#endif // CONFIG_BT_ENABLED
18 changes: 18 additions & 0 deletions main/ble/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <freertos/task.h>
#include <stdbool.h>

#ifdef CONFIG_BT_ENABLED
bool ble_init(TaskHandle_t* ble_handle);

bool ble_enabled(void);
Expand All @@ -15,4 +16,21 @@ void ble_stop(void);

bool ble_remove_all_devices(void);

#else /* CONFIG_BT_ENABLED */

/* Provide stub implementations to simplify calling code */

#include "../jade_assert.h"

static inline bool ble_init(TaskHandle_t* ble_handle) { return false; }

static inline bool ble_enabled(void) { return false; }
static inline bool ble_connected(void) { return false; }

static inline void ble_start(void) { JADE_ASSERT(false); }
static inline void ble_stop(void) { return; }

static inline bool ble_remove_all_devices(void) { JADE_ASSERT(false); }
#endif /* CONFIG_BT_ENABLED */

#endif /* BLE_H_ */
5 changes: 1 addition & 4 deletions main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "display.h"

#include "ble/ble.h"
#include "gui.h"
#include "idletimer.h"
#include "jade_assert.h"
Expand All @@ -19,10 +20,6 @@
#include "utils/event.h"
#include "utils/malloc_ext.h"

#ifdef CONFIG_BT_ENABLED
#include "ble/ble.h"
#endif

// A genuine production v2 Jade may be awaiting mandatory attestation data
#if defined(CONFIG_BOARD_TYPE_JADE_V2) && defined(CONFIG_SECURE_BOOT) \
&& defined(CONFIG_SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS)
Expand Down
3 changes: 0 additions & 3 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
#include "qemu_tcp.h"
#endif

#ifdef CONFIG_BT_ENABLED
#include "ble/ble.h"
#endif

#include "idletimer.h"
#include "power.h"
#include "smoketest.h"
Expand Down
8 changes: 1 addition & 7 deletions main/process.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "process.h"
#include "ble/ble.h"
#include "jade_assert.h"
#include "jade_wally_verify.h"
#include "power.h"
#include "process/process_utils.h"
#include "utils/cbor_rpc.h"
#include "utils/malloc_ext.h"
#ifdef CONFIG_BT_ENABLED
#include "../ble/ble.h"
#endif

#include <esp_mac.h>
#include <freertos/FreeRTOS.h>
Expand Down Expand Up @@ -369,10 +367,6 @@ static void dump_mem_report(void)
}
#endif /* CONFIG_HEAP_TRACING */

#ifndef CONFIG_BT_ENABLED
static inline bool ble_connected(void) { return false; }
#endif

void jade_process_get_in_message(void* ctx, inbound_message_reader_fn_t reader, bool blocking)
{
// reader can be null to just discard messages
Expand Down
8 changes: 0 additions & 8 deletions main/process/dashboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ static inline bool awaiting_attestation_data(void) { return !attestation_initial
static inline bool awaiting_attestation_data(void) { return false; }
#endif

#ifdef CONFIG_BT_ENABLED
#include "../ble/ble.h"
#else
// Stubs
static inline bool ble_enabled(void) { return false; }
static inline bool ble_connected(void) { return false; }
static inline void ble_start(void) { JADE_ASSERT(false); }
static inline void ble_stop(void) { return; }
#endif
#include "process/ota_defines.h"
#include "process_utils.h"

Expand Down

0 comments on commit e49eb81

Please sign in to comment.