Adds support for user-supplied BT address
Also cleans up BLE configs
This commit is contained in:
parent
b483af4126
commit
a93171b9bf
4 changed files with 27 additions and 21 deletions
|
|
@ -19,4 +19,6 @@
|
|||
// Checks that expr evaluates to true, otherwise return 1.
|
||||
#define RET_CHECK(expr, msg) RET_IF_ERR_MSG(!(expr), msg)
|
||||
|
||||
#define UNUSED_OK(expr) (void)expr;
|
||||
|
||||
#endif // _PRST_MACROS_H_
|
||||
|
|
@ -1,34 +1,16 @@
|
|||
|
||||
source "Kconfig.zephyr"
|
||||
|
||||
choice PRST_NETWORK
|
||||
prompt "b-parasite Network"
|
||||
default PRST_NETWORK_BLE
|
||||
|
||||
config PRST_NETWORK_NONE
|
||||
bool "Network disabled"
|
||||
|
||||
config PRST_NETWORK_BLE
|
||||
bool "Uses BLE as the network"
|
||||
depends on BT
|
||||
|
||||
endchoice # PRST_NETWORK
|
||||
|
||||
config PRST_SLEEP_DURATION_SEC
|
||||
int "Sleep duration in seconds"
|
||||
default 600
|
||||
|
||||
###
|
||||
### BLE configs
|
||||
###
|
||||
|
||||
config PRST_BLE_ADV_DURATION_SEC
|
||||
int "Advertising duration in seconds"
|
||||
default 600
|
||||
default 1
|
||||
|
||||
choice PRST_BLE_ENCODING
|
||||
prompt "b-parasite BLE encoding"
|
||||
depends on PRST_NETWORK_BLE
|
||||
default PRST_BLE_ENCODING_BPARASITE_V2
|
||||
|
||||
config PRST_BLE_ENCODING_BPARASITE_V2
|
||||
|
|
@ -45,7 +27,17 @@ endchoice # PRST_BLE_ENCODING
|
|||
config PRST_BLE_ENCODING_SERVICE_DATA_LEN
|
||||
int
|
||||
help
|
||||
Size of the service data buffer
|
||||
Size of the service data buffer.
|
||||
default 20 if PRST_BLE_ENCODING_BPARASITE_V2
|
||||
default 18 if PRST_BLE_ENCODING_BTHOME_V1
|
||||
default 19 if PRST_BLE_ENCODING_BTHOME_V2
|
||||
|
||||
|
||||
config PRST_BLE_HAS_USER_DEFINED_RANDOM_STATIC_ADDR
|
||||
bool "Whether to use a custom BLE address"
|
||||
|
||||
config PRST_BLE_USER_DEFINED_RANDOM_STATIC_ADDR
|
||||
string "Overrides the device's BT address"
|
||||
help
|
||||
This address has to be random static (e.g.: f0:ca:f0:ca:01:d5).
|
||||
depends on PRST_BLE_HAS_USER_DEFINED_RANDOM_STATIC_ADDR
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ CONFIG_PM_DEVICE=y
|
|||
|
||||
CONFIG_USE_SEGGER_RTT=y
|
||||
|
||||
# Otherwise a weird float multiplication error?
|
||||
CONFIG_NEWLIB_LIBC=y
|
||||
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ static const struct bt_data sd[] = {};
|
|||
|
||||
static bt_addr_le_t mac_addr;
|
||||
|
||||
static int set_user_defined_bt_addr(const char *addr_str) {
|
||||
bt_addr_le_t addr;
|
||||
RET_IF_ERR(bt_addr_le_from_str(addr_str, "random", &addr));
|
||||
RET_IF_ERR(bt_id_create(&addr, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// bt_addr_le_t.a holds the MAC address in big-endian.
|
||||
static int get_mac_addr(bt_addr_le_t *out) {
|
||||
struct bt_le_oob oob;
|
||||
|
|
@ -33,6 +40,12 @@ static int get_mac_addr(bt_addr_le_t *out) {
|
|||
}
|
||||
|
||||
int prst_ble_init() {
|
||||
#if CONFIG_PRST_BLE_HAS_USER_DEFINED_RANDOM_STATIC_ADDR
|
||||
RET_IF_ERR(set_user_defined_bt_addr(CONFIG_PRST_BLE_USER_DEFINED_RANDOM_STATIC_ADDR));
|
||||
#else
|
||||
UNUSED_OK(set_user_defined_bt_addr);
|
||||
#endif // PRST_BLE_HAS_USER_DEFINED_MAC_ADDR
|
||||
|
||||
RET_IF_ERR(bt_enable(/*bt_reader_cb_t=*/NULL));
|
||||
if (IS_ENABLED(CONFIG_SETTINGS)) {
|
||||
RET_IF_ERR_MSG(settings_load(), "Error in settings_load()");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue