Skip to content

Commit

Permalink
Merge branch 'bugfix/nimble_static_declaration_rpa_v1.1.0-idfv3.3' in…
Browse files Browse the repository at this point in the history
…to 'nimble-1.1.0-idf-v3.3'

NimBLE: Fix build failures in RPA feature & in `ble_hs_reset` (Backport nimble-1.1.0-idfv3.3)

See merge request espressif/esp-nimble!37
  • Loading branch information
dhrishi committed Apr 6, 2020
2 parents 32ae92f + 4de96d1 commit 5364a96
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
48 changes: 48 additions & 0 deletions nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,14 @@ ble_gap_master_failed(int status)
ble_gap_master_connect_failure(status);
break;

#if NIMBLE_BLE_SCAN
case BLE_GAP_OP_M_DISC:
STATS_INC(ble_gap_stats, initiate_fail);
ble_gap_disc_complete();
ble_gap_master_reset_state();
break;
#endif

default:
BLE_HS_DBG_ASSERT(0);
break;
Expand Down Expand Up @@ -1196,6 +1204,46 @@ ble_gap_adv_active_instance(uint8_t instance)
return ble_gap_slave[instance].op == BLE_GAP_OP_S_ADV;
}

/**
* Clears advertisement and discovery state. This function is necessary
* when the controller loses its active state (e.g. on host stack reset).
*/
void
ble_gap_reset_state(int reason)
{
uint16_t conn_handle;

while (1) {
conn_handle = ble_hs_atomic_first_conn_handle();
if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
break;
}

ble_gap_conn_broken(conn_handle, reason);
}

#if NIMBLE_BLE_ADVERTISE
#if MYNEWT_VAL(BLE_EXT_ADV)
uint8_t i;
for (i = 0; i < BLE_ADV_INSTANCES; i++) {
if (ble_gap_adv_active_instance(i)) {
/* Indicate to application that advertising has stopped. */
ble_gap_adv_finished(i, reason, 0, 0);
}
}
#else
if (ble_gap_adv_active_instance(0)) {
/* Indicate to application that advertising has stopped. */
ble_gap_adv_finished(0, reason, 0, 0);
}
#endif
#endif

#if (NIMBLE_BLE_SCAN || NIMBLE_BLE_CONNECT)
ble_gap_master_failed(reason);
#endif
}

static int
ble_gap_accept_slave_conn(uint8_t instance)
{
Expand Down
1 change: 1 addition & 0 deletions nimble/host/src/ble_gap_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void ble_gap_preempt(void);
void ble_gap_preempt_done(void);

void ble_gap_conn_broken(uint16_t conn_handle, int reason);
void ble_gap_reset_state(int reason);
int32_t ble_gap_timer(void);

int ble_gap_init(void);
Expand Down
11 changes: 2 additions & 9 deletions nimble/host/src/ble_hs.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ ble_hs_sync(void)
static int
ble_hs_reset(void)
{
uint16_t conn_handle;
int rc;

STATS_INC(ble_hs_stats, reset);
Expand All @@ -387,14 +386,8 @@ ble_hs_reset(void)

ble_hs_clear_rx_queue();

while (1) {
conn_handle = ble_hs_atomic_first_conn_handle();
if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
break;
}

ble_gap_conn_broken(conn_handle, ble_hs_reset_reason);
}
/* Clear adverising and scanning states. */
ble_gap_reset_state(ble_hs_reset_reason);

/* Clear configured addresses. */
ble_hs_id_reset();
Expand Down
4 changes: 0 additions & 4 deletions nimble/host/src/ble_hs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ void ble_hs_notifications_sched(void);
struct ble_npl_eventq *ble_hs_evq_get(void);
void ble_hs_stop_init(void);

int
ble_sm_alg_encrypt(uint8_t *key, uint8_t *plaintext, uint8_t *enc_data);


struct ble_mqueue {
STAILQ_HEAD(, os_mbuf_pkthdr) head;
struct ble_npl_event ev;
Expand Down
2 changes: 2 additions & 0 deletions nimble/host/src/ble_hs_resolv_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ struct ble_hs_resolv_entry {
uint8_t rl_peer_rpa[BLE_DEV_ADDR_LEN];
};

#if MYNEWT_VAL(BLE_STORE_CONFIG_PERSIST)
/* Persist peer records in NVS. XXX Need to handle this in `store` module */
int ble_store_persist_peer_records(void);
#endif

struct ble_hs_peer_sec {
ble_addr_t peer_addr;
Expand Down
4 changes: 4 additions & 0 deletions nimble/host/src/ble_sm_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ int ble_sm_slave_initiate(uint16_t conn_handle);
int ble_sm_enc_initiate(uint16_t conn_handle, uint8_t key_size,
const uint8_t *ltk, uint16_t ediv,
uint64_t rand_val, int auth);
int ble_sm_alg_encrypt(uint8_t *key, uint8_t *plaintext, uint8_t *enc_data);
int ble_sm_init(void);

#define BLE_SM_LOG_CMD(is_tx, cmd_name, conn_handle, log_cb, cmd) \
Expand All @@ -419,6 +420,9 @@ int ble_sm_init(void);

#define ble_sm_init() 0

#define ble_sm_alg_encrypt(key, plaintext, enc_data) \
BLE_HS_ENOTSUP

#endif

struct ble_l2cap_chan *ble_sm_create_chan(uint16_t handle);
Expand Down

0 comments on commit 5364a96

Please sign in to comment.