Skip to content

Commit

Permalink
Merge branch 'nimble/log_level_filter_v1.1.0_idf_v3.3' into 'nimble-1…
Browse files Browse the repository at this point in the history
….1.0-idf-v3.3'

NimBLE: Add macros for log level filtering and include upstream fixes (nimble-1.1.0-idf-v3.3)

See merge request espressif/esp-nimble!45
  • Loading branch information
dhrishi committed May 20, 2020
2 parents 5364a96 + 69bdb87 commit a9239c6
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 165 deletions.
18 changes: 16 additions & 2 deletions nimble/host/include/host/ble_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ struct hci_conn_update;

#define BLE_GAP_INITIAL_CONN_LATENCY 0
#define BLE_GAP_INITIAL_SUPERVISION_TIMEOUT 0x0100
#define BLE_GAP_INITIAL_CONN_MIN_CE_LEN 0x0010
#define BLE_GAP_INITIAL_CONN_MAX_CE_LEN 0x0300
#define BLE_GAP_INITIAL_CONN_MIN_CE_LEN 0x0000
#define BLE_GAP_INITIAL_CONN_MAX_CE_LEN 0x0000

#define BLE_GAP_ROLE_MASTER 0
#define BLE_GAP_ROLE_SLAVE 1
Expand Down Expand Up @@ -1239,6 +1239,20 @@ int ble_gap_unpair(const ble_addr_t *peer_addr);
*/
int ble_gap_unpair_oldest_peer(void);

/**
* Similar to `ble_gap_unpair_oldest_peer()`, except it makes sure that the
* peer received in input parameters is not deleted.
*
* @param peer_addr Address of the peer (not to be deleted)
*
* @return 0 on success;
* A BLE host HCI return code if the controller
* rejected the request;
* A BLE host core return code on unexpected
* error.
*/
int ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr);

#define BLE_GAP_PRIVATE_MODE_NETWORK 0
#define BLE_GAP_PRIVATE_MODE_DEVICE 1
int ble_gap_set_priv_mode(const ble_addr_t *peer_addr, uint8_t priv_mode);
Expand Down
7 changes: 3 additions & 4 deletions nimble/host/src/ble_att_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ ble_att_tx(uint16_t conn_handle, struct os_mbuf *txom)

ble_hs_lock();

ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT, &conn,
&chan);
if (chan == NULL) {
rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT, &conn,
&chan);
if (rc != 0) {
os_mbuf_free_chain(txom);
rc = BLE_HS_ENOTCONN;
} else {
ble_att_truncate_to_mtu(chan, txom);
rc = ble_l2cap_tx(conn, chan, txom);
Expand Down
58 changes: 50 additions & 8 deletions nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,6 @@ ble_gap_update_timer(void)
ble_hs_unlock();

if (entry != NULL) {
ble_gap_update_notify(conn_handle, BLE_HS_ETIMEOUT);
ble_gap_update_entry_free(entry);
}
} while (entry != NULL);
Expand Down Expand Up @@ -4496,6 +4495,36 @@ ble_gap_unpair_oldest_peer(void)
return 0;
}

int
ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr)
{
ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
int num_peers;
int rc, i;

rc = ble_store_util_bonded_peers(
&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
if (rc != 0) {
return rc;
}

if (num_peers == 0) {
return BLE_HS_ENOENT;
}

for (i = 0; i < num_peers; i++) {
if (ble_addr_cmp(peer_addr, &peer_id_addrs[i]) != 0) {
break;
}
}

if (i >= num_peers) {
return BLE_HS_ENOMEM;
}

return ble_gap_unpair(&peer_id_addrs[i]);
}

void
ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params)
Expand All @@ -4517,7 +4546,8 @@ ble_gap_passkey_event(uint16_t conn_handle,
}

void
ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
ble_gap_enc_event(uint16_t conn_handle, int status,
int security_restored, int bonded)
{
#if !NIMBLE_BLE_SM
return;
Expand All @@ -4533,12 +4563,24 @@ ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
ble_gap_event_listener_call(&event);
ble_gap_call_conn_event_cb(&event, conn_handle);

if (status == 0) {
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
} else {
ble_gatts_bonding_established(conn_handle);
}
if (status != 0) {
return;
}

/* If encryption succeded and encryption has been restored for bonded device,
* notify gatt server so it has chance to send notification/indication if needed.
*/
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
return;
}

/* If this is fresh pairing and bonding has been established,
* notify gatt server about that so previous subscriptions (before bonding)
* can be stored.
*/
if (bonded) {
ble_gatts_bonding_established(conn_handle);
}
}

Expand Down
2 changes: 1 addition & 1 deletion nimble/host/src/ble_gap_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
struct ble_gap_upd_params *params);
void ble_gap_rx_phy_update_complete(struct hci_le_phy_upd_complete *evt);
void ble_gap_enc_event(uint16_t conn_handle, int status,
int security_restored);
int security_restored, int bonded);
void ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params);
void ble_gap_notify_rx_event(uint16_t conn_handle, uint16_t attr_handle,
Expand Down
21 changes: 9 additions & 12 deletions nimble/host/src/ble_hs_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,22 +410,19 @@ ble_hs_conn_addrs(const struct ble_hs_conn *conn,

#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
/* RPA: Override peer address information. */
struct ble_hs_resolv_entry *rl = NULL;

ble_addr_t bhc_peer_addr;
bhc_peer_addr.type = conn->bhc_peer_addr.type;
memcpy(bhc_peer_addr.val, conn->bhc_peer_addr.val, BLE_DEV_ADDR_LEN);
if (ble_host_rpa_enabled()) {

uint8_t *local_id = NULL;
ble_hs_id_addr(BLE_ADDR_PUBLIC, (const uint8_t **) &local_id, NULL);

rl = ble_hs_resolv_list_find(bhc_peer_addr.val);
if (rl != NULL) {
memcpy(addrs->peer_ota_addr.val, addrs->peer_id_addr.val, BLE_DEV_ADDR_LEN);
memcpy(addrs->peer_id_addr.val, rl->rl_identity_addr, BLE_DEV_ADDR_LEN);

addrs->peer_id_addr.type = rl->rl_addr_type;
struct ble_hs_resolv_entry *rl = NULL;
rl = ble_hs_resolv_list_find(bhc_peer_addr.val);
if (rl != NULL) {
memcpy(addrs->peer_id_addr.val, rl->rl_identity_addr, BLE_DEV_ADDR_LEN);
addrs->peer_id_addr.type = rl->rl_addr_type;

if (ble_host_rpa_enabled()) {
uint8_t *local_id = NULL;
ble_hs_id_addr(BLE_ADDR_PUBLIC, (const uint8_t **) &local_id, NULL);

/* RL is present: populate our id addr with public ID */
memcpy(addrs->our_id_addr.val, local_id, BLE_DEV_ADDR_LEN);
Expand Down
2 changes: 1 addition & 1 deletion nimble/host/src/ble_hs_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ ble_hs_hci_process_ack(uint16_t expected_opcode,
}

if (rc == 0) {
if (params_buf == NULL) {
if (params_buf == NULL || out_ack->bha_params == NULL) {
out_ack->bha_params_len = 0;
} else {
if (out_ack->bha_params_len > params_buf_len) {
Expand Down
21 changes: 4 additions & 17 deletions nimble/host/src/ble_hs_hci_evt.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,11 @@ ble_hs_hci_evt_le_conn_complete(uint8_t subevent, uint8_t *data, int len)
if (ble_host_rpa_enabled()) {
uint8_t *local_id_rpa = ble_hs_get_rpa_local();
memcpy(evt.local_rpa, local_id_rpa, 6);

struct ble_hs_resolv_entry *rl = NULL;
ble_rpa_replace_peer_params_with_rl(evt.peer_addr,
&evt.peer_addr_type, &rl);
if (rl == NULL) {
if (ble_rpa_resolv_add_peer_rec(evt.peer_addr) != 0) {
BLE_HS_LOG(DEBUG, "Memory unavailable for new peer record\n");
}
}
}

struct ble_hs_resolv_entry *rl = NULL;
ble_rpa_replace_peer_params_with_rl(evt.peer_addr,
&evt.peer_addr_type, &rl);
#endif
} else {
memset(evt.local_rpa, 0, BLE_DEV_ADDR_LEN);
Expand Down Expand Up @@ -448,14 +443,6 @@ ble_hs_hci_evt_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
memcpy(desc.addr.val, data + off, 6);
off += 6;

#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
if (ble_host_rpa_enabled()) {
/* Now RPA to be resolved here, since controller is unaware of the
* address is RPA */
ble_rpa_replace_peer_params_with_rl(desc.addr.val,
&desc.addr.type, NULL);
}
#endif
desc.length_data = data[off];
++off;

Expand Down
8 changes: 6 additions & 2 deletions nimble/host/src/ble_hs_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
return rc;
}

void
int
ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan)
Expand All @@ -66,14 +66,18 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
int rc;

rc = ble_hs_misc_conn_chan_find(conn_handle, cid, &conn, &chan);
BLE_HS_DBG_ASSERT_EVAL(rc == 0);
if (rc != 0) {
return rc;
}

if (out_conn != NULL) {
*out_conn = conn;
}
if (out_chan != NULL) {
*out_chan = chan;
}

return 0;
}

uint8_t
Expand Down
6 changes: 3 additions & 3 deletions nimble/host/src/ble_hs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ int ble_hs_hci_evt_acl_process(struct os_mbuf *om);
int ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan);
void ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan);
int ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan);
uint8_t ble_hs_misc_addr_type_to_id(uint8_t addr_type);
int ble_hs_misc_restore_irks(void);

Expand Down
9 changes: 7 additions & 2 deletions nimble/host/src/ble_l2cap_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,13 @@ ble_l2cap_sig_update(uint16_t conn_handle,
STATS_INC(ble_l2cap_stats, update_init);

ble_hs_lock();
ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
&conn, &chan);
rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
&conn, &chan);
if (rc != 0) {
ble_hs_unlock();
goto done;
}

master = conn->bhc_flags & BLE_HS_CONN_F_MASTER;
ble_hs_unlock();

Expand Down
8 changes: 5 additions & 3 deletions nimble/host/src/ble_l2cap_sig_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
int rc;

ble_hs_lock();
ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
&conn, &chan);
rc = ble_l2cap_tx(conn, chan, txom);
rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG,
&conn, &chan);
if (rc == 0) {
rc = ble_l2cap_tx(conn, chan, txom);
}
ble_hs_unlock();

return rc;
Expand Down
Loading

0 comments on commit a9239c6

Please sign in to comment.