Skip to content

Commit

Permalink
Update to esp-nimble (1.4.0 branch) @0fc6282
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Apr 6, 2023
1 parent ffc5ab7 commit 6a3da51
Show file tree
Hide file tree
Showing 27 changed files with 267 additions and 46 deletions.
4 changes: 4 additions & 0 deletions src/nimble/esp_port/port/include/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@
#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#endif

#ifndef MYNEWT_VAL_BLE_GATT_BLOB_TRANSFER
#define MYNEWT_VAL_BLE_GATT_BLOB_TRANSFER (0)
#endif

#ifndef MYNEWT_VAL_BLE_HOST
#define MYNEWT_VAL_BLE_HOST (1)
#endif
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/controller/src/ble_ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ OS_TASK_STACK_DEFINE(g_ble_ll_stack, BLE_LL_STACK_SIZE);

#endif /* MYNEWT */

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

/** Our global device address (public) */
uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];

Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/controller/src/ble_ll_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
extern void bletest_completed_pkt(uint16_t handle);
#endif

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

/* XXX TODO
* 1) I think if we are initiating and we already have a connection with
* a device that we will still try and connect to it. Fix this.
Expand Down
10 changes: 9 additions & 1 deletion src/nimble/nimble/controller/src/ble_ll_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
*/
#ifndef ESP_PLATFORM

#include <stdint.h>
Expand Down Expand Up @@ -43,6 +43,14 @@
#include "ble_ll_dtm_priv.h"
#endif

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

static void ble_ll_hci_cmd_proc(struct ble_npl_event *ev);

/* OS event to enqueue command */
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/drivers/nrf51/src/ble_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
#error LE Coded PHY cannot be enabled on nRF51
#endif

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

/* XXX: 4) Make sure RF is higher priority interrupt than schedule */

/*
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/drivers/nrf52/src/ble_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
#endif
#endif

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

/*
* NOTE: This code uses a couple of PPI channels so care should be taken when
* using PPI somewhere else.
Expand Down
12 changes: 12 additions & 0 deletions src/nimble/nimble/host/include/host/ble_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,18 @@ int ble_gap_ext_adv_remove(uint8_t instance);
* other error code on failure.
*/
int ble_gap_ext_adv_clear(void);

/**
* Indicates whether an advertisement procedure is currently in progress on
* the specified Instance
*
* @param instance Instance Id
*
* @return 0 if there is no active advertising procedure for the instance,
* 1 otherwise
*
*/
int ble_gap_ext_adv_active(uint8_t instance);
#endif

/* Periodic Advertising */
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/host/mesh/src/adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
#define ADV_INT_DEFAULT_MS 100
#define ADV_INT_FAST_MS 20

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

static int32_t adv_int_min = ADV_INT_DEFAULT_MS;

/* TinyCrypt PRNG consumes a lot of stack space, so we need to have
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/host/mesh/src/cfg_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#include "settings.h"
#include "cfg.h"

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

void (*bt_mesh_app_key_cb_list[1]) (uint16_t app_idx, uint16_t net_idx,
enum bt_mesh_key_evt evt);

Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/host/mesh/src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ extern uint8_t g_mesh_addr_type;
static struct ble_gap_adv_params ble_adv_cur_conf[2];
#endif

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

const char *
bt_hex(const void *buf, size_t len)
{
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/host/mesh/src/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ ble_uuid16_t BT_UUID_MESH_PROXY_DATA_OUT = BLE_UUID16_INIT(0x2ade);

#define CLIENT_BUF_SIZE 68

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

static const struct ble_gap_adv_params slow_adv_param = {
.conn_mode = (BLE_GAP_CONN_MODE_UND),
.disc_mode = (BLE_GAP_DISC_MODE_GEN),
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/host/mesh/src/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
/* How long to wait for available buffers before giving up */
#define BUF_TIMEOUT K_NO_WAIT

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

static struct seg_tx {
struct bt_mesh_subnet *sub;
void *seg[CONFIG_BT_MESH_TX_SEG_MAX];
Expand Down
9 changes: 9 additions & 0 deletions src/nimble/nimble/host/src/ble_att.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
#include "ble_hs_priv.h"

#if NIMBLE_BLE_CONNECT

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

static uint16_t ble_att_preferred_mtu_val;

/** Dispatch table for incoming ATT requests. Sorted by op code. */
Expand Down
11 changes: 10 additions & 1 deletion src/nimble/nimble/host/src/ble_att_clt.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,

struct ble_att_write_cmd *cmd;
struct os_mbuf *txom2;

#if MYNEWT_VAL(BLE_HS_DEBUG)
uint8_t b;
int rc;
int i;
Expand All @@ -720,7 +722,7 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,
assert(rc == 0);
BLE_HS_LOG(DEBUG, "0x%02x", b);
}

#endif

cmd = ble_att_cmd_get(BLE_ATT_OP_WRITE_CMD, sizeof(*cmd), &txom2);
if (cmd == NULL) {
Expand Down Expand Up @@ -767,10 +769,17 @@ ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle,
goto err;
}

#if MYNEWT_VAL(BLE_GATT_BLOB_TRANSFER)
if (OS_MBUF_PKTLEN(txom) > BLE_ATT_ATTR_MAX_LEN) {
rc = BLE_HS_EINVAL;
goto err;
}
#else
if (offset + OS_MBUF_PKTLEN(txom) > BLE_ATT_ATTR_MAX_LEN) {
rc = BLE_HS_EINVAL;
goto err;
}
#endif

if (OS_MBUF_PKTLEN(txom) >
ble_att_mtu(conn_handle) - BLE_ATT_PREP_WRITE_CMD_BASE_SZ) {
Expand Down
5 changes: 4 additions & 1 deletion src/nimble/nimble/host/src/ble_att_svr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,9 @@ ble_att_svr_prep_validate(struct ble_att_prep_entry_list *prep_list,
{
struct ble_att_prep_entry *entry;
struct ble_att_prep_entry *prev;
#if !MYNEWT_VAL(BLE_GATT_BLOB_TRANSFER)
int cur_len;
#endif

prev = NULL;
SLIST_FOREACH(entry, prep_list, bape_next) {
Expand All @@ -2153,12 +2155,13 @@ ble_att_svr_prep_validate(struct ble_att_prep_entry_list *prep_list,
}
}

#if !MYNEWT_VAL(BLE_GATT_BLOB_TRANSFER)
cur_len = entry->bape_offset + OS_MBUF_PKTLEN(entry->bape_value);
if (cur_len > BLE_ATT_ATTR_MAX_LEN) {
*err_handle = entry->bape_handle;
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}

#endif
prev = entry;
}

Expand Down
18 changes: 18 additions & 0 deletions src/nimble/nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
#include "ble_hs_priv.h"
#include "ble_hs_resolv_priv.h"

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

#if MYNEWT
#include "bsp/bsp.h"
#else
Expand Down Expand Up @@ -1445,6 +1453,16 @@ ble_gap_adv_active_instance(uint8_t instance)
}
#endif

#if MYNEWT_VAL(BLE_EXT_ADV)
int ble_gap_ext_adv_active(uint8_t instance)
{
if (instance >= BLE_ADV_INSTANCES) {
return 0;
}
return ble_gap_adv_active_instance(instance);
}
#endif

/**
* Clears advertisement and discovery state. This function is necessary
* when the controller loses its active state (e.g. on stack reset).
Expand Down
9 changes: 9 additions & 0 deletions src/nimble/nimble/host/src/ble_gattc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
#include "ble_hs_priv.h"

#if NIMBLE_BLE_CONNECT

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

/*****************************************************************************
* $definitions / declarations *
*****************************************************************************/
Expand Down
9 changes: 7 additions & 2 deletions src/nimble/nimble/host/src/ble_hs_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
return 0;
}

#if !(SOC_ESP_NIMBLE_CONTROLLER)
/**
* Calculates the largest ACL payload that the controller can accept.
*/
Expand All @@ -420,6 +421,7 @@ ble_hs_hci_max_acl_payload_sz(void)
*/
return ble_hs_hci_buf_sz;
}
#endif

/**
* Allocates an mbuf to contain an outgoing ACL data fragment.
Expand Down Expand Up @@ -524,8 +526,11 @@ ble_hs_hci_acl_tx_now(struct ble_hs_conn *conn, struct os_mbuf **om)

/* Send fragments until the entire packet has been sent. */
while (txom != NULL && ble_hs_hci_avail_pkts > 0) {
frag = mem_split_frag(&txom, ble_hs_hci_max_acl_payload_sz(),
ble_hs_hci_frag_alloc, NULL);
#if SOC_ESP_NIMBLE_CONTROLLER
frag = mem_split_frag(&txom, BLE_ACL_MAX_PKT_SIZE, ble_hs_hci_frag_alloc, NULL);
#else
frag = mem_split_frag(&txom, ble_hs_hci_max_acl_payload_sz(), ble_hs_hci_frag_alloc, NULL);
#endif
if (frag == NULL) {
*om = txom;
return BLE_HS_EAGAIN;
Expand Down
8 changes: 8 additions & 0 deletions src/nimble/nimble/host/src/ble_hs_hci_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
#include "nimble/nimble/host/include/host/ble_hs_hci.h"
#include "ble_hs_priv.h"

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

uint16_t
ble_hs_hci_util_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc)
{
Expand Down
22 changes: 6 additions & 16 deletions src/nimble/nimble/host/src/ble_hs_resolv.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,16 @@ static void
ble_rpa_peer_dev_rec_clear_all(void)
{
uint8_t i;
int num_peer_dev_rec = ble_store_num_peer_dev_rec;

/* As NVS record need to be deleted one by one, we loop through
* peer_records */
for (i = 0; i < ble_store_num_peer_dev_rec; i++) {
for (i = 0; i < num_peer_dev_rec; i++) {
ble_store_num_peer_dev_rec--;

if ((i != ble_store_num_peer_dev_rec) && (ble_store_num_peer_dev_rec != 0)) {
memmove(&peer_dev_rec[i], &peer_dev_rec[i + 1],
(ble_store_num_peer_dev_rec - i + 1) * sizeof(struct ble_hs_dev_records ));
}

memmove(&peer_dev_rec[0], &peer_dev_rec[1],
ble_store_num_peer_dev_rec * sizeof(struct ble_hs_dev_records));
memset(&peer_dev_rec[ble_store_num_peer_dev_rec], 0,
sizeof(struct ble_hs_dev_records));
ble_store_persist_peer_records();
}
return;
Expand Down Expand Up @@ -230,15 +229,6 @@ ble_rpa_resolv_add_peer_rec(uint8_t *peer_addr)
{
struct ble_hs_dev_records *p_dev_rec =
&peer_dev_rec[ble_store_num_peer_dev_rec];
uint8_t idx = 0;

while (p_dev_rec->rec_used) {
p_dev_rec++;
idx++;
if (idx > MYNEWT_VAL(BLE_STORE_MAX_BONDS)) {
return BLE_HS_ESTORE_CAP;
}
}

p_dev_rec->rec_used = 1;
memcpy(p_dev_rec->pseudo_addr, peer_addr, BLE_DEV_ADDR_LEN);
Expand Down
Loading

0 comments on commit 6a3da51

Please sign in to comment.