Skip to content

Commit

Permalink
Resync NimBLE core to upstream master.
Browse files Browse the repository at this point in the history
esp-idf @be8c847
esp-nimble@0a1604a
  • Loading branch information
h2zero committed Apr 30, 2020
1 parent 1d6bf67 commit c35e5fd
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 295 deletions.
2 changes: 1 addition & 1 deletion src/console/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

#define console_printf printf

#endif
#endif
2 changes: 1 addition & 1 deletion src/esp-hci/src/esp_nimble_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,4 @@ esp_err_t esp_nimble_hci_and_controller_deinit(void)
}

return ESP_OK;
}
}
4 changes: 1 addition & 3 deletions src/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

/* Modifications copyright (C) 2020 Ryan Powell */

#ifndef __ESP_NIMBLE_CFG__
#define __ESP_NIMBLE_CFG__
#include "nimconfig.h"
Expand Down Expand Up @@ -470,7 +468,7 @@
#endif

#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT
#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT CONFIG_BT_NIMBLE_FLOW_CTRL_TX_ON_DISCONNECT
#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT CONFIG_BT_NIMBLE_HS_FLOW_CTRL_TX_ON_DISCONNECT
#endif

#ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS
Expand Down
2 changes: 1 addition & 1 deletion src/esp_nimble_hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ esp_err_t esp_nimble_hci_and_controller_deinit(void);
}
#endif

#endif /* __ESP_NIMBLE_HCI_H__ */
#endif /* __ESP_NIMBLE_HCI_H__ */
3 changes: 1 addition & 2 deletions src/esp_nimble_mem.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
*
Expand Down Expand Up @@ -37,4 +36,4 @@ void nimble_platform_mem_free(void *ptr);
}
#endif

#endif /* __ESP_NIMBLE_MEM_H__ */
#endif /* __ESP_NIMBLE_MEM_H__ */
14 changes: 0 additions & 14 deletions src/host/ble_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1886,20 +1886,6 @@ struct ble_gap_event_listener {
SLIST_ENTRY(ble_gap_event_listener) link;
};

/**
* Similar to `ble_gap_unpair_oldest_peer()`, except it makes sure that current
* peer is not deleted.
*
* @param peer_addr Address of the current 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_curr(const ble_addr_t *curr_peer);

/**
* Registers listener for GAP events
*
Expand Down
2 changes: 0 additions & 2 deletions src/host/ble_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ int ble_store_clear(void);

/*** Utility functions. */

int ble_store_clean_old_cccds(const ble_addr_t *curr_peer);

int ble_store_util_bonded_peers(ble_addr_t *out_peer_id_addrs,
int *out_num_peers,
int max_peers);
Expand Down
1 change: 1 addition & 0 deletions src/nimble/host/mesh/src/src/ble_gap_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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
4 changes: 4 additions & 0 deletions src/nimble/host/mesh/src/src/ble_hs_id_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ int ble_hs_id_use_addr(uint8_t addr_type);
void ble_hs_id_reset(void);
void ble_hs_id_rnd_reset(void);

#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
bool ble_hs_is_rpa(uint8_t *addr, uint8_t addr_type);
int ble_hs_id_set_pseudo_rnd(const uint8_t *);
#endif
#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/nimble/host/mesh/src/src/ble_hs_pvcy_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ int ble_hs_pvcy_add_entry(const uint8_t *addr, uint8_t addrtype,
const uint8_t *irk);
int ble_hs_pvcy_ensure_started(void);
int ble_hs_pvcy_set_mode(const ble_addr_t *addr, uint8_t priv_mode);
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
bool ble_hs_pvcy_enabled(void);
#endif

#ifdef __cplusplus
}
Expand Down
108 changes: 108 additions & 0 deletions src/nimble/host/mesh/src/src/ble_hs_resolv_priv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifdef __cplusplus
extern "C" {
#endif

#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
/*
* An entry in the resolving list.
*/
struct ble_hs_resolv_entry {
uint8_t rl_addr_type;
uint8_t rl_local_irk[16];
uint8_t rl_peer_irk[16];
uint8_t rl_identity_addr[BLE_DEV_ADDR_LEN];
uint8_t rl_pseudo_id[BLE_DEV_ADDR_LEN];
uint8_t rl_local_rpa[BLE_DEV_ADDR_LEN];
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;
uint8_t irk[16];
uint8_t irk_present: 1;
};
/*
* BLE host peer device record, this helps in storing peer RPA before bond is
* created and IRKs are exchanged.
*/
struct ble_hs_dev_records {
bool rec_used;
uint8_t pseudo_addr[BLE_DEV_ADDR_LEN];
uint8_t rand_addr[BLE_DEV_ADDR_LEN];
uint8_t identity_addr[BLE_DEV_ADDR_LEN];
struct ble_hs_peer_sec peer_sec;
};

/* Add a device to the resolving list */
int ble_hs_resolv_list_add(uint8_t *cmdbuf);
int ble_hs_gen_own_rpa_random(void);
uint8_t *ble_hs_get_rpa_local(void);

/* Remove a device from the resolving list */
int ble_hs_resolv_list_rmv(uint8_t, uint8_t *);
/* Clear the resolving list and peer dev record */
void ble_hs_resolv_list_clear_all(void);

/* Address resolution enable command */
void ble_hs_resolv_enable(bool);

/* Finds 'addr' in resolving list. Doesnt check if address resolution enabled */
struct ble_hs_resolv_entry *
ble_hs_resolv_list_find(uint8_t *addr);

/* Returns true if host based RPA (privacy) is enabled */
bool ble_host_rpa_enabled(void);

/* Searches peer device records (RPA) and fetches matching RL, peer_address
* into input parameters if RL is found */
void
ble_rpa_replace_peer_params_with_rl(uint8_t *, uint8_t *, struct ble_hs_resolv_entry **);

int ble_rpa_resolv_add_peer_rec(uint8_t *);

struct ble_hs_dev_records *ble_rpa_get_peer_dev_records(void);
int ble_rpa_get_num_peer_dev_records(void);
void ble_rpa_set_num_peer_dev_records(int);
int ble_rpa_remove_peer_dev_rec(struct ble_hs_dev_records *);
struct ble_hs_dev_records *ble_rpa_find_peer_dev_rec(uint8_t *);

/* Set the resolvable private address timeout */
int ble_hs_resolv_set_rpa_tmo(uint16_t);

/* Resolve a resolvable private address */
int ble_hs_resolv_rpa(uint8_t *rpa, uint8_t *irk);

/* Initialize resolv*/
void ble_hs_resolv_init(void);

#ifdef __cplusplus
}
#endif

#endif
4 changes: 4 additions & 0 deletions src/nimble/host/mesh/src/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
47 changes: 2 additions & 45 deletions src/nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

/* Modifications copyright (C) 2020 Ryan Powell */

#include <assert.h>
#include <string.h>
#include <errno.h>
Expand Down Expand Up @@ -5303,8 +5301,7 @@ ble_gap_unpair_oldest_peer(void)
}

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

rc = ble_gap_unpair(&oldest_peer_id_addr);
Expand All @@ -5315,41 +5312,6 @@ ble_gap_unpair_oldest_peer(void)
return 0;
}

int
ble_gap_unpair_oldest_except_curr(const ble_addr_t *curr_peer)
{
ble_addr_t oldest_peer_id_addr[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
int num_peers;
int rc, i;

rc = ble_store_util_bonded_peers(
&oldest_peer_id_addr[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 (memcmp(curr_peer, &oldest_peer_id_addr[i], sizeof (ble_addr_t)) != 0) {
break;
}
}

if (i < num_peers) {
rc = ble_gap_unpair(&oldest_peer_id_addr[i]);
if (rc != 0) {
return rc;
}
} else {
return BLE_HS_ENOMEM;
}

return 0;
}

void
ble_gap_passkey_event(uint16_t conn_handle,
struct ble_gap_passkey_params *passkey_params)
Expand Down Expand Up @@ -5387,12 +5349,7 @@ 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);

/* H2zero mod
If bonding is not enabled don't store cccd data
if (status == 0) {
*/
if (status == 0 && ble_hs_cfg.sm_bonding) {
/* End mod */
if (status == 0) {
if (security_restored) {
ble_gatts_bonding_restored(conn_handle);
} else {
Expand Down
37 changes: 18 additions & 19 deletions src/nimble/host/src/ble_gatts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1689,30 +1689,29 @@ ble_gatts_bonding_established(uint16_t conn_handle)

conn = ble_hs_conn_find(conn_handle);
BLE_HS_DBG_ASSERT(conn != NULL);
BLE_HS_DBG_ASSERT(conn->bhc_sec_state.bonded);

if (conn->bhc_sec_state.bonded) {
cccd_value.peer_addr = conn->bhc_peer_addr;
gatt_srv = &conn->bhc_gatt_svr;
cccd_value.peer_addr = conn->bhc_peer_addr;
gatt_srv = &conn->bhc_gatt_svr;

for (i = 0; i < gatt_srv->num_clt_cfgs; ++i) {
clt_cfg = (gatt_srv->clt_cfgs + i);
if (clt_cfg == NULL) {
continue;
}
for (i = 0; i < gatt_srv->num_clt_cfgs; ++i) {
clt_cfg = (gatt_srv->clt_cfgs + i);
if (clt_cfg == NULL) {
continue;
}

if (clt_cfg->flags != 0) {
cccd_value.chr_val_handle = clt_cfg->chr_val_handle;
cccd_value.flags = clt_cfg->flags;
cccd_value.value_changed = 0;
if (clt_cfg->flags != 0) {
cccd_value.chr_val_handle = clt_cfg->chr_val_handle;
cccd_value.flags = clt_cfg->flags;
cccd_value.value_changed = 0;

/* Store write use ble_hs_lock */
ble_hs_unlock();
ble_store_write_cccd(&cccd_value);
ble_hs_lock();
/* Store write use ble_hs_lock */
ble_hs_unlock();
ble_store_write_cccd(&cccd_value);
ble_hs_lock();

conn = ble_hs_conn_find(conn_handle);
BLE_HS_DBG_ASSERT(conn != NULL);
}
conn = ble_hs_conn_find(conn_handle);
BLE_HS_DBG_ASSERT(conn != NULL);
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/nimble/host/src/ble_hs_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,17 @@ ble_hs_conn_addrs(const struct ble_hs_conn *conn,
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);

rl = ble_hs_resolv_list_find(bhc_peer_addr.val);
if (rl != NULL) {
addrs->peer_ota_addr = conn->bhc_peer_rpa_addr;
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);
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;

/* RL is present: populate our id addr with public ID */
memcpy(addrs->our_id_addr.val, local_id, BLE_DEV_ADDR_LEN);
Expand Down

0 comments on commit c35e5fd

Please sign in to comment.