apps/bttester: Fix handling own address

Use public address if assigned, otherwise use static random address.
Set correct flags when using random address.
This commit is contained in:
Michał Narajowski
2019-02-25 14:40:37 +01:00
parent ff5d9a6211
commit f45de569ca
3 changed files with 27 additions and 5 deletions
+24 -3
View File
@@ -31,7 +31,7 @@ const uint8_t irk[16] = {
struct hal_timer conn_param_update_timer;
#endif
static atomic_t current_settings;
static u8_t own_addr_type = BLE_OWN_ADDR_PUBLIC;
u8_t own_addr_type;
static ble_addr_t peer_id_addr;
static ble_addr_t peer_ota_addr;
static bool encrypted = false;
@@ -112,6 +112,18 @@ static void controller_index_list(u8_t *data, u16_t len)
BTP_INDEX_NONE, (u8_t *) rp, sizeof(buf));
}
static int check_pub_addr_unassigned(void)
{
#ifdef ARCH_sim
return 0;
#else
uint8_t zero_addr[BLE_DEV_ADDR_LEN] = { 0 };
return memcmp(MYNEWT_VAL(BLE_PUBLIC_DEV_ADDR),
zero_addr, BLE_DEV_ADDR_LEN) == 0;
#endif
}
static void controller_info(u8_t *data, u16_t len)
{
struct gap_read_controller_info_rp rp;
@@ -137,8 +149,17 @@ static void controller_info(u8_t *data, u16_t len)
supported_settings |= BIT(GAP_SETTINGS_PRIVACY);
memcpy(rp.address, addr.val, sizeof(rp.address));
} else {
memcpy(rp.address, MYNEWT_VAL(BLE_PUBLIC_DEV_ADDR),
sizeof(rp.address));
if (check_pub_addr_unassigned()) {
own_addr_type = BLE_OWN_ADDR_RANDOM;
memcpy(rp.address, addr.val, sizeof(rp.address));
supported_settings |= BIT(GAP_SETTINGS_STATIC_ADDRESS);
atomic_set_bit(&current_settings,
GAP_SETTINGS_STATIC_ADDRESS);
} else {
own_addr_type = BLE_OWN_ADDR_PUBLIC;
memcpy(rp.address, MYNEWT_VAL(BLE_PUBLIC_DEV_ADDR),
sizeof(rp.address));
}
}
ble_hs_cfg.sm_mitm = 0;
+3 -1
View File
@@ -19,6 +19,8 @@
#include "bttester.h"
extern u8_t own_addr_type;
#define CONTROLLER_INDEX 0
#define CID_LOCAL 0xffff
@@ -433,7 +435,7 @@ static void init(u8_t *data, u16_t len)
SYS_LOG_DBG("");
err = bt_mesh_init(0, &prov, &comp);
err = bt_mesh_init(own_addr_type, &prov, &comp);
if (err) {
status = BTP_STATUS_FAILED;
-1
View File
@@ -61,7 +61,6 @@ syscfg.vals:
SHELL_NEWTMGR: 0
LOG_LEVEL: 1
MSYS_1_BLOCK_COUNT: 48
BLE_PUBLIC_DEV_ADDR: "((uint8_t[6]){0x66, 0x55, 0x44, 0x33, 0x22, 0x11})"
BLE_MONITOR_RTT: 1
CONSOLE_RTT: 0