mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
Merge branch 'feature/option_to_advertise_random_addr' into 'master'
NimBLE: Feature/option to advertise random addr See merge request espressif/esp-idf!18896
This commit is contained in:
@@ -55,4 +55,9 @@ menu "Example Configuration"
|
|||||||
help
|
help
|
||||||
Use this option to enable extended advertising in the example
|
Use this option to enable extended advertising in the example
|
||||||
|
|
||||||
|
config EXAMPLE_RANDOM_ADDR
|
||||||
|
bool
|
||||||
|
prompt "Advertise RANDOM Address"
|
||||||
|
help
|
||||||
|
Use this option to advertise a random address instead of public address
|
||||||
endmenu
|
endmenu
|
||||||
|
@@ -39,7 +39,11 @@ static uint8_t ext_adv_pattern_1[] = {
|
|||||||
|
|
||||||
static const char *tag = "NimBLE_BLE_PRPH";
|
static const char *tag = "NimBLE_BLE_PRPH";
|
||||||
static int bleprph_gap_event(struct ble_gap_event *event, void *arg);
|
static int bleprph_gap_event(struct ble_gap_event *event, void *arg);
|
||||||
|
#if CONFIG_EXAMPLE_RANDOM_ADDR
|
||||||
|
static uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
|
||||||
|
#else
|
||||||
static uint8_t own_addr_type;
|
static uint8_t own_addr_type;
|
||||||
|
#endif
|
||||||
|
|
||||||
void ble_store_config_init(void);
|
void ble_store_config_init(void);
|
||||||
|
|
||||||
@@ -368,13 +372,40 @@ bleprph_on_reset(int reason)
|
|||||||
MODLOG_DFLT(ERROR, "Resetting state; reason=%d\n", reason);
|
MODLOG_DFLT(ERROR, "Resetting state; reason=%d\n", reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_EXAMPLE_RANDOM_ADDR
|
||||||
|
static void
|
||||||
|
ble_app_set_addr(void)
|
||||||
|
{
|
||||||
|
ble_addr_t addr;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* generate new non-resolvable private address */
|
||||||
|
rc = ble_hs_id_gen_rnd(0, &addr);
|
||||||
|
assert(rc == 0);
|
||||||
|
|
||||||
|
/* set generated address */
|
||||||
|
rc = ble_hs_id_set_rnd(addr.val);
|
||||||
|
|
||||||
|
assert(rc == 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bleprph_on_sync(void)
|
bleprph_on_sync(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
#if CONFIG_EXAMPLE_RANDOM_ADDR
|
||||||
|
/* Generate a non-resolvable private address. */
|
||||||
|
ble_app_set_addr();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Make sure we have proper identity address set (public preferred) */
|
/* Make sure we have proper identity address set (public preferred) */
|
||||||
|
#if CONFIG_EXAMPLE_RANDOM_ADDR
|
||||||
|
rc = ble_hs_util_ensure_addr(1);
|
||||||
|
#else
|
||||||
rc = ble_hs_util_ensure_addr(0);
|
rc = ble_hs_util_ensure_addr(0);
|
||||||
|
#endif
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
|
|
||||||
/* Figure out address to use while advertising (no privacy for now) */
|
/* Figure out address to use while advertising (no privacy for now) */
|
||||||
|
Reference in New Issue
Block a user